Просмотр исходного кода

Adapted code for use on evaluation machine.

root 8 лет назад
Родитель
Сommit
e2039714ed

+ 8 - 3
code/Attack/PortscanAttack.py

@@ -156,7 +156,12 @@ class PortscanAttack(BaseAttack.BaseAttack):
                 # else: destination port is NOT OPEN -> no reply is sent by target
 
         # store end time of attack
-        self.attack_end_utime = reply.time
+        self.attack_end_utime = packets[-1].time
 
-        # return packets sorted by packet time_sec_start
-        return sorted(packets, key=lambda pkt: pkt.time)
+        print("Packets created: " + str(len(packets)))
+
+        # 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

+ 8 - 8
code/CLI.py

@@ -111,18 +111,18 @@ def main(args):
 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.pcap']
+    FILES = ['/root/datasets/201506021400_2G.pcap']
 
-    # FILES = ['/mnt/hgfs/datasets/95M.pcap']
+#    FILES = ['/root/test_me_short.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', 'ip.dst=193.133.122.23', 'ip.src=192.124.34.12', 'inject.after-pkt=34']
-    ATTACK_DD = ['-a', 'DDoSAttack', 'attackers.count=10', 'packets.limit=10000']
+    ATTACK_PS2 = ['-a', 'PortscanAttack', 'port.dst=1-1024']
+    ATTACK_DD = ['-a', 'DDoSAttack', 'attackers.count=10', 'packets.limit=500000']
 
     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] + STATS_RECALC)  # Statistics Calculation
+        main(INPUT + [f] + ATTACK_PS2)  # Statistics Calculation
         #main(INPUT + ATTACK_DD)  # Attack Packet Generation -> insert exit() | Merging

+ 7 - 6
code/ID2TLib/AttackController.py

@@ -86,13 +86,14 @@ class AttackController:
         print("Generating attack packets...", end=" ")
         sys.stdout.flush()  # force python to print text immediately
 
-        time_s = time.time()
+        # time_s = time.time()
         temp_attack_pcap_path = self.current_attack.generate_attack_pcap()
-        time_e = time.time()
-        f = open("/root/perfresults/runtime_packetgen.txt", "a")
-        f.write(time_e - time_s)
-        f.close()
-
+        # 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.")
 
         # Merge attack with existing pcap

+ 2 - 2
code/ID2TLib/PcapFile.py

@@ -27,12 +27,12 @@ class PcapFile(object):
 
         time_s = time.time()
         pcap = pr.pcap_processor(self.pcap_file_path)
+        file_out_path = pcap.merge_pcaps(attack_pcap_path)
         time_e = time.time()
         f = open("/root/perfresults/runtime_merging.txt", "a")
-        f.write(time_e - time_s)
+        f.write(str(time_e - time_s)+"\n")
         f.close()
 
-        file_out_path = pcap.merge_pcaps(attack_pcap_path)
         print("done.")
 
         return file_out_path

+ 2 - 2
code/ID2TLib/Statistics.py

@@ -1,6 +1,6 @@
 import os
 import time
-import libpcapreader as pr
+import ID2TLib.libpcapreader as pr
 import matplotlib.pyplot as plt
 from ID2TLib.PcapFile import PcapFile
 from ID2TLib.StatsDatabase import StatsDatabase
@@ -52,7 +52,7 @@ class Statistics:
             self.pcap_proc.collect_statistics()
             time_e = time.time()
             f = open("/root/perfresults/runtime_stats.txt", "a")
-            f.write(time_e - time_s)
+            f.write(str(time_e - time_s) + "\n")
             f.close()
 
             self.pcap_proc.write_to_database(self.path_db)

BIN
code/ID2TLib/libpcapreader


+ 2 - 1
code/profile-process.py

@@ -5,6 +5,7 @@ import subprocess
 import time
 import psutil
 import matplotlib
+matplotlib.use('Agg')
 import matplotlib.pyplot as plt
 from matplotlib.backends.backend_pdf import PdfPages
 
@@ -34,7 +35,7 @@ def log_performance():
     stats_io_r_b = []
     stats_io_w_b = []
 
-    proc = subprocess.Popen("/home/pjattke/Thesis/public/code/CLI.py")
+    proc = subprocess.Popen("./CLI.py")
     p = psutil.Process(proc.pid)
     start_time = time.time()
     while proc is None or proc.poll() is None:

+ 7 - 0
id2t

@@ -0,0 +1,7 @@
+#!/bin/sh
+# Find the executable
+ID2T_DIR=$(readlink -f $0)
+SCRIPT_PATH=${ID2T_DIR%/*}
+cd $SCRIPT_PATH
+# Execute ID2T
+exec ./code/CLI.py "$@"