Procházet zdrojové kódy

Fix time fields in message mapping

dustin.born před 7 roky
rodič
revize
72c2a84ca6

+ 2 - 1
code/Attack/MembersMgmtCommAttack.py

@@ -53,6 +53,7 @@ class Message():
         self.dst = dst
         self.type = type_
         self.time = time
+        self.csv_time = time
         self.refer_msg_id = refer_msg_id
         self.line_no = line_no
 
@@ -194,7 +195,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
         path_attack_pcap = None
         overThousand = False
 
-        msg_packet_mapping = MessageMapping(messages)
+        msg_packet_mapping = MessageMapping(messages, self.statistics.get_pcap_timestamp_start())
 
         # create packets to write to PCAP file
         for msg in messages:

+ 9 - 5
code/ID2TLib/Botnet/MessageMapping.py

@@ -13,14 +13,16 @@ class MessageMapping:
 
     ATTR_PACKET_TIME = "packet_time"
 
-    def __init__(self, messages):
+    def __init__(self, messages, pcap_start_timestamp_str):
         self.messages = messages
         self.id_to_packet = {}
+        ts_date_format = "%Y-%m-%d %H:%M:%S.%f"
+        self.pcap_start_dt = datetime.datetime.strptime(pcap_start_timestamp_str, ts_date_format)
 
     def map_message(self, message, packet):
         self.id_to_packet[message.msg_id] = packet
 
-    def to_xml(self):
+    def to_xml(self, ):
         doc = Document()
 
         mappings = doc.createElement(self.TAG_MAPPING_GROUP)
@@ -34,11 +36,13 @@ class MessageMapping:
             mapping.setAttribute("Src", str(message.src["ID"]))
             mapping.setAttribute("Dst", str(message.dst["ID"]))
             mapping.setAttribute("Type", str(message.type.value))
+            mapping.setAttribute("CSV_XML_Time", str(message.csv_time))
 
             dt = datetime.datetime.fromtimestamp(message.time)
-            mapping.setAttribute("Time", str(message.time))
-            mapping.setAttribute("Time-Datetime", dt.strftime("%Y-%m-%d %H:%M:%S.") + str(dt.microsecond))
-            mapping.setAttribute("Time-Timeonly", dt.strftime("%H:%M:%S.") + str(dt.microsecond))
+            dt_relative = dt - self.pcap_start_dt
+            mapping.setAttribute("PCAP_Time-Timestamp", str(message.time))
+            mapping.setAttribute("PCAP_Time-Datetime", dt.strftime("%Y-%m-%d %H:%M:%S.") + str(dt.microsecond))
+            mapping.setAttribute("PCAP_Time-Relative", "%d.%s" % (dt_relative.total_seconds(), str(dt_relative.microseconds).rjust(6, "0")))
 
             packet = self.id_to_packet.get(message.msg_id)
             mapping.setAttribute(self.ATTR_HAS_PACKET, "true" if packet is not None else "false")