Browse Source

fix CaptureDuration calculation

fix issue #118
remove calculation
use static_cast
adjust internalQueries tests accordingly
increase DB_VERSION
change hashes in Test/test_EternalBlueExploit.py
change hashes in Test/test_FTPWinaXeExploit.py
change hashes in Test/test_JoomlaRegPrivExploit.py
change hashes in Test/test_MemcrashedSpooferAttack.py
change hashes in Test/test_MS17ScanAttack.py
change hashes in Test/test_PortscanAttack.py
change hashes in Test/test_SalityBotnet.py
change hashes in Test/test_SMBLorisAttack.py
change hashes in Test/test_SMBScanAttack.py
change hashes in Test/test_SQLiAttack.py
to match changes in database
Jens Keim 6 years ago
parent
commit
971df14819

+ 3 - 3
code/Test/test_EternalBlueExploit.py

@@ -1,9 +1,9 @@
 import ID2TLib.TestLibrary as Lib
 import Test.ID2TAttackTest as Test
 
-sha_default = '0ea04ea0ac61092aee244d56b2efd2e48056b9006c530e708f46b3cb2a9c314b'
-sha_ips_not_in_pcap = '03b7d1d2b0c9999aa607ce9ef7186c5f352d2330145a0f9774109d0f21c03aea'
-sha_multiple_params = '1f97161c38c2d586a7aedafe265747401317ecd6f1747af5216bb41af7b3aaf8'
+sha_default = '5a997aa3e1be1a34b46ea3308fece71336fae5f47e45d7ef4b26a8e4982f21e3'
+sha_ips_not_in_pcap = '32919a785133574c536ea383dce70874b76d60a5c41679b94822177acd6263b1'
+sha_multiple_params = '07eb84bd0cb695012d2d4aa5b3ba7943e4eadbc86dd538bbc64f6768a3516d8d'
 
 # TODO: improve coverage
 

+ 6 - 6
code/Test/test_FTPWinaXeExploit.py

@@ -3,12 +3,12 @@ import unittest.mock as mock
 import ID2TLib.TestLibrary as Lib
 import Test.ID2TAttackTest as Test
 
-sha_ftp_basic = 'ad9bc7b55c3b0365c0f02ae9b9b7aafdb43acbdd8c8c274d30cb286821e772cc'
-sha_ftp_mac = '388831100c907cfc6815bcc1869f30d937be29091dd8e54a734eb52f14a23f3c'
-sha_ftp_random_ip_src = 'b18c0f1d15f1afb239116e1ccec20b03716412eea58ca969f7d2ede1749409e3'
-sha_not_empty_custom_payload_empty_file = '41186fc804fb2a8fb3605be3246a5246be927e3187ea82bd2fbe2097643863a8'
-sha_empty_custom_payload_not_empty_file = 'b1f43c3147dd3684b1db4d7d370801f25de693b632b97a95b933a4d296094f31'
-sha_valid_ip = 'ad9bc7b55c3b0365c0f02ae9b9b7aafdb43acbdd8c8c274d30cb286821e772cc'
+sha_ftp_basic = '3152c9b06a1c7f45b4bfcd7c1947c9d924701b1f90947e9cac9f9b52efa85fb5'
+sha_ftp_mac = '95a3a68e0b8d7ed414082e9abfe9806de6b62cdbee0747f2ba751b2367255646'
+sha_ftp_random_ip_src = '3d175f9d5a19682fd2122161b6f9cd6189a32d7547f78e998600803a3952138d'
+sha_not_empty_custom_payload_empty_file = '62fd066efc6f12d4d0641e4851c10ac29b647aa330d2e1ba6938a639e8b2445e'
+sha_empty_custom_payload_not_empty_file = '68e26d70f33c4fd6c004bbf3458c2847cbee7ab1d316247750754a31081fc8b6'
+sha_valid_ip = '3152c9b06a1c7f45b4bfcd7c1947c9d924701b1f90947e9cac9f9b52efa85fb5'
 # TODO: improve coverage
 
 

+ 3 - 3
code/Test/test_JoomlaRegPrivExploit.py

@@ -1,9 +1,9 @@
 import ID2TLib.TestLibrary as Lib
 import Test.ID2TAttackTest as Test
 
-sha_default = 'a45bd543ae7416cdc5fd76c886f48990b43075753931683407686aac2cfbc111'
-sha_ips_not_in_pcap = 'bb3926cea75624124777422b68de8f1e699b3219e279f5a9bcd789ed837aa349'
-sha_multiple_params = '6a39bafde84f30c63389c35ba24446d5aabb8e8942ee3a34974556211d6091d8'
+sha_default = '3063eaf16f7344034e4ecb9b5a0cf6da8e160cb75f268dd3dfd3ad40b7c373a0'
+sha_ips_not_in_pcap = '69089b1832b62dfa4bdbc93a47db570e5c88fd78aad06cb440df9be312a4ee93'
+sha_multiple_params = '83addb1f0ef39bf74454dd88c14114cd5016f28538450b58ab6b545669427c87'
 
 # TODO: improve coverage
 

+ 3 - 3
code/Test/test_MS17ScanAttack.py

@@ -1,9 +1,9 @@
 import ID2TLib.TestLibrary as Lib
 import Test.ID2TAttackTest as Test
 
-sha_default = '7251523bec9294756ac7ced1ad8b3c53625fdad8648b86915c8a4699300ce46a'
-sha_ips_not_in_pcap = '6d150cf267fba423b5dabe44b36bee37b0d626c15041131a1f01a81f36ea3dfd'
-sha_multiple_params = '765f71390a75827fc362d55c07a2d46d74c6b918b767ae1da2706247adb60919'
+sha_default = 'a04d77120dbd20b789a5224c629f655a010c8a99b57330039dd15da09303011a'
+sha_ips_not_in_pcap = '195e798169c6dc1eec7a006eb75738a4bceca8c28e8dc920fc3d9b5804722eeb'
+sha_multiple_params = '594bb82f94c20bde35ccffc485542f68342a2cb2dbc9bdeda933d345c768d570'
 
 
 class UnitTestMS17Scan(Test.ID2TAttackTest):

+ 2 - 2
code/Test/test_MemcrashedSpooferAttack.py

@@ -1,7 +1,7 @@
 import Test.ID2TAttackTest as Test
 
-sha_default = "065e7de040fb41bcaad81b705fb70f3e07807f0d3dc1efe0f437929ff33b49f8"
-sha_ips_not_in_pcap = "46c015fde4509227ee70fbe1557fe0efd3ac76abf58e00dcbbcf09d0b950fb5f"
+sha_default = "88c62360baee6067a8f0e9c002c329bf800b59aab2c7f97ccad5e76cfd00a5b2"
+sha_ips_not_in_pcap = "83d47486673a87fda0bed8842e406738053cdff519746165565d71cda6d968cc"
 
 
 class UnitTestMemcrashedSpooferAttack(Test.ID2TAttackTest):

+ 5 - 5
code/Test/test_PortscanAttack.py

@@ -1,11 +1,11 @@
 import Test.ID2TAttackTest as Test
 
-sha_portscan_default = '6af539fb9f9a28f84a5c337a07dbdc1a11885c5c6de8f9a682bd74b89edc5130'
-sha_portscan_reverse_ports = '1c03342b7b94fdd1c9903d07237bc5239ebb7bd77a3dd137c9c378fa216c5382'
-sha_portscan_shuffle_dst_ports = '40485e47766438425900b787c4cda4ad1b5cd0d233b80f38bd45b5a88b70a797'
-sha_portscan_shuffle_src_ports = '48578b45e18bdbdc0a9f3f4cec160ccb58839250348ec4d3ec44c1b15da248de'
+sha_portscan_default = 'b70c543c8d9bb4bf7ef8cfe09c23254a968c66a9f4174aea0ec2aa65bc1f090f'
+sha_portscan_reverse_ports = '0ea771c6ded24cb667c00d490653ee620f5c29975e966d14dd5bba5008048eac'
+sha_portscan_shuffle_dst_ports = 'dea87a34d21d7efa8128fa2d7471e2b4265ad4e150b00b24da8e182149e6fe81'
+sha_portscan_shuffle_src_ports = 'cf0fe4c8f9d0d1f016aaebe6ce0a3d66af72d1c6cbc4c671391374506d7f5a9e'
 sha_portscan_ip_src_random = 'c3939f30a40fa6e2164cc91dc4a7e823ca409492d44508e3edfc9d24748af0e5'
-sha_portscan_ips_not_in_pcap = '7f0f65beb8398fc1abe65b0819b6e3a5ce143fd8c9eafb2d5498b84f21cec9e1'
+sha_portscan_ips_not_in_pcap = 'd4703defeaaf8d421f79eb15eb019eed6d4644448054cebcb0caba300d3e0012'
 
 # TODO: improve coverage
 

+ 4 - 4
code/Test/test_SMBLorisAttack.py

@@ -1,10 +1,10 @@
 import ID2TLib.TestLibrary as Lib
 import Test.ID2TAttackTest as Test
 
-sha_default = 'cbfb154a80546ebcf0a0d5128bcc42e4d69228c1d97ea4dda49ba156703b78c2'
-sha_one_attacker = 'a316ba1a667318ef4b8d1bf5ffee3f58dfcd0221b0cc3ab62dd967379217eb27'
-sha_sixteen_attackers = '08b17b360ee9be1657e7c437e5aef354dac374ceca3b4ee437c45c0d9d03a2ef'
-sha_ips_in_pcap = 'f299e4139780869d9f02c25ba00f1cad483a4f215d6aef4079b93f7f7e1de22a'
+sha_default = 'b69f106ec7c86ff28d7434206de2243b9641d8a7e569363d8670e4c1cfe89819'
+sha_one_attacker = 'faa38854094245aa057afbc1cc4dbad3a82a2b62bdf365e491becde5f9e6e1eb'
+sha_sixteen_attackers = 'ff9567a3510f1707fd1a846ab383d005f39eca9bd839d619c280cc2010ca77c4'
+sha_ips_in_pcap = '2088d512d77020c64f358c8f661af6b0d33066dad023af04518e91c0e8934227'
 
 # TODO: improve coverage
 

+ 8 - 8
code/Test/test_SMBScanAttack.py

@@ -2,14 +2,14 @@ import unittest.mock as mock
 
 import Test.ID2TAttackTest as Test
 
-sha_default = 'ef321877edfd828f6e6cd4abbffb5ade9cb66b3acd54ba9f3a5e2bfbeac9c964'
-sha_one_victim_linux = '4928d421caaec8f2c4e5c5bb835b5521b705478779cbc8f343b77143a5a66995'
-sha_victim_range_winxp_hosting = '4c6cb5cb4f838e75b41af4feb2fd9a6fe7e1b226a38b3e8759ce3d31e5a2535e'
-sha_multiple_victims_macos = '82d6d7e0471e6395c77df7b5bac141e48d50afe22841c7c53747bbfdd0de184d'
-sha_port_shuffle = '8ef501fa31135b8fea845a2be6a9605e0c3f9c4895b717f9206d485a669c2a73'
-sha_dest_mac_only = '0814dadb666e0056ef5b3a572a4971f333376b61e602acb84cb99c851845f016'
-sha_ip_src_shuffle = '6c0c9ccbedb631e4965ec36932276a1bd73b8a4aca5a5c46f01fd0a2800a064f'
-sha_smb2 = '8755a901295a90362d8041ecf1243a31fff582f5fe64555205625263c253476e'
+sha_default = 'bf2ef698c61429d4b0c3d9f7af95ec45576ef20b7e21a7904709b95dec1b525c'
+sha_one_victim_linux = 'e992ba20469fa630b09d5e450475bddae3db40bf7ed1aa32b33570999717d50c'
+sha_victim_range_winxp_hosting = '9510e4cd5442cd0912710ada8069beeedfebf375eefd733286aed63323c1cc50'
+sha_multiple_victims_macos = '87d0346bdb6b5a4b28a9247c26445bbf685f8cb6c77f82141739b107244625f9'
+sha_port_shuffle = 'cad9356ca92610371c9976edd08b8d16a5d8b9edf431c9cd9177f2bb757ff4d6'
+sha_dest_mac_only = 'a66832a461d9a2cf745a7232864c472c357e634b49f4f25bc9896a91c7967a17'
+sha_ip_src_shuffle = 'b4b6e9e9007085e2d1f9dd5d1199695dd6533b8b0ee9d77850c512a496e55581'
+sha_smb2 = '7d78e9c78bdc2ebac2055d42c5b2446794959053cc27eb8b177f6711d592ae82'
 
 # TODO: improve coverage
 

+ 3 - 3
code/Test/test_SQLiAttack.py

@@ -1,9 +1,9 @@
 import ID2TLib.TestLibrary as Lib
 import Test.ID2TAttackTest as Test
 
-sha_default = 'a130ecdaf5fd8c09ef8418d2dbe7bd68c54e922553eb9fa703df016115393a46'
-sha_ips_not_in_pcap = 'b3174ab4b7573c317c3e87b35e14eb38d99cf33613d76cfd77b0c30cbf1f1fa2'
-sha_multiple_params = 'aac4d2015e2af52dfefc0f76fcbfca664e3420d07af8b574803f56aae70222c5'
+sha_default = 'bb0a52766ee2fdf7c5f59b2c3f0322da463ecd2b91046da2559b4349cbbdc9b8'
+sha_ips_not_in_pcap = 'b0b0ac7f4b06a7fd53e5c7c29e0a64095a66ecf317864a48a0c0045132eee1ea'
+sha_multiple_params = '597dea34972c8bb03fb70d1d8579eab9a23428f55b0e2352f098b4a2b76a14c7'
 
 # TODO: improve coverage
 

+ 2 - 2
code/Test/test_SalityBotnet.py

@@ -3,8 +3,8 @@ import unittest.mock as mock
 import ID2TLib.TestLibrary as Lib
 import Test.ID2TAttackTest as Test
 
-sha_botnet_basic = '72c537fba918154dbe937694d8da87260bebb05c0ad20802051fa80107c1efbe'
-sha_botnet_most_used_ip_in_list = '72c537fba918154dbe937694d8da87260bebb05c0ad20802051fa80107c1efbe'
+sha_botnet_basic = 'fa16b25b8bad5e03c47e195c1c73f80d5667c4445d16aca44dbb390ade3c0d4f'
+sha_botnet_most_used_ip_in_list = 'fa16b25b8bad5e03c47e195c1c73f80d5667c4445d16aca44dbb390ade3c0d4f'
 
 
 class UnitTestSalityBotnet(Test.ID2TAttackTest):

+ 7 - 7
code/Test/test_internalQueries.py

@@ -23,7 +23,7 @@ class UnitTestInternalQueries(unittest.TestCase):
                           ("Unrecognized packets", 10, "PDUs"), ("% Recognized packets", 99.49949949949949, "%"),
                           ("% Unrecognized packets", 0.5005005005005005, "%"),
                           ("Last unknown PDU", '1970-01-01 01:07:39.604899'),
-                          ('Capture duration', '25.4294414520264', 'seconds'),
+                          ('Capture duration', '385.429443359375', 'seconds'),
                           ('Capture start', '\t1970-01-01 01:01:45.647675'),
                           ('Capture end', '\t1970-01-01 01:08:10.102034')])
 
@@ -31,7 +31,7 @@ class UnitTestInternalQueries(unittest.TestCase):
         self.assertEqual(controller.statistics.get_packet_count(), 1998)
 
     def test_get_capture_duration(self):
-        self.assertEqual(controller.statistics.get_capture_duration(), '25.4294414520264')
+        self.assertEqual(controller.statistics.get_capture_duration(), '385.429443359375')
 
     def test_get_pcap_timestamp_start(self):
         self.assertEqual(controller.statistics.get_pcap_timestamp_start(), '1970-01-01 01:01:45.647675')
@@ -42,14 +42,14 @@ class UnitTestInternalQueries(unittest.TestCase):
     # FIXME: This seems to be the only testcase where float values differ slightly between macOS and Linux
     def test_get_general_file_statistics(self):
         file_stats = controller.statistics.get_general_file_statistics()
-        self.assertEqual(file_stats[0], ('Avg. packet rate', 78.57034301757812, 'packets/sec'))
+        self.assertEqual(file_stats[0], ('Avg. packet rate', 5.183828353881836, 'packets/sec'))
         self.assertEqual(file_stats[1], ('Avg. packet size', 0.0, 'kbytes'))
         self.assertEqual(file_stats[2], ('Avg. packets sent', 90.0, 'packets'))
         self.assertEqual(file_stats[3][0], 'Avg. bandwidth in')
-        self.assertAlmostEqual(file_stats[3][1], 9.529013633728027, places=5)
+        self.assertAlmostEqual(file_stats[3][1], 0.6286947727203369, places=5)
         self.assertEqual(file_stats[3][2], 'kbit/s')
         self.assertEqual(file_stats[4][0], 'Avg. bandwidth out')
-        self.assertAlmostEqual(file_stats[4][1], 9.529013633728027, places=5)
+        self.assertAlmostEqual(file_stats[4][1], 0.6286947727203369, places=5)
 
     # INTERNAL QUERY TESTS
     def test_get_ip_address_count(self):
@@ -88,7 +88,7 @@ class UnitTestInternalQueries(unittest.TestCase):
         self.assertEqual(controller.statistics.get_pps_sent(ip_address='72.247.178.67'), 0)
 
     def test_get_pps_sent_2(self):
-        self.assertEqual(controller.statistics.get_pps_sent(ip_address='10.0.2.15'), 32)
+        self.assertEqual(controller.statistics.get_pps_sent(ip_address='10.0.2.15'), 2)
 
     def test_get_pps_sent_wrong_input(self):
         # wrong input parameter
@@ -99,7 +99,7 @@ class UnitTestInternalQueries(unittest.TestCase):
         self.assertEqual(controller.statistics.get_pps_received(ip_address='72.247.178.67'), 0)
 
     def test_get_pps_received_2(self):
-        self.assertEqual(controller.statistics.get_pps_received(ip_address='10.0.2.15'), 46)
+        self.assertEqual(controller.statistics.get_pps_received(ip_address='10.0.2.15'), 3)
 
     def test_get_ttl_distribution_1(self):
         self.assertEqual(controller.statistics.get_ttl_distribution(ip_address='72.247.178.67'), {64: 5})

+ 3 - 5
code_boost/src/cxx/statistics.cpp

@@ -642,10 +642,8 @@ float statistics::getCaptureDurationSeconds() const {
     timeval d;
     d.tv_sec = timestamp_lastPacket.seconds() - timestamp_firstPacket.seconds();
     d.tv_usec = timestamp_lastPacket.microseconds() - timestamp_firstPacket.microseconds();
-    char tmbuf[64], buf[64];
-    auto nowtm = localtime(&(d.tv_sec));
-    strftime(tmbuf, sizeof(tmbuf), "%S", nowtm);
-    snprintf(buf, sizeof(buf), "%s.%06u", tmbuf, (uint) d.tv_usec);
+    char buf[64];
+    snprintf(buf, sizeof(buf), "%u.%06u", static_cast<uint>(d.tv_sec), static_cast<uint>(d.tv_usec));
     return std::stof(std::string(buf));
 }
 
@@ -663,7 +661,7 @@ std::string statistics::getFormattedTimestamp(time_t seconds, suseconds_t micros
     char tmbuf[64], buf[64];
     auto nowtm = localtime(&(tv.tv_sec));
     strftime(tmbuf, sizeof(tmbuf), "%Y-%m-%d %H:%M:%S", nowtm);
-    snprintf(buf, sizeof(buf), "%s.%06u", tmbuf, (uint) tv.tv_usec);
+    snprintf(buf, sizeof(buf), "%s.%06u", tmbuf, static_cast<uint>(tv.tv_usec));
     return std::string(buf);
 }
 

+ 1 - 1
code_boost/src/cxx/statistics_db.h

@@ -22,7 +22,7 @@ public:
     /*
      * Database version: Increment number on every change in the C++ code!
      */
-    static const int DB_VERSION = 8;
+    static const int DB_VERSION = 9;
 
     /*
      * Methods for writing values into database