소스 검색

US28 + US29

christof 7 년 전
부모
커밋
1a14efecc4
2개의 변경된 파일15개의 추가작업 그리고 7개의 파일을 삭제
  1. 4 4
      code/Attack/MembersMgmtCommAttack.py
  2. 11 3
      code/ID2TLib/PaddingGenerator.py

+ 4 - 4
code/Attack/MembersMgmtCommAttack.py

@@ -133,7 +133,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
         self.add_param_value(Param.IP_REUSE_EXTERNAL, 0.5)
 
         # add default additional padding
-        self.add_param_value(Param.PACKET_PADDING, 0)
+        self.add_param_value(Param.PACKET_PADDING, 20)
 
         
     def generate_attack_pcap(self):
@@ -188,7 +188,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
             # create suitable IP/UDP packet and add to packets list
             packet = pkt_gen.generate_mmcom_packet(ip_src=ip_src, ip_dst=ip_dst, ttl=ttl, mac_src=mac_src, mac_dst=mac_dst, 
                 port_src=port_src, port_dst=port_dst, message_type=msg.type, neighborlist_entries=nl_size)
-            PaddingGenerator.add_padding(packet, padding)
+            PaddingGenerator.add_padding(packet, padding,True, True)
 
             packet.time = pcap_timestamp
             packets.append(packet)
@@ -199,7 +199,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
                 self.attack_start_utime = packets[0].time
             elif total_pkts % BUFFER_SIZE == 0: # every 1000 packets write them to the PCAP file (append)
                 packets = list(packets)
-                PaddingGenerator.equal_length(packets)
+                PaddingGenerator.equal_length(packets, padding = padding)
                 last_packet = packets[-1]
                 path_attack_pcap = self.write_attack_pcap(packets, True, path_attack_pcap)
                 packets = deque(maxlen=BUFFER_SIZE)
@@ -207,7 +207,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
         # if there are unwritten packets remaining, write them to the PCAP file
         if len(packets) > 0:
             packets = list(packets)
-            PaddingGenerator.equal_length(packets)
+            PaddingGenerator.equal_length(packets, padding = padding)
             path_attack_pcap = self.write_attack_pcap(packets, True, path_attack_pcap)
             last_packet = packets[-1]
 

+ 11 - 3
code/ID2TLib/PaddingGenerator.py

@@ -1,24 +1,31 @@
 from scapy.packet import Raw
 
 import ID2TLib.PayloadGenerator as PayloadGenerator
+import numpy.random as random
 
 
-def add_padding(packet, bytes_padding = 0, user_padding=True):
+def add_padding(packet, bytes_padding = 0, user_padding=True, rnd = False):
     '''
     Adds padding to a packet with the given amount of bytes, but a maximum of 100 bytes.
     :param packet: the packet that will be extended with the additional payload
     :param bytes_padding: the amount of bytes that will be appended to the packet
+    :param user_padding: true, if the function add_padding is called from another class and the user
+    sets the padding manually
+    :param rnd: adds a random padding betwing 0 and bytes_adding, if true
     :return: the initial packet, extended with the wanted amount of bytes of padding
     '''
 
     if(user_padding and bytes_padding > 100):
         bytes_padding = 100
 
+    if (rnd is True):
+        r = int(round(bytes_padding / 4))                  #sets bytes_padding to any number between 0 and bytes_padding
+        bytes_padding = random.random_integers(0, r) * 4   #, that's dividable by 4
     payload = PayloadGenerator.generate_payload(bytes_padding)
     packet[Raw].load += Raw(load=payload).load
     return packet
 
-def equal_length(list_of_packets, length = 0):
+def equal_length(list_of_packets, length = 0, padding = 0):
     '''
     Equals the length of a given set of packets on the given length. If the given length is smaller than the largest
     packet, all the other packets are extended to the largest packet's length.
@@ -36,6 +43,7 @@ def equal_length(list_of_packets, length = 0):
     for packet in list_of_packets:
         bytes_padding = largest_packet - len(packet)
         if(bytes_padding > 0):
-            add_padding(packet, bytes_padding, False)
+            add_padding(packet, bytes_padding, False, False)
+            add_padding(packet, padding, False, True)
 
     return list_of_packets