Browse Source

refactor imports

So it begins ...
Jens Keim 6 years ago
parent
commit
bfb8999e4f

+ 0 - 0
code/Test/Lib.py → code/ID2TLib/TestLibrary.py


+ 7 - 6
code/Test/GenericTest.py

@@ -1,18 +1,19 @@
 import random
 import unittest
 
-from ID2TLib.Controller import Controller
-from Test.Lib import test_pcap, get_sha256, clean_up
+import ID2TLib.Controller as Ctrl
+import ID2TLib.TestLibrary as Lib
 
 
 class GenericTest(unittest.TestCase):
 
-    def generic_test(self, attack_args, sha_checksum, seed=5, cleanup=True, pcap=test_pcap, flag_write_file=False,
+    def generic_test(self, attack_args, sha_checksum, seed=5, cleanup=True, pcap=Lib.test_pcap, flag_write_file=False,
                      flag_recalculate_stats=False, flag_print_statistics=False):
+        # TODO: move seed to attacks
         random.seed(seed)
-        controller = Controller(pcap_file_path=pcap, do_extra_tests=False)
+        controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False)
         controller.load_pcap_statistics(flag_write_file, flag_recalculate_stats, flag_print_statistics)
         controller.process_attacks(attack_args)
-        self.assertEqual(get_sha256(controller.pcap_dest_path), sha_checksum)
+        self.assertEqual(Lib.get_sha256(controller.pcap_dest_path), sha_checksum)
         if cleanup:
-            clean_up(controller)
+            Lib.clean_up(controller)

+ 60 - 60
code/Test/test_BaseAttack.py

@@ -1,178 +1,178 @@
-from unittest import TestCase
-from Attack.BaseAttack import *
+import unittest
+import Attack.BaseAttack as BaseAttack
 
 
-class TestBaseAttack(TestCase):
+class TestBaseAttack(unittest.TestCase):
 
     def test_is_mac_address_valid(self):
-        self.assertTrue(BaseAttack._is_mac_address("00:80:41:ae:fd:7e"))
+        self.assertTrue(BaseAttack.BaseAttack._is_mac_address("00:80:41:ae:fd:7e"))
 
     def test_is_mac_address_invalid(self):
-        self.assertFalse(BaseAttack._is_mac_address("00:80:41:aec:fd:7e"))
+        self.assertFalse(BaseAttack.BaseAttack._is_mac_address("00:80:41:aec:fd:7e"))
 
     def test_is_mac_address_empty(self):
-        self.assertFalse(BaseAttack._is_mac_address(""))
+        self.assertFalse(BaseAttack.BaseAttack._is_mac_address(""))
 
     def test_is_mac_address_minus_valid(self):
-        self.assertTrue(BaseAttack._is_mac_address("00-80-41-ae-fd-7e"))
+        self.assertTrue(BaseAttack.BaseAttack._is_mac_address("00-80-41-ae-fd-7e"))
 
     def test_is_mac_address_minus_invalid(self):
-        self.assertFalse(BaseAttack._is_mac_address("00-80-41-aec-fd-7e"))
+        self.assertFalse(BaseAttack.BaseAttack._is_mac_address("00-80-41-aec-fd-7e"))
 
     def test_is_mac_address_list_valid(self):
-        self.assertTrue(BaseAttack._is_mac_address(["00:80:41:ae:fd:7e", "00-80-41-ae-fd-7e"]))
+        self.assertTrue(BaseAttack.BaseAttack._is_mac_address(["00:80:41:ae:fd:7e", "00-80-41-ae-fd-7e"]))
 
     def test_is_mac_address_list_invalid(self):
-        self.assertFalse(BaseAttack._is_mac_address(["00:80:41:aec:fd:7e", "00-80-41-aec-fd-7e"]))
+        self.assertFalse(BaseAttack.BaseAttack._is_mac_address(["00:80:41:aec:fd:7e", "00-80-41-aec-fd-7e"]))
 
     def test_is_ip_address_empty(self):
-        self.assertFalse(BaseAttack._is_ip_address("")[0])
+        self.assertFalse(BaseAttack.BaseAttack._is_ip_address("")[0])
 
     def test_is_ip_address_v4_valid(self):
-        self.assertTrue(BaseAttack._is_ip_address("192.168.178.1")[0])
+        self.assertTrue(BaseAttack.BaseAttack._is_ip_address("192.168.178.1")[0])
 
     def test_is_ip_address_v4_invalid(self):
-        self.assertFalse(BaseAttack._is_ip_address("192.1689.178.1")[0])
+        self.assertFalse(BaseAttack.BaseAttack._is_ip_address("192.1689.178.1")[0])
 
     def test_is_ip_address_v6_valid(self):
-        self.assertTrue(BaseAttack._is_ip_address("2001:0db8:85a3:08d3:1319:8a2e:0370:7344")[0])
+        self.assertTrue(BaseAttack.BaseAttack._is_ip_address("2001:0db8:85a3:08d3:1319:8a2e:0370:7344")[0])
 
     def test_is_ip_address_v6_invalid(self):
-        self.assertFalse(BaseAttack._is_ip_address("2001:0db8:85a3:08d3X:1319:8a2e:0370:7344")[0])
+        self.assertFalse(BaseAttack.BaseAttack._is_ip_address("2001:0db8:85a3:08d3X:1319:8a2e:0370:7344")[0])
 
     def test_is_ip_address_v6_shortened_valid(self):
-        self.assertTrue(BaseAttack._is_ip_address("2001:0db8:85a3:08d3:1319::0370:7344")[0])
+        self.assertTrue(BaseAttack.BaseAttack._is_ip_address("2001:0db8:85a3:08d3:1319::0370:7344")[0])
 
     def test_is_ip_address_v6_shortened_invalid(self):
-        self.assertFalse(BaseAttack._is_ip_address("2001::85a3:08d3X::8a2e:0370:7344")[0])
+        self.assertFalse(BaseAttack.BaseAttack._is_ip_address("2001::85a3:08d3X::8a2e:0370:7344")[0])
 
     def test_is_ip_address_list_valid(self):
-        self.assertTrue(BaseAttack._is_ip_address(["192.168.178.1", "192.168.178.10"])[0])
+        self.assertTrue(BaseAttack.BaseAttack._is_ip_address(["192.168.178.1", "192.168.178.10"])[0])
 
     def test_is_ip_address_list_invalid(self):
-        self.assertFalse(BaseAttack._is_ip_address(["192.1689.178.1", "192.168.178.10"])[0])
+        self.assertFalse(BaseAttack.BaseAttack._is_ip_address(["192.1689.178.1", "192.168.178.10"])[0])
 
     def test_is_ip_address_comma_list_valid(self):
-        self.assertTrue(BaseAttack._is_ip_address("192.168.178.1,192.168.178.10")[0])
+        self.assertTrue(BaseAttack.BaseAttack._is_ip_address("192.168.178.1,192.168.178.10")[0])
 
     def test_is_ip_address_comma_list_invalid(self):
-        self.assertFalse(BaseAttack._is_ip_address("192.168.178.1,192.1689.178.10")[0])
+        self.assertFalse(BaseAttack.BaseAttack._is_ip_address("192.168.178.1,192.1689.178.10")[0])
 
     #FIX?
     #def test_is_port_empty(self):
-        #self.assertFalse(BaseAttack._is_port(""))
+        #self.assertFalse(ba._is_port(""))
 
     #def test_is_port_empty_list(self):
-        #self.assertFalse(BaseAttack._is_port([]))
+        #self.assertFalse(ba._is_port([]))
 
     def test_is_port_valid(self):
-        self.assertTrue(BaseAttack._is_port(5000))
+        self.assertTrue(BaseAttack.BaseAttack._is_port(5000))
 
     def test_is_port_invalid(self):
-        self.assertFalse(BaseAttack._is_port(70000))
+        self.assertFalse(BaseAttack.BaseAttack._is_port(70000))
 
     def test_is_port_string_valid(self):
-        self.assertTrue(BaseAttack._is_port("5000"))
+        self.assertTrue(BaseAttack.BaseAttack._is_port("5000"))
 
     def test_is_port_string_invalid(self):
-        self.assertFalse(BaseAttack._is_port("70000"))
+        self.assertFalse(BaseAttack.BaseAttack._is_port("70000"))
 
     def test_is_port_string_comma_valid(self):
-        self.assertTrue(BaseAttack._is_port("5000, 4000, 3000"))
+        self.assertTrue(BaseAttack.BaseAttack._is_port("5000, 4000, 3000"))
 
     def test_is_port_string_comma_ivalid(self):
-        self.assertFalse(BaseAttack._is_port("5000, 70000, 3000"))
+        self.assertFalse(BaseAttack.BaseAttack._is_port("5000, 70000, 3000"))
 
     def test_is_port_valid_list(self):
-        self.assertTrue(BaseAttack._is_port([5000, 4000, 3000]))
+        self.assertTrue(BaseAttack.BaseAttack._is_port([5000, 4000, 3000]))
 
     def test_is_port_invalid_list(self):
-        self.assertFalse(BaseAttack._is_port([5000, 70000, 0]))
+        self.assertFalse(BaseAttack.BaseAttack._is_port([5000, 70000, 0]))
 
     def test_is_port_valid_string_list(self):
-        self.assertTrue(BaseAttack._is_port(["5000", "4000", "3000"]))
+        self.assertTrue(BaseAttack.BaseAttack._is_port(["5000", "4000", "3000"]))
 
     def test_is_port_invalid_string_list(self):
-        self.assertFalse(BaseAttack._is_port(["5000", "70000", "0"]))
+        self.assertFalse(BaseAttack.BaseAttack._is_port(["5000", "70000", "0"]))
 
     def test_is_port_range_valid(self):
-        self.assertTrue(BaseAttack._is_port("3000-5000"))
+        self.assertTrue(BaseAttack.BaseAttack._is_port("3000-5000"))
 
     def test_is_port_range_invalid(self):
-        self.assertFalse(BaseAttack._is_port("0-70000"))
+        self.assertFalse(BaseAttack.BaseAttack._is_port("0-70000"))
 
     def test_is_port_range_dots_valid(self):
-        self.assertTrue(BaseAttack._is_port("3000...5000"))
+        self.assertTrue(BaseAttack.BaseAttack._is_port("3000...5000"))
 
     def test_is_port_range_dots_invalid(self):
-        self.assertFalse(BaseAttack._is_port("0...70000"))
+        self.assertFalse(BaseAttack.BaseAttack._is_port("0...70000"))
 
     def test_is_port_range_list_valid(self):
-        self.assertTrue(BaseAttack._is_port(["3000-5000", "6000-7000"]))
+        self.assertTrue(BaseAttack.BaseAttack._is_port(["3000-5000", "6000-7000"]))
 
     def test_is_port_range_list_invalid(self):
-        self.assertFalse(BaseAttack._is_port(["0-70000", "6000-7000"]))
+        self.assertFalse(BaseAttack.BaseAttack._is_port(["0-70000", "6000-7000"]))
 
     def test_is_timestamp_valid(self):
-        self.assertTrue(BaseAttack._is_timestamp("2018-01-25 23:54:00"))
+        self.assertTrue(BaseAttack.BaseAttack._is_timestamp("2018-01-25 23:54:00"))
 
     def test_is_timestamp_invalid(self):
-        self.assertFalse(BaseAttack._is_timestamp("20-0100-125 23c:54x:00a"))
+        self.assertFalse(BaseAttack.BaseAttack._is_timestamp("20-0100-125 23c:54x:00a"))
 
     def test_is_boolean_invalid(self):
-        self.assertFalse(BaseAttack._is_boolean("42")[0])
+        self.assertFalse(BaseAttack.BaseAttack._is_boolean("42")[0])
 
     def test_is_boolean_valid(self):
-        self.assertTrue(BaseAttack._is_boolean(True))
-        self.assertTrue(BaseAttack._is_boolean(False))
+        self.assertTrue(BaseAttack.BaseAttack._is_boolean(True))
+        self.assertTrue(BaseAttack.BaseAttack._is_boolean(False))
 
     def test_is_boolean_valid_strings(self):
         for value in {"y", "yes", "t", "true", "on", "1", "n", "no", "f", "false", "off", "0"}:
             with self.subTest(value=value):
-                self.assertTrue(BaseAttack._is_boolean(value))
+                self.assertTrue(BaseAttack.BaseAttack._is_boolean(value))
 
     def test_is_float_valid(self):
-        self.assertTrue(BaseAttack._is_float(50.67)[0])
+        self.assertTrue(BaseAttack.BaseAttack._is_float(50.67)[0])
 
     def test_is_float_invalid(self):
-        self.assertFalse(BaseAttack._is_float("invalid")[0])
+        self.assertFalse(BaseAttack.BaseAttack._is_float("invalid")[0])
 
     def test_is_domain_valid(self):
-        self.assertTrue(BaseAttack._is_domain("foo://example.com:8042/over/there?name=ferret"))
+        self.assertTrue(BaseAttack.BaseAttack._is_domain("foo://example.com:8042/over/there?name=ferret"))
 
     def test_is_domain_invalid(self):
-        self.assertFalse(BaseAttack._is_domain("this is not a valid domain, I guess, maybe, let's find out."))
+        self.assertFalse(BaseAttack.BaseAttack._is_domain("this is not a valid domain, I guess, maybe, let's find out."))
 
     def test_is_valid_ipaddress_valid(self):
-        self.assertTrue(BaseAttack.is_valid_ip_address(BaseAttack, "192.168.178.42"))
+        self.assertTrue(BaseAttack.BaseAttack.is_valid_ip_address(BaseAttack, "192.168.178.42"))
 
     def test_is_valid_ipaddress_invalid(self):
-        self.assertFalse(BaseAttack.is_valid_ip_address(BaseAttack, "192.168.1789.42"))
+        self.assertFalse(BaseAttack.BaseAttack.is_valid_ip_address(BaseAttack, "192.168.1789.42"))
 
     def test_ip_src_dst_equal_check_equal(self):
         with self.assertRaises(SystemExit):
-            BaseAttack.ip_src_dst_equal_check(BaseAttack, "192.168.178.42", "192.168.178.42")
+            BaseAttack.BaseAttack.ip_src_dst_equal_check(BaseAttack, "192.168.178.42", "192.168.178.42")
 
     def test_ip_src_dst_equal_check_unequal(self):
-        BaseAttack.ip_src_dst_equal_check(BaseAttack, "192.168.178.42", "192.168.178.43")
+        BaseAttack.BaseAttack.ip_src_dst_equal_check(BaseAttack, "192.168.178.42", "192.168.178.43")
 
     def test_clean_whitespaces(self):
-        self.assertEqual("a\nb\rc\td\'e", BaseAttack.clean_white_spaces(BaseAttack, "a\\nb\\rc\\td\\\'e"))
+        self.assertEqual("a\nb\rc\td\'e", BaseAttack.BaseAttack.clean_white_spaces(BaseAttack, "a\\nb\\rc\\td\\\'e"))
 
     def test_generate_random_ipv4_address(self):
-        ip_list = BaseAttack.generate_random_ipv4_address("Unknown", 10)
+        ip_list = BaseAttack.BaseAttack.generate_random_ipv4_address("Unknown", 10)
         for ip in ip_list:
             with self.subTest(ip=ip):
-                self.assertTrue(BaseAttack._is_ip_address(ip))
+                self.assertTrue(BaseAttack.BaseAttack._is_ip_address(ip))
 
     def test_generate_random_ipv6_address(self):
-        ip_list = BaseAttack.generate_random_ipv6_address(10)
+        ip_list = BaseAttack.BaseAttack.generate_random_ipv6_address(10)
         for ip in ip_list:
             with self.subTest(ip=ip):
-                self.assertTrue(BaseAttack._is_ip_address(ip))
+                self.assertTrue(BaseAttack.BaseAttack._is_ip_address(ip))
 
     def test_generate_random_mac_address(self):
-        mac_list = BaseAttack.generate_random_mac_address(10)
+        mac_list = BaseAttack.BaseAttack.generate_random_mac_address(10)
         for mac in mac_list:
             with self.subTest(mac=mac):
-                self.assertTrue(BaseAttack._is_mac_address(mac))
+                self.assertTrue(BaseAttack.BaseAttack._is_mac_address(mac))

+ 2 - 4
code/Test/test_EternalBlue.py

@@ -1,8 +1,6 @@
 import unittest
-import unittest.mock as mock
 
-from Test.GenericTest import GenericTest
-from Test.Lib import test_pcap_ips
+import Test.GenericTest as GenTest
 
 sha_default = 'c707492a0493efcf46a569c91fe77685286402ddfdff3c79e64157b3324dc9f6'
 
@@ -15,7 +13,7 @@ Attack/EternalBlueExploit.py       246     10    96%   62, 72, 112, 119, 126-127
 # TODO: get 100% coverage
 
 
-class UnitTestEternalBlue(GenericTest):
+class UnitTestEternalBlue(GenTest.GenericTest):
 
     def test_default(self):
         self.generic_test([['EternalBlueExploit']], sha_default)

+ 19 - 19
code/Test/test_FTPWinaXeExploit.py

@@ -1,8 +1,8 @@
 import unittest
 import unittest.mock as mock
 
-from Test.GenericTest import GenericTest
-from Test.Lib import *
+import ID2TLib.TestLibrary as Lib
+import Test.GenericTest as GenericTest
 
 sha_ftp_basic = 'ad9bc7b55c3b0365c0f02ae9b9b7aafdb43acbdd8c8c274d30cb286821e772cc'
 sha_ftp_most_used_ip = 'ad9bc7b55c3b0365c0f02ae9b9b7aafdb43acbdd8c8c274d30cb286821e772cc'
@@ -20,47 +20,47 @@ Attack/FTPWinaXeExploit.py         141     14    99%    67
 # TODO: get 100% coverage
 
 
-class UnitTestFTPWinaXeExploit(GenericTest):
+class UnitTestFTPWinaXeExploit(GenericTest.GenericTest):
 
-    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
-    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
+    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
+    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
     def test_ftp_basic(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
         self.generic_test([['FTPWinaXeExploit']], sha_ftp_basic)
 
-    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
-    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
+    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
+    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
     @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_ip_address')
     def test_ftp_most_used_ips(self,mock_most_used_ip_address, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
-        mock_most_used_ip_address.return_value = test_pcap_ips
+        mock_most_used_ip_address.return_value = Lib.test_pcap_ips
         self.generic_test([['FTPWinaXeExploit']], sha_ftp_most_used_ip)
 
-    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
-    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
+    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
+    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
     @mock.patch('ID2TLib.Statistics.Statistics.get_mac_address')
     def test_ftp_mac(self, mock_mac_address, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
-        mock_mac_address.return_value = test_pcap_empty
+        mock_mac_address.return_value = Lib.test_pcap_empty
         self.generic_test([['FTPWinaXeExploit']], sha_ftp_mac)
 
-    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
-    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
+    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
+    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
     def test_ftp_random_ip_src(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
         self.generic_test([['FTPWinaXeExploit', 'ip.src.shuffle=1']], sha_ftp_random_ip_src)
 
-    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
-    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
+    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
+    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
     def test_ftp_not_empty_custom_payload_empty_file(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
         self.generic_test([['FTPWinaXeExploit', 'custom.payload=1']], sha_not_empty_custom_payload_empty_file)
 
-    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
-    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
+    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
+    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
     @mock.patch('ID2TLib.Utility.check_payload_len')
     @mock.patch('ID2TLib.Utility.get_bytes_from_file', return_value=b'AAAAA')
     def test_ftp_empty_custom_payload_not_empty_file(self, mock_bytes_from_file, mock_payload_len, mock_get_rnd_x86_nop,
                                                      mock_get_rnd_bytes):
         self.generic_test([['FTPWinaXeExploit', 'custom.payload.file=1']], sha_empty_custom_payload_not_empty_file)
 
-    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=get_bytes)
-    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=get_x86_nop)
+    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
+    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
     @mock.patch('Attack.BaseAttack.BaseAttack.is_valid_ip_address', return_values=[False, True])
     def test_ftp_invalid_ip(self, mock_valid_ip_check, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
         self.generic_test([['FTPWinaXeExploit']], sha_valid_ip)

+ 2 - 4
code/Test/test_Joomla.py

@@ -1,8 +1,6 @@
 import unittest
-import unittest.mock as mock
 
-from Test.GenericTest import GenericTest
-from Test.Lib import test_pcap_ips
+import Test.GenericTest as GenericTest
 
 sha_default = 'a45bd543ae7416cdc5fd76c886f48990b43075753931683407686aac2cfbc111'
 
@@ -15,7 +13,7 @@ Attack/JoomlaRegPrivExploit.py     127      4    97%   62, 71, 116, 123
 # TODO: get 100% coverage
 
 
-class UnitTestJoomla(GenericTest):
+class UnitTestJoomla(GenericTest.GenericTest):
 
     def test_default(self):
         self.generic_test([['JoomlaRegPrivExploit']], sha_default)

+ 2 - 2
code/Test/test_PortscanAttack.py

@@ -1,8 +1,8 @@
 import unittest
 import unittest.mock as mock
 
+import ID2TLib.TestLibrary as Lib
 from Test.GenericTest import GenericTest
-from Test.Lib import *
 
 sha_portscan_default = '6af539fb9f9a28f84a5c337a07dbdc1a11885c5c6de8f9a682bd74b89edc5130'
 sha_portscan_reverse_ports = '1c03342b7b94fdd1c9903d07237bc5239ebb7bd77a3dd137c9c378fa216c5382'
@@ -51,7 +51,7 @@ class UnitTestPortscanAttack(GenericTest):
 
     @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_ip_address')
     def test_portscan_most_used_ips(self, mock_most_used_ip_address):
-        mock_most_used_ip_address.return_value = test_pcap_ips
+        mock_most_used_ip_address.return_value = Lib.test_pcap_ips
         self.generic_test([['PortscanAttack']], sha_portscan_most_used_ip_in_list)
 
 

+ 22 - 19
code/Test/test_SMBLib.py

@@ -1,24 +1,26 @@
-from unittest import TestCase
-from ID2TLib.SMBLib import *
-from ID2TLib.Utility import platforms, get_filetime_format
+import unittest
 
+import ID2TLib.SMBLib as SMBLib
+import ID2TLib.Utility as Utility
 
-class TestSMBLib(TestCase):
+
+class TestSMBLib(unittest.TestCase):
 
     def test_get_smb_version_all(self):
 
-        for platform in platforms:
+        for platform in Utility.platforms:
             with self.subTest(platform):
-                result = get_smb_version(platform)
-                self.assertTrue((result in smb_versions_per_win.values() or result in smb_versions_per_samba.values()))
+                result = SMBLib.get_smb_version(platform)
+                self.assertTrue((result in SMBLib.smb_versions_per_win.values() or
+                                 result in SMBLib.smb_versions_per_samba.values()))
 
     def test_get_smb_version_invalid(self):
 
         with self.assertRaises(SystemExit):
-            get_smb_version("abc")
+            SMBLib.get_smb_version("abc")
 
     def test_get_smb_version_mac(self):
-        self.assertEqual(get_smb_version("macos"), "2.1")
+        self.assertEqual(SMBLib.get_smb_version("macos"), "2.1")
 
     def test_get_smb_version_win(self):
 
@@ -26,32 +28,33 @@ class TestSMBLib(TestCase):
 
         for platform in win_platforms:
             with self.subTest(platform):
-                self.assertIn(get_smb_version(platform), smb_versions_per_win.values())
+                self.assertIn(SMBLib.get_smb_version(platform), SMBLib.smb_versions_per_win.values())
 
     def test_get_smb_version_linux(self):
-        self.assertIn(get_smb_version("linux"), smb_versions_per_samba.values())
+        self.assertIn(SMBLib.get_smb_version("linux"), SMBLib.smb_versions_per_samba.values())
 
     def test_get_smb_platform_data_invalid(self):
 
         with self.assertRaises(SystemExit):
-            get_smb_platform_data("abc", 0)
+            SMBLib.get_smb_platform_data("abc", 0)
 
     def test_get_smb_platform_data_linux(self):
-        self.assertEqual((get_smb_platform_data("linux", 0)), ("ubuntu", security_blob_ubuntu, 0x5, 0x800000, 0))
+        self.assertEqual((SMBLib.get_smb_platform_data("linux", 0)),
+                         ("ubuntu", SMBLib.security_blob_ubuntu, 0x5, 0x800000, 0))
 
     def test_get_smb_platform_data_mac(self):
-        guid, blob, cap, d_size, time = get_smb_platform_data("macos", 0)
-        self.assertEqual((blob, cap, d_size, time), (security_blob_macos, 0x6, 0x400000, 0))
+        guid, blob, cap, d_size, time = SMBLib.get_smb_platform_data("macos", 0)
+        self.assertEqual((blob, cap, d_size, time), (SMBLib.security_blob_macos, 0x6, 0x400000, 0))
         self.assertTrue(isinstance(guid, str) and len(guid) > 0)
 
     def test_get_smb_platform_data_win(self):
-        guid, blob, cap, d_size, time = get_smb_platform_data("win7", 100)
-        self.assertEqual((blob, cap, d_size), (security_blob_windows, 0x7, 0x100000))
+        guid, blob, cap, d_size, time = SMBLib.get_smb_platform_data("win7", 100)
+        self.assertEqual((blob, cap, d_size), (SMBLib.security_blob_windows, 0x7, 0x100000))
         self.assertTrue(isinstance(guid, str) and len(guid) > 0)
-        self.assertTrue(time <= get_filetime_format(100))
+        self.assertTrue(time <= Utility.get_filetime_format(100))
 
     def test_invalid_smb_version(self):
         with self.assertRaises(SystemExit):
-            invalid_smb_version("abc")
+            SMBLib.invalid_smb_version("abc")
 
 

+ 4 - 4
code/Test/test_SMBLoris.py

@@ -1,8 +1,8 @@
 import unittest
 import unittest.mock as mock
 
+import ID2TLib.TestLibrary as Lib
 from Test.GenericTest import GenericTest
-from Test.Lib import test_pcap_ips
 
 sha_default = 'cbfb154a80546ebcf0a0d5128bcc42e4d69228c1d97ea4dda49ba156703b78c2'
 sha_one_attacker = 'a316ba1a667318ef4b8d1bf5ffee3f58dfcd0221b0cc3ab62dd967379217eb27'
@@ -27,8 +27,8 @@ class UnitTestSMBLoris(GenericTest):
         self.generic_test([['SMBLorisAttack', 'ip.src=192.168.1.240', 'ip.dst=192.168.1.210']], sha_one_attacker)
 
     def test_ips_in_pcap(self):
-        ip_src = 'ip.src='+test_pcap_ips[0]
-        ip_dst = 'ip.dst='+test_pcap_ips[1]
+        ip_src = 'ip.src='+Lib.test_pcap_ips[0]
+        ip_dst = 'ip.dst='+Lib.test_pcap_ips[1]
         self.generic_test([['SMBLorisAttack', ip_src, ip_dst]], sha_ips_in_pcap)
 
     def test_sixteen_attackers(self):
@@ -36,7 +36,7 @@ class UnitTestSMBLoris(GenericTest):
 
     @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_ip_address')
     def test_two_most_used_ips(self, mock_most_used_ip_address):
-        mock_most_used_ip_address.return_value = test_pcap_ips
+        mock_most_used_ip_address.return_value = Lib.test_pcap_ips
         self.generic_test([['SMBLorisAttack']], sha_default)
 
     def test_same_ip_src_dst(self):

+ 2 - 2
code/Test/test_SMBScan.py

@@ -1,7 +1,7 @@
 import unittest
 import unittest.mock as mock
 
-from Test.GenericTest import GenericTest
+import Test.GenericTest as GenericTest
 
 sha_default = '264b243c9b67978f3c892327352f4b293c9a79f6023b06b53d0af7628d171c0b'
 sha_one_victim_linux = '4928d421caaec8f2c4e5c5bb835b5521b705478779cbc8f343b77143a5a66995'
@@ -21,7 +21,7 @@ Attack/SMBScanAttack.py            239      9    96%   65, 73-74, 82, 193, 210-2
 # TODO: get 100% coverage
 
 
-class UnitTestSMBScan(GenericTest):
+class UnitTestSMBScan(GenericTest.GenericTest):
 
     def test_default(self):
         with mock.patch("ID2TLib.Utility.get_rnd_os", return_value="win7"):

+ 2 - 4
code/Test/test_SQLi.py

@@ -1,8 +1,6 @@
 import unittest
-import unittest.mock as mock
 
-from Test.GenericTest import GenericTest
-from Test.Lib import test_pcap_ips
+import Test.GenericTest as GenericTest
 
 sha_default = 'a130ecdaf5fd8c09ef8418d2dbe7bd68c54e922553eb9fa703df016115393a46'
 
@@ -15,7 +13,7 @@ Attack/SQLiAttack.py               159      5    97%   62, 71, 113, 120, 245
 # TODO: get 100% coverage
 
 
-class UnitTestSQLi(GenericTest):
+class UnitTestSQLi(GenericTest.GenericTest):
 
     def test_default(self):
         self.generic_test([['SQLiAttack']], sha_default)

+ 4 - 4
code/Test/test_SalityBotnet.py

@@ -1,8 +1,8 @@
 import unittest
 import unittest.mock as mock
 
-from Test.GenericTest import GenericTest
-from Test.Lib import test_pcap_ips
+import ID2TLib.TestLibrary as Lib
+import Test.GenericTest as GenericTest
 
 sha_botnet_basic = '8ff1e400dcf01d2d2cb97312cecdb71473ea140f6406ea935f74970aecdd7305'
 sha_botnet_most_used_ip_in_list = '8ff1e400dcf01d2d2cb97312cecdb71473ea140f6406ea935f74970aecdd7305'
@@ -16,14 +16,14 @@ Attack/SalityBotnet.py           77      0    100%
 # TODO: get 100% coverage
 
 
-class UnitTestSalityBotnet(GenericTest):
+class UnitTestSalityBotnet(GenericTest.GenericTest):
 
     def test_botnet_basic(self):
         self.generic_test([['SalityBotnet']], sha_botnet_basic)
 
     @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_ip_address')
     def test_botnet_most_used_ips(self, mock_most_used_ip_address):
-        mock_most_used_ip_address.return_value = test_pcap_ips
+        mock_most_used_ip_address.return_value = Lib.test_pcap_ips
         self.generic_test([['SalityBotnet']], sha_botnet_most_used_ip_in_list)
 
 

+ 53 - 52
code/Test/test_Utility.py

@@ -1,154 +1,155 @@
-from unittest import TestCase
-from ID2TLib.Utility import *
-from Test.Lib import test_resource_dir
+import unittest
 
+import ID2TLib.TestLibrary as TestLibrary
+import ID2TLib.Utility as Utility
 
-class TestUtility(TestCase):
+
+class TestUtility(unittest.TestCase):
 
     def test_update_timestamp_no_delay(self):
-        self.assertTrue(100+10/5 >= update_timestamp(100, 5) >= 100+1/5)
+        self.assertTrue(100+10/5 >= Utility.update_timestamp(100, 5) >= 100+1/5)
 
     def test_update_timestamp_with_delay(self):
-        self.assertTrue(100+1/5+10*100 >= update_timestamp(100, 5, 10) >= 100+1/5+10)
+        self.assertTrue(100+1/5+10*100 >= Utility.update_timestamp(100, 5, 10) >= 100+1/5+10)
 
     def test_update_timestamp_comparison(self):
-        self.assertTrue(update_timestamp(100, 5) <= update_timestamp(100, 5, 10))
+        self.assertTrue(Utility.update_timestamp(100, 5) <= Utility.update_timestamp(100, 5, 10))
 
     def test_get_interval_pps_below_max(self):
         cipps = [(5, 1), (10, 2), (15, 3)]
-        self.assertEqual(get_interval_pps(cipps, 3), 1)
-        self.assertEqual(get_interval_pps(cipps, 7), 2)
-        self.assertEqual(get_interval_pps(cipps, 12), 3)
+        self.assertEqual(Utility.get_interval_pps(cipps, 3), 1)
+        self.assertEqual(Utility.get_interval_pps(cipps, 7), 2)
+        self.assertEqual(Utility.get_interval_pps(cipps, 12), 3)
 
     def test_get_interval_pps_above_max(self):
         cipps = [(5, 1), (10, 2), (15, 3)]
-        self.assertEqual(get_interval_pps(cipps, 30), 3)
+        self.assertEqual(Utility.get_interval_pps(cipps, 30), 3)
 
     # Errors if empty list and result bad if only one list
     def test_get_nth_random_element_equal_no(self):
         letters = ["A", "B", "C"]
         numbers = [1, 2, 3]
         results = [("A", 1), ("B", 2), ("C", 3)]
-        self.assertIn(get_nth_random_element(letters, numbers), results)
+        self.assertIn(Utility.get_nth_random_element(letters, numbers), results)
 
     def test_get_nth_random_element_unequal_no(self):
         letters = ["A", "B", "C"]
         numbers = [1, 2]
         results = [("A", 1), ("B", 2)]
-        self.assertIn(get_nth_random_element(letters, numbers), results)
+        self.assertIn(Utility.get_nth_random_element(letters, numbers), results)
 
     #def test_get_nth_random_element_single_list(self):
         #letters = ["A", "B", "C"]
-        #self.assertIn(get_nth_random_element(letters), letters)
+        #self.assertIn(Utility.get_nth_random_element(letters), letters)
 
     def test_index_increment_not_max(self):
-        self.assertEqual(index_increment(5, 10), 6)
+        self.assertEqual(Utility.index_increment(5, 10), 6)
 
     def test_index_increment_max(self):
-        self.assertEqual(index_increment(10, 10), 0)
+        self.assertEqual(Utility.index_increment(10, 10), 0)
 
     # Correct?
     def test_index_increment_max2(self):
-        self.assertEqual(index_increment(9, 10), 0)
+        self.assertEqual(Utility.index_increment(9, 10), 0)
 
     def test_get_rnd_os(self):
-        self.assertIn(get_rnd_os(), platforms)
+        self.assertIn(Utility.get_rnd_os(), Utility.platforms)
 
     def test_check_platform_valid(self):
-        check_platform("linux")
+        Utility.check_platform("linux")
 
     def test_check_platform_invalid(self):
         with self.assertRaises(SystemExit):
-            check_platform("abc")
+            Utility.check_platform("abc")
 
     def test_get_ip_range_forwards(self):
         start = "192.168.178.254"
         end = "192.168.179.1"
         result = ["192.168.178.254", "192.168.178.255", "192.168.179.0", "192.168.179.1"]
-        self.assertEqual(get_ip_range(start, end), result)
+        self.assertEqual(Utility.get_ip_range(start, end), result)
 
     def test_get_ip_range_backwards(self):
         end = "192.168.178.254"
         start = "192.168.179.1"
         result = ["192.168.179.1", "192.168.179.0", "192.168.178.255", "192.168.178.254"]
-        self.assertEqual(get_ip_range(start, end), result)
+        self.assertEqual(Utility.get_ip_range(start, end), result)
 
     def test_get_ip_range_equal(self):
         end = "192.168.178.254"
         start = "192.168.178.254"
         result = ["192.168.178.254"]
-        self.assertEqual(get_ip_range(start, end), result)
+        self.assertEqual(Utility.get_ip_range(start, end), result)
 
     def test_generate_source_port_from_platform_invalid(self):
         with self.assertRaises(SystemExit):
-            generate_source_port_from_platform("abc")
+            Utility.generate_source_port_from_platform("abc")
 
     def test_generate_source_port_from_platform_oldwin_firstport(self):
-        self.assertTrue(1024 <= generate_source_port_from_platform("winxp") <= 5000)
+        self.assertTrue(1024 <= Utility.generate_source_port_from_platform("winxp") <= 5000)
 
     def test_generate_source_port_from_platform_oldwin_nextport(self):
-        self.assertEqual(generate_source_port_from_platform("winxp", 2000), 2001)
+        self.assertEqual(Utility.generate_source_port_from_platform("winxp", 2000), 2001)
 
     def test_generate_source_port_from_platform_oldwin_maxport(self):
-        self.assertTrue(1024 <= generate_source_port_from_platform("winxp", 5000) <= 5000)
+        self.assertTrue(1024 <= Utility.generate_source_port_from_platform("winxp", 5000) <= 5000)
 
     def test_generate_source_port_from_platform_linux(self):
-        self.assertTrue(32768 <= generate_source_port_from_platform("linux") <= 61000)
+        self.assertTrue(32768 <= Utility.generate_source_port_from_platform("linux") <= 61000)
 
     def test_generate_source_port_from_platform_newwinmac_firstport(self):
-        self.assertTrue(49152 <= generate_source_port_from_platform("win7") <= 65535)
+        self.assertTrue(49152 <= Utility.generate_source_port_from_platform("win7") <= 65535)
 
     def test_generate_source_port_from_platform_newwinmac_nextport(self):
-        self.assertEqual(generate_source_port_from_platform("win7", 50000), 50001)
+        self.assertEqual(Utility.generate_source_port_from_platform("win7", 50000), 50001)
 
     def test_generate_source_port_from_platform_newwinmac_maxport(self):
-        self.assertTrue(49152 <= generate_source_port_from_platform("win7", 65535) <= 65535)
+        self.assertTrue(49152 <= Utility.generate_source_port_from_platform("win7", 65535) <= 65535)
 
     # Test get_filetime_format????
 
     def test_get_rnd_boot_time_invalid(self):
         with self.assertRaises(SystemExit):
-            get_rnd_boot_time(10, "abc")
+            Utility.get_rnd_boot_time(10, "abc")
 
     def test_get_rnd_boot_time_linux(self):
-        self.assertTrue(get_rnd_boot_time(100, "linux") < 100)
+        self.assertTrue(Utility.get_rnd_boot_time(100, "linux") < 100)
 
     def test_get_rnd_boot_time_macos(self):
-        self.assertTrue(get_rnd_boot_time(100, "macos") < 100)
+        self.assertTrue(Utility.get_rnd_boot_time(100, "macos") < 100)
 
     def test_get_rnd_boot_time_win(self):
-        self.assertTrue(get_rnd_boot_time(100, "win7") < 100)
+        self.assertTrue(Utility.get_rnd_boot_time(100, "win7") < 100)
 
     def test_get_rnd_x86_nop_len(self):
-        result = get_rnd_x86_nop(1000)
+        result = Utility.get_rnd_x86_nop(1000)
         self.assertEqual(len(result), 1000)
 
     def test_get_rnd_x86_nop_with_sideeffects(self):
-        result = get_rnd_x86_nop(1000, False)
+        result = Utility.get_rnd_x86_nop(1000, False)
         correct = True
         for byte in result:
-            if byte.to_bytes(1, "little") not in x86_nops and byte.to_bytes(1, "little") not in x86_pseudo_nops:
+            if byte.to_bytes(1, "little") not in TestLibrary.x86_nops and byte.to_bytes(1, "little") not in TestLibrary.x86_pseudo_nops:
                 correct = False
         self.assertTrue(correct)
 
     def test_get_rnd_x86_nop_without_sideeffects(self):
-        result = get_rnd_x86_nop(1000, True)
+        result = Utility.get_rnd_x86_nop(1000, True)
         correct = True
         for byte in result:
-            if byte.to_bytes(1, "little") in x86_pseudo_nops:
+            if byte.to_bytes(1, "little") in Utility.x86_pseudo_nops:
                 correct = False
         self.assertTrue(correct)
 
     def test_get_rnd_x86_nop_filter(self):
-        result = get_rnd_x86_nop(1000, False, x86_nops.copy())
+        result = Utility.get_rnd_x86_nop(1000, False, Utility.x86_nops.copy())
         correct = True
         for byte in result:
-            if byte.to_bytes(1, "little") in x86_nops:
+            if byte.to_bytes(1, "little") in Utility.x86_nops:
                 correct = False
         self.assertTrue(correct)
 
     def test_get_rnd_x86_nop_single_filter(self):
-        result = get_rnd_x86_nop(1000, False, b'\x20')
+        result = Utility.get_rnd_x86_nop(1000, False, b'\x20')
         correct = True
         for byte in result:
             if byte.to_bytes(1, "little") == b'\x20':
@@ -156,37 +157,37 @@ class TestUtility(TestCase):
         self.assertTrue(correct)
 
     def test_get_rnd_bytes_number(self):
-        result = get_rnd_bytes(1000)
+        result = Utility.get_rnd_bytes(1000)
         self.assertEqual(len(result), 1000)
 
     def test_get_rnd_bytes_filter(self):
-        result = get_rnd_bytes(1000, x86_pseudo_nops.copy())
+        result = Utility.get_rnd_bytes(1000, Utility.x86_pseudo_nops.copy())
         correct = True
         for byte in result:
-            if byte.to_bytes(1, "little") in x86_pseudo_nops:
+            if byte.to_bytes(1, "little") in Utility.x86_pseudo_nops:
                 correct = False
         self.assertTrue(correct)
 
     def test_get_bytes_from_file_invalid_path(self):
         with self.assertRaises(SystemExit):
-            get_bytes_from_file(test_resource_dir+"/NonExistingFile.txt")
+            Utility.get_bytes_from_file(TestLibrary.test_resource_dir+"/NonExistingFile.txt")
 
     def test_get_bytes_from_file_invalid_header(self):
         with self.assertRaises(SystemExit):
-            get_bytes_from_file(test_resource_dir+"/InvalidHeader.txt")
+            Utility.get_bytes_from_file(TestLibrary.test_resource_dir+"/InvalidHeader.txt")
 
     def test_get_bytes_from_file_invalid_hexfile(self):
         with self.assertRaises(SystemExit):
-            get_bytes_from_file(test_resource_dir+"/InvalidHexFile.txt")
+            Utility.get_bytes_from_file(TestLibrary.test_resource_dir+"/InvalidHexFile.txt")
 
     def test_get_bytes_from_file_invalid_strfile(self):
         with self.assertRaises(SystemExit):
-            get_bytes_from_file(test_resource_dir+"/InvalidStringFile.txt")
+            Utility.get_bytes_from_file(TestLibrary.test_resource_dir+"/InvalidStringFile.txt")
 
     def test_get_bytes_from_file_str(self):
-        result = get_bytes_from_file(test_resource_dir+"/StringTestFile.txt")
+        result = Utility.get_bytes_from_file(TestLibrary.test_resource_dir+"/StringTestFile.txt")
         self.assertEqual(result, b'This is a string-test')
 
     def test_get_bytes_from_file_hex(self):
-        result = get_bytes_from_file(test_resource_dir+"/HexTestFile.txt")
+        result = Utility.get_bytes_from_file(TestLibrary.test_resource_dir+"/HexTestFile.txt")
         self.assertEqual(result, b'\xab\xcd\xef\xff\x10\xff\xaa\xab')