Browse Source

- Improves the temporary attack pcap merging

Patrick Jattke 7 years ago
parent
commit
078fd54731
2 changed files with 7 additions and 38 deletions
  1. 0 29
      code/CLI.py
  2. 7 9
      code/ID2TLib/Controller.py

+ 0 - 29
code/CLI.py

@@ -92,7 +92,6 @@ class CLI(object):
 
         self.process_arguments()
 
-
 def main(args):
     """
     Creates a new CLI object and invokes the arguments parsing.
@@ -103,34 +102,6 @@ def main(args):
     # Check arguments
     cli.parse_arguments(args)
 
-
 # Uncomment to enable calling by terminal
 if __name__ == '__main__':
     main(sys.argv[1:])
-
-# if __name__ == '__main__':
-#     INPUT = ['-i']
-#
-#     #    FILES = ['/root/datasets/201506021400_1G.pcap',
-#     #             '/root/datasets/201506021400_2G.pcap',
-#     #             '/root/datasets/201506021400_5G.pcap']
-#
-#     # FILES = ['/mnt/hgfs/datasets/201506021400_2G.pcap']
-#
-#     FILES = ['/home/pjattke/temp/test_me_short.pcap']
-#
-#     ATTACK_PS = ['-a', 'PortscanAttack', 'ip.src=10.2.2.4', 'mac.dst=05:AB:47:B5:19:11',
-#                  'inject.at-timestamp=1449038705.316721', 'attack.note=Portscan2']
-#     ATTACK_PS2 = ['-a', 'PortscanAttack', 'port.dst=1-1024', 'ip.src=3.3.3.3']
-#     ATTACK_DD = ['-a', 'DDoSAttack', 'ip.dst=9.9.9.9', 'attackers.count=10', 'packets.limit=100']
-#
-#     STATS_RECALC = ['-r']
-#     STATS_PRINT = ['-s']
-#     STATS_PLOT = ['-p']
-#
-#     QUERY_MODE_LOOP = ['-q']
-#     QUERY_DB = ['-q', 'ipAddress(pktsSent > 1000, kbytesSent >= 20)']
-#
-#     for f in FILES:
-#         main(INPUT + [f] + ATTACK_PS2 + ATTACK_DD)  # Statistics Calculation
-#         #main(INPUT + ATTACK_DD)  # Attack Packet Generation -> insert exit() | Merging

+ 7 - 9
code/ID2TLib/Controller.py

@@ -55,26 +55,24 @@ class Controller:
         if len(self.written_pcaps) > 1:
             print("\nMerging temporary attack pcaps into single pcap file...", end=" ")
             sys.stdout.flush()  # force python to print text immediately
-            attack_pcap_file = PcapFile(self.written_pcaps[0])
-            for attack in self.written_pcaps[1:]:
-                all_attacks_pcap = attack_pcap_file.merge_attack(attack)
-                os.remove(attack)  # remove merged pcap
-                # Create new PcapFile object for next iteration
-                attack_pcap_file = PcapFile(all_attacks_pcap)
+            for i in range(0, len(self.written_pcaps) - 1):
+                attacks_pcap = PcapFile(self.written_pcaps[i])
+                attacks_pcap_path = attacks_pcap.merge_attack(self.written_pcaps[i + 1])
+                os.remove(self.written_pcaps[i + 1])  # remove merged pcap
             print("done.")
         else:
-            all_attacks_pcap = self.written_pcaps[0]
+            attacks_pcap_path = self.written_pcaps[0]
 
         # merge single attack pcap with all attacks into base pcap
         print("Merging base pcap with single attack pcap...", end=" ")
         sys.stdout.flush()  # force python to print text immediately
-        self.pcap_dest_path = self.pcap_file.merge_attack(all_attacks_pcap)
+        self.pcap_dest_path = self.pcap_file.merge_attack(attacks_pcap_path)
         print("done.")
 
         # delete intermediate PCAP files
         print('Deleting intermediate attack pcap...', end="")
         sys.stdout.flush()  # force python to print text immediately
-        os.remove(all_attacks_pcap)
+        os.remove(attacks_pcap_path)
         print("done.")
 
         # write label file with attacks