Quellcode durchsuchen

Merge branch 'development' into performance_eval

Patrick Jattke vor 8 Jahren
Ursprung
Commit
fb29f34825
4 geänderte Dateien mit 24 neuen und 21 gelöschten Zeilen
  1. 6 3
      code/Attack/DDoSAttack.py
  2. 8 7
      code/Attack/PortscanAttack.py
  3. 8 8
      code/CLI.py
  4. 2 3
      code/ID2TLib/AttackController.py

+ 6 - 3
code/Attack/DDoSAttack.py

@@ -51,7 +51,10 @@ class DDoSAttack(BaseAttack.BaseAttack):
         # victim configuration
         random_ip_address = self.statistics.get_random_ip_address()
         self.add_param_value(Param.IP_DESTINATION, random_ip_address)
-        self.add_param_value(Param.MAC_DESTINATION, self.statistics.get_mac_address(random_ip_address))
+        destination_mac = self.statistics.get_mac_address(random_ip_address)
+        if isinstance(destination_mac, list) and len(destination_mac) == 0:
+            destination_mac = self.generate_random_mac_address()
+        self.add_param_value(Param.MAC_DESTINATION, destination_mac)
         port_destination = self.statistics.process_db_query(
             "SELECT portNumber FROM ip_ports WHERE portDirection='in' ORDER BY RANDOM() LIMIT 1;")
         if port_destination is None:
@@ -152,7 +155,7 @@ class DDoSAttack(BaseAttack.BaseAttack):
         gd = gamma.rvs(alpha, loc=loc, scale=beta, size=len(ip_source_list))
 
         path_attack_pcap = None
-        for pkt_num in range(self.get_param_value(Param.PACKETS_LIMIT)):
+        for pkt_num in range(self.get_param_value(Param.PACKETS_LIMIT) + 1):
             # Select one IP address and its corresponding MAC address
             (ip_source, mac_source) = get_nth_random_element(ip_source_list, mac_source_list)
 
@@ -184,4 +187,4 @@ class DDoSAttack(BaseAttack.BaseAttack):
         self.attack_end_utime = last_packet.time
 
         # return packets sorted by packet time_sec_start
-        return path_attack_pcap
+        return pkt_num, path_attack_pcap

+ 8 - 7
code/Attack/PortscanAttack.py

@@ -53,7 +53,10 @@ class PortscanAttack(BaseAttack.BaseAttack):
 
         random_ip_address = self.statistics.get_random_ip_address()
         self.add_param_value(Param.IP_DESTINATION, random_ip_address)
-        self.add_param_value(Param.MAC_DESTINATION, self.statistics.get_mac_address(random_ip_address))
+        destination_mac = self.statistics.get_mac_address(random_ip_address)
+        if isinstance(destination_mac, list) and len(destination_mac) == 0:
+            destination_mac = self.generate_random_mac_address()
+        self.add_param_value(Param.MAC_DESTINATION, destination_mac)
 
         self.add_param_value(Param.PORT_DESTINATION, '1-1023,1720,1900,8080')
         self.add_param_value(Param.PORT_OPEN, '8080,9232,9233')
@@ -158,10 +161,8 @@ class PortscanAttack(BaseAttack.BaseAttack):
         # store end time of attack
         self.attack_end_utime = packets[-1].time
 
-        print("Packets created: " + str(len(packets)))
+        # write attack packets to pcap
+        pcap_path = self.write_attack_pcap(sorted(packets, key=lambda pkt: pkt.time))
 
-        # write packets to disk
-        path_attack_pcap = self.write_attack_pcap(sorted(packets, key=lambda pkt: pkt.time))
-
-        # return destination path
-        return path_attack_pcap
+        # return packets sorted by packet time_sec_start
+        return len(packets), pcap_path

+ 8 - 8
code/CLI.py

@@ -106,23 +106,23 @@ def main(args):
 
 # Uncomment to enable calling by terminal
 # if __name__ == '__main__':
-#     main(sys.argv[1:])
+#    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 = ['/root/datasets/201506021400_1G.pcap',
+    #             '/root/datasets/201506021400_2G.pcap',
+    #             '/root/datasets/201506021400_5G.pcap']
 
-    FILES = ['/root/datasets/201506021400_2G.pcap']
+    FILES = ['/mnt/hgfs/datasets/201506021400_2G.pcap']
 
-#    FILES = ['/root/test_me_short.pcap']
+    #    FILES = ['/mnt/hgfs/datasets/95M.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']
-    ATTACK_DD = ['-a', 'DDoSAttack', 'attackers.count=10', 'packets.limit=500000']
+    ATTACK_DD = ['-a', 'DDoSAttack', 'attackers.count=10', 'packets.limit=1000']
 
     STATS_RECALC = ['-r']
     STATS_PRINT = ['-s']
@@ -132,5 +132,5 @@ if __name__ == '__main__':
     QUERY_DB = ['-q', 'ipAddress(pktsSent > 1000, kbytesSent >= 20)']
 
     for f in FILES:
-        main(INPUT + [f] + ATTACK_PS2)  # Statistics Calculation
+        main(INPUT + [f] + ATTACK_PS2 + ATTACK_DD)  # Statistics Calculation
         #main(INPUT + ATTACK_DD)  # Attack Packet Generation -> insert exit() | Merging

+ 2 - 3
code/ID2TLib/AttackController.py

@@ -85,16 +85,15 @@ class AttackController:
         # Write attack into pcap file
         print("Generating attack packets...", end=" ")
         sys.stdout.flush()  # force python to print text immediately
-
         # time_s = time.time()
-        temp_attack_pcap_path = self.current_attack.generate_attack_pcap()
+        total_packets, temp_attack_pcap_path = self.current_attack.generate_attack_pcap()
         # time_e = time.time()
         # f = open("/root/perfresults/runtime_packetgen.txt", "a")
         # f.write(str(time_e - time_s) + "\n")
         # f.close()
         # print("Finished............")
         # exit(0)
-        print("done.")
+        print("done. (total: " + str(total_packets) + " pkts.)")
 
         # Merge attack with existing pcap
         pcap_dest_path = self.pcap_file.merge_attack(temp_attack_pcap_path)