test_SMBLoris.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import unittest
  2. import unittest.mock as mock
  3. from Test.GenericTest import GenericTest
  4. from Test.Lib import test_pcap_ips
  5. # FIXME: create new hashes if new test.pcap is used
  6. sha_default = 'e6201c4a6b42fb86304b935ee522d4c1f655bc19a4646c4df45a64bb504a0b5c'
  7. sha_one_attacker = '538f584a7a12488269cb22a2986cd0e6f32f0c243c7cce72c5deb5230167897c'
  8. sha_sixteen_attackers = 'ca3cb549a213832e238a25eaadfc8e6c55c0b37b595ca1fc16cfca7c0990d675'
  9. sha_ips_in_pcap = 'bb54c042f870467021958d5f6947d21876b1fa5cda5f27da41adebac8cd44b74'
  10. """
  11. CURRENT COVERAGE
  12. Name Stmts Miss Cover Missing (lines)
  13. ---------------------------------------------------------------------------
  14. Attack/SMBLorisAttack.py 128 4 97% 67, 72, 149, 182
  15. """
  16. # TODO: get 100% coverage
  17. class UnitTestSMBLoris(GenericTest):
  18. def test_default(self):
  19. # FIXME: maybe use another seed
  20. self.generic_test([['SMBLorisAttack']], sha_default)
  21. def test_one_attacker(self):
  22. self.generic_test([['SMBLorisAttack', 'ip.src=192.168.1.240', 'ip.dst=192.168.1.210']], sha_one_attacker)
  23. def test_ips_in_pcap(self):
  24. ip_src = 'ip.src='+test_pcap_ips[0]
  25. ip_dst = 'ip.dst='+test_pcap_ips[1]
  26. self.generic_test([['SMBLorisAttack', ip_src, ip_dst]], sha_ips_in_pcap)
  27. def test_sixteen_attackers(self):
  28. self.generic_test([['SMBLorisAttack', 'ip.dst=192.168.1.210', 'attackers.count=16']], sha_sixteen_attackers)
  29. @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_ip_address')
  30. def test_two_most_used_ips(self, mock_most_used_ip_address):
  31. mock_most_used_ip_address.return_value = test_pcap_ips
  32. self.generic_test([['SMBLorisAttack']], sha_default)
  33. def test_same_ip_src_dst(self):
  34. with self.assertRaises(SystemExit):
  35. self.generic_test([['SMBLorisAttack', 'ip.src=192.168.1.240', 'ip.dst=192.168.1.240']], sha_default)
  36. if __name__ == '__main__':
  37. unittest.main()