3
0

test_SMBLoris.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import random
  2. import unittest
  3. import unittest.mock as mock
  4. from ID2TLib.Controller import *
  5. from Test.Lib import test_pcap, test_pcap_ips, get_sha256, clean_up
  6. # FIXME: create new hashes
  7. sha_one_attacker = '887226f047456608c5c8746c91d387ffa35777650f083564e0104e381155c58e'
  8. sha_one_hundred_attackers = '3cab29e73bc048ea7cbffde51f5637fe00256d896a6788db27fbec3804f19cc9'
  9. sha_ips_in_pcap = '4a072c57bf97c8543305964c4df4de5f010df7da22fc8f414ccbbf88b962ae86'
  10. class UnitTestSMBLoris(unittest.TestCase):
  11. def test_one_attacker(self):
  12. random.seed(5)
  13. controller = Controller(pcap_file_path=test_pcap, do_extra_tests=False)
  14. controller.load_pcap_statistics(False, False, False)
  15. controller.process_attacks([['SMBLorisAttack', 'ip.src=192.168.1.240', 'ip.dst=192.168.1.210']])
  16. self.assertEqual(get_sha256(controller.pcap_dest_path), sha_one_attacker)
  17. clean_up(controller)
  18. def test_ips_in_pcap(self):
  19. # TODO: implement test
  20. ip_src = 'ip.src='+test_pcap_ips[0]
  21. ip_dst = 'ip.dst='+test_pcap_ips[1]
  22. random.seed(5)
  23. controller = Controller(pcap_file_path=test_pcap, do_extra_tests=False)
  24. controller.load_pcap_statistics(False, False, False)
  25. controller.process_attacks([['SMBLorisAttack', ip_src, ip_dst]])
  26. self.assertEqual(get_sha256(controller.pcap_dest_path), sha_ips_in_pcap)
  27. clean_up(controller)
  28. #def five_minutes(self):
  29. # TODO: implement test
  30. def test_one_hundred_attackers(self):
  31. random.seed(5)
  32. controller = Controller(pcap_file_path=test_pcap, do_extra_tests=False)
  33. controller.load_pcap_statistics(False, False, False)
  34. controller.process_attacks([['SMBLorisAttack', 'ip.dst=192.168.1.210', 'attackers.count=100']])
  35. self.assertEqual(get_sha256(controller.pcap_dest_path), sha_one_hundred_attackers)
  36. clean_up(controller)
  37. if __name__ == '__main__':
  38. unittest.main()