|
@@ -1,33 +1,28 @@
|
|
|
+import os
|
|
|
import random
|
|
|
import unittest
|
|
|
import unittest.mock as mock
|
|
|
-import hashlib
|
|
|
|
|
|
-from definitions import ROOT_DIR
|
|
|
from ID2TLib.Controller import *
|
|
|
+from Test.Lib import test_pcap, get_sha256
|
|
|
|
|
|
+
|
|
|
sha_one_attacker = '887226f047456608c5c8746c91d387ffa35777650f083564e0104e381155c58e'
|
|
|
|
|
|
|
|
|
class UnitTestSMBLoris(unittest.TestCase):
|
|
|
|
|
|
- def get_sha256(self, file):
|
|
|
- sha = hashlib.sha256()
|
|
|
- with open(file, 'rb') as f:
|
|
|
- while True:
|
|
|
- data = f.read(0x100000)
|
|
|
- if not data:
|
|
|
- break
|
|
|
- sha.update(data)
|
|
|
- return sha.hexdigest()
|
|
|
+ def clean_up(self, controller):
|
|
|
+ os.remove(controller.pcap_dest_path)
|
|
|
+ os.remove(controller.label_manager.label_file_path)
|
|
|
|
|
|
def test_one_attacker(self):
|
|
|
-
|
|
|
random.seed(5)
|
|
|
- controller = Controller(pcap_file_path=ROOT_DIR+"/../resources/test/test.pcap", do_extra_tests=False)
|
|
|
+ controller = Controller(pcap_file_path=test_pcap, do_extra_tests=False)
|
|
|
controller.load_pcap_statistics(False, False, False)
|
|
|
controller.process_attacks([['SMBLorisAttack', 'ip.src=192.168.1.240', 'ip.dst=192.168.1.210']])
|
|
|
- self.assertEqual(self.get_sha256(controller.pcap_dest_path), sha_one_attacker)
|
|
|
+ self.assertEqual(get_sha256(controller.pcap_dest_path), sha_one_attacker)
|
|
|
+ self.clean_up(controller)
|
|
|
|
|
|
|
|
|
|
|
@@ -38,6 +33,5 @@ class UnitTestSMBLoris(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
if __name__ == '__main__':
|
|
|
unittest.main()
|