소스 검색

added --inject_empty Parameter

Marcel 6 년 전
부모
커밋
8d0a2dfc09
2개의 변경된 파일23개의 추가작업 그리고 9개의 파일을 삭제
  1. 3 1
      code/CLI.py
  2. 20 8
      code/Core/Controller.py

+ 3 - 1
code/CLI.py

@@ -71,6 +71,8 @@ class CLI(object):
         parser.add_argument('-T', '--time', help='measures packet generation time', action='store_true', default=False)
         parser.add_argument('-T', '--time', help='measures packet generation time', action='store_true', default=False)
         parser.add_argument('-V', '--non-verbose', help='reduces terminal clutter', action='store_true', default=False)
         parser.add_argument('-V', '--non-verbose', help='reduces terminal clutter', action='store_true', default=False)
         parser.add_argument('-o', '--output', metavar="PCAP_FILE", help='path to the output pcap file')
         parser.add_argument('-o', '--output', metavar="PCAP_FILE", help='path to the output pcap file')
+        parser.add_argument('-ie', '--inject_empty', action='store_true',
+                                       help='injects ATTACK into an EMPTY PCAP file, using the statistics of the input PCAP.')
 
 
         # Attack arguments
         # Attack arguments
         parser.add_argument('-a', '--attack', metavar="ATTACK", action='append',
         parser.add_argument('-a', '--attack', metavar="ATTACK", action='append',
@@ -161,7 +163,7 @@ class CLI(object):
         # Process attack(s) with given attack params
         # Process attack(s) with given attack params
         if self.args.attack is not None:
         if self.args.attack is not None:
             # If attack is present, load attack with params
             # If attack is present, load attack with params
-            controller.process_attacks(self.args.attack, self.args.rngSeed, self.args.time)
+            controller.process_attacks(self.args.attack, self.args.rngSeed, self.args.time, self.args.inject_empty)
 
 
         # Parameter -q without arguments was given -> go into query loop
         # Parameter -q without arguments was given -> go into query loop
         if self.args.query == [None]:
         if self.args.query == [None]:

+ 20 - 8
code/Core/Controller.py

@@ -1,6 +1,8 @@
 import os
 import os
 import readline
 import readline
 import sys
 import sys
+import shutil
+import time
 
 
 import pyparsing as pp
 import pyparsing as pp
 import Core.AttackController as atkCtrl
 import Core.AttackController as atkCtrl
@@ -61,17 +63,18 @@ class Controller:
         self.statistics.load_pcap_statistics(flag_write_file, flag_recalculate_stats, flag_print_statistics,
         self.statistics.load_pcap_statistics(flag_write_file, flag_recalculate_stats, flag_print_statistics,
                                              self.non_verbose)
                                              self.non_verbose)
 
 
-    def process_attacks(self, attacks_config: list, seeds=None, time=False):
+    def process_attacks(self, attacks_config: list, seeds=None, time_value: bool=False, inject_empty: bool=False):
         """
         """
         Creates the attack based on the attack name and the attack parameters given in the attacks_config. The
         Creates the attack based on the attack name and the attack parameters given in the attacks_config. The
         attacks_config is a list of attacks.
         attacks_config is a list of attacks.
         e.g. [['PortscanAttack', 'ip.src="192.168.178.2",'dst.port=80'],['PortscanAttack', 'ip.src="10.10.10.2"]].
         e.g. [['PortscanAttack', 'ip.src="192.168.178.2",'dst.port=80'],['PortscanAttack', 'ip.src="10.10.10.2"]].
         Merges the individual temporary attack pcaps into one single pcap and merges this single pcap with the
         Merges the individual temporary attack pcaps into one single pcap and merges this single pcap with the
-        input dataset.
+        input dataset if desired.
 
 
         :param attacks_config: A list of attacks with their attack parameters.
         :param attacks_config: A list of attacks with their attack parameters.
         :param seeds: A list of random seeds for the given attacks.
         :param seeds: A list of random seeds for the given attacks.
-        :param time: Measure time for packet generation.
+        :param time_value: Measure time for packet generation.
+        :param inject_empty: if flag is set, Attack PCAPs will not be merged with the base PCAP, ie. Attacks are injected into an empty PCAP
         """
         """
 
 
         # load attacks sequentially
         # load attacks sequentially
@@ -82,7 +85,7 @@ class Controller:
             else:
             else:
                 rng_seed = int.from_bytes(os.urandom(16), sys.byteorder)
                 rng_seed = int.from_bytes(os.urandom(16), sys.byteorder)
             self.attack_controller.set_seed(seed=rng_seed)
             self.attack_controller.set_seed(seed=rng_seed)
-            temp_attack_pcap, duration = self.attack_controller.process_attack(attack[0], attack[1:], time)
+            temp_attack_pcap, duration = self.attack_controller.process_attack(attack[0], attack[1:], time_value)
             self.durations.append(duration)
             self.durations.append(duration)
             self.added_packets += self.attack_controller.total_packets
             self.added_packets += self.attack_controller.total_packets
             if not self.non_verbose:
             if not self.non_verbose:
@@ -105,10 +108,19 @@ class Controller:
         else:
         else:
             attacks_pcap_path = 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(attacks_pcap_path)
+        if inject_empty:
+            # copy the attack pcap to the directory of the base PCAP instead of merging them
+            print("Copying single attack pcap to location of base pcap...", end=" ")
+            sys.stdout.flush()  # force python to print text immediately
+
+            timestamp = '_' + time.strftime("%Y%m%d") + '-' + time.strftime("%X").replace(':', '')
+            self.pcap_dest_path = self.pcap_src_path.replace(".pcap", timestamp + '.pcap')
+            shutil.copy(attacks_pcap_path, self.pcap_dest_path)
+        else:
+            # 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(attacks_pcap_path)
 
 
         if self.pcap_out_path:
         if self.pcap_out_path:
             if not self.pcap_out_path.endswith(".pcap"):
             if not self.pcap_out_path.endswith(".pcap"):