소스 검색

avoided context problem and stored dest path in a global variable instead. f... this in particular.

Denis Waßmann 6 년 전
부모
커밋
1bcee8ecb8
3개의 변경된 파일15개의 추가작업 그리고 8개의 파일을 삭제
  1. 7 8
      code/Attack/MembersMgmtCommAttack.py
  2. 4 0
      code/Core/Controller.py
  3. 4 0
      code/ID2TLib/Utility.py

+ 7 - 8
code/Attack/MembersMgmtCommAttack.py

@@ -12,6 +12,7 @@ from Attack.AttackParameters import ParameterTypes
 # from ID2TLib import PcapFile
 # from ID2TLib.PcapFile import PcapFile
 from ID2TLib.Ports import PortSelectors
+import ID2TLib.Utility
 
 class MessageType(Enum):
     """
@@ -158,15 +159,14 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
         self.add_param_value(Param.BOTNET_DST_PORT_CALCULATION, True)
 
 
-    def generate_attack_pcap(self, context):
+    def generate_attack_pcap(self):
         """
         Injects the packets of this attack into a PCAP and stores it as a temporary file.
-        :param context: the context of the attack, containing e.g. files that are to be created
         :return: a tuple of the number packets injected and the path to the temporary attack PCAP
         """
 
         # create the final messages that have to be sent, including all bot configurations
-        messages = self._create_messages(context)
+        messages = self._create_messages()
 
         if messages == []:
             return 0, []
@@ -252,7 +252,8 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
                 last_packet = packets[-1]
 
         # write the mapping to a file
-        msg_packet_mapping.write_to(context.allocate_file("_mapping.xml"))
+        dest_without_ext = os.path.splitext(ID2TLib.Utility.PCAP_DEST_PATH)[0]
+        msg_packet_mapping.write_to(dest_without_ext + "_mapping.xml")
 
         # Store timestamp of last packet
         self.attack_end_utime = last_packet.time
@@ -264,10 +265,9 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
     def generate_attack_packets(self):
         pass
 
-    def _create_messages(self, context):
+    def _create_messages(self):
         """
         Creates the messages that are to be injected into the PCAP.
-        :param context: the context of the attack, containing e.g. files that are to be created
         :return: the final messages as a list
         """
 
@@ -459,14 +459,13 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
             :return: the new filepath to the XML file
             """
 
-            pcap_dir = context.get_output_dir()
+            pcap_dir = os.path.dirname(ID2TLib.Utility.PCAP_DEST_PATH)
             xml_name = os.path.basename(filepath_xml)
             if pcap_dir.endswith("/"):
                 new_xml_path = pcap_dir + xml_name
             else:
                 new_xml_path = pcap_dir + "/" + xml_name
             os.rename(filepath_xml, new_xml_path)
-            context.add_other_created_file(new_xml_path)
             return new_xml_path
 
         # parse input CSV or XML

+ 4 - 0
code/Core/Controller.py

@@ -7,6 +7,7 @@ import Core.AttackController as atkCtrl
 import Core.LabelManager as LabelManager
 import Core.Statistics as Statistics
 import ID2TLib.PcapFile as PcapFile
+from ID2TLib import Utility
 
 
 class Controller:
@@ -24,6 +25,9 @@ class Controller:
         self.seed = None
         self.durations = []
 
+        # ugly hack, but the best we have
+        Utility.PCAP_DEST_PATH = pcap_file_path.strip()
+
         # Initialize class instances
         print("Input file: %s" % self.pcap_src_path)
         self.pcap_file = PcapFile.PcapFile(self.pcap_src_path)

+ 4 - 0
code/ID2TLib/Utility.py

@@ -16,6 +16,10 @@ ROOT_DIR = CODE_DIR + "../"
 RESOURCE_DIR = ROOT_DIR + "resources/"
 TEST_DIR = RESOURCE_DIR + "test/"
 
+# this has to be initialized to None and will be set later
+# if your code needs this value and it's None something went really wrong
+PCAP_DEST_PATH = None
+
 platforms = {"win7", "win10", "winxp", "win8.1", "macos", "linux", "win8", "winvista", "winnt", "win2000"}
 platform_probability = {"win7": 48.43, "win10": 27.99, "winxp": 6.07, "win8.1": 6.07, "macos": 5.94, "linux": 3.38,
                         "win8": 1.35, "winvista": 0.46, "winnt": 0.31}