test_PortscanAttack.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import unittest
  2. import unittest.mock as mock
  3. from Test.GenericTest import GenericTest
  4. from Test.Lib import *
  5. sha_portscan_default = 'dd28509dcc55a722c57d6b462741581d7b48024cddb8b8c89fe138661fac2b07'
  6. sha_portscan_reverse_ports = '04f5cdab7ade15bde00f0fcf42278508da7104ac76eab543d9c4b1cbab4f67c7'
  7. sha_portscan_shuffle_dst_ports = 'a6ef8a714da52d7608a84f50fe9dc71a3714e8b78a62be07c4e3d5509fa03d95'
  8. sha_portscan_shuffle_src_ports = '218382e8feabea3c5a35834c9962034cdff6e0c90fafee899883a9a54bb38371'
  9. sha_portscan_mss_value_zero = 'c3847e0a3a5abf886506dc5402fbc9a3096db2fd1df16d276d6c60c6b4b4ca5f'
  10. sha_portscan_ttl_value_zero = 'c3847e0a3a5abf886506dc5402fbc9a3096db2fd1df16d276d6c60c6b4b4ca5f'
  11. sha_portscan_win_value_zero = 'c3847e0a3a5abf886506dc5402fbc9a3096db2fd1df16d276d6c60c6b4b4ca5f'
  12. sha_portscan_ip_src_random = 'c3939f30a40fa6e2164cc91dc4a7e823ca409492d44508e3edfc9d24748af0e5'
  13. sha_portscan_most_used_ip_in_list = 'c3939f30a40fa6e2164cc91dc4a7e823ca409492d44508e3edfc9d24748af0e5'
  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 = test_pcap_ips
  42. self.generic_test([['PortscanAttack']], sha_portscan_most_used_ip_in_list)
  43. if __name__ == '__main__':
  44. unittest.main()