test_PortscanAttack.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import unittest
  2. import unittest.mock as mock
  3. import ID2TLib.TestLibrary as Lib
  4. from Test.GenericTest import GenericTest
  5. sha_portscan_default = '6af539fb9f9a28f84a5c337a07dbdc1a11885c5c6de8f9a682bd74b89edc5130'
  6. sha_portscan_reverse_ports = '1c03342b7b94fdd1c9903d07237bc5239ebb7bd77a3dd137c9c378fa216c5382'
  7. sha_portscan_shuffle_dst_ports = '40485e47766438425900b787c4cda4ad1b5cd0d233b80f38bd45b5a88b70a797'
  8. sha_portscan_shuffle_src_ports = '48578b45e18bdbdc0a9f3f4cec160ccb58839250348ec4d3ec44c1b15da248de'
  9. sha_portscan_mss_value_zero = '8d32476a89262b78118a68867fff1d45c81f8ffb4970201f9d5ee3dfd94ba58a'
  10. sha_portscan_ttl_value_zero = 'ff8cf15d8e59856e0c6e43d81fa40180ebf2127042f376217cc2a20e4f21726e'
  11. sha_portscan_win_value_zero = 'b2fcbf72190ac3bf12192d0d7ee8c09ef87adb0d94a2610615ca76d8b577bbfb'
  12. sha_portscan_ip_src_random = 'c3939f30a40fa6e2164cc91dc4a7e823ca409492d44508e3edfc9d24748af0e5'
  13. sha_portscan_most_used_ip_in_list = '6af539fb9f9a28f84a5c337a07dbdc1a11885c5c6de8f9a682bd74b89edc5130'
  14. """
  15. CURRENT COVERAGE
  16. Name Stmts Miss Cover Missing (lines)
  17. ---------------------------------------------------------------------------
  18. Attack/PortscanAttack.py 146 6 96% 73, 108-109, 158, 211, 238
  19. """
  20. # TODO: get 100% coverage
  21. class UnitTestPortscanAttack(GenericTest):
  22. def test_portscan_default(self):
  23. self.generic_test([['PortscanAttack']], sha_portscan_default)
  24. def test_portscan_reverse_ports(self):
  25. self.generic_test([['PortscanAttack', 'port.dst.order-desc=1']], sha_portscan_reverse_ports)
  26. def test_portscan_shuffle_dst_ports(self):
  27. self.generic_test([['PortscanAttack', 'port.dst.shuffle=1']], sha_portscan_shuffle_dst_ports)
  28. def test_portscan_shuffle_src_ports(self):
  29. self.generic_test([['PortscanAttack', 'port.src.shuffle=1']], sha_portscan_shuffle_src_ports)
  30. @mock.patch('ID2TLib.Statistics.Statistics.get_mss_distribution', return_value='')
  31. def test_portscan_mss_length_zero(self, mock_mss_dis):
  32. self.generic_test([['PortscanAttack']], sha_portscan_mss_value_zero)
  33. @mock.patch('ID2TLib.Statistics.Statistics.get_ttl_distribution', return_value='')
  34. def test_portscan_ttl_length_zero(self, mock_ttl_dis):
  35. self.generic_test([['PortscanAttack']], sha_portscan_ttl_value_zero)
  36. @mock.patch('ID2TLib.Statistics.Statistics.get_win_distribution', return_value='')
  37. def test_portscan_win_length_zero(self, mock_win_dis):
  38. self.generic_test([['PortscanAttack']], sha_portscan_win_value_zero)
  39. @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_ip_address')
  40. def test_portscan_most_used_ips(self, mock_most_used_ip_address):
  41. mock_most_used_ip_address.return_value = Lib.test_pcap_ips
  42. self.generic_test([['PortscanAttack']], sha_portscan_most_used_ip_in_list)
  43. if __name__ == '__main__':
  44. unittest.main()