Browse Source

fix packet rate

aidmar.wainakh 6 years ago
parent
commit
d59583a0c5
1 changed files with 6 additions and 6 deletions
  1. 6 6
      code/Attack/PortscanAttack.py

+ 6 - 6
code/Attack/PortscanAttack.py

@@ -12,7 +12,7 @@ from Attack.AttackParameters import ParameterTypes
 logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
 # noinspection PyPep8
 from scapy.layers.inet import IP, Ether, TCP
-
+import numpy as np
 
 class PortscanAttack(BaseAttack.BaseAttack):
     # Aidmar - Values derived empirically from Nmap experiments.
@@ -117,10 +117,10 @@ class PortscanAttack(BaseAttack.BaseAttack):
 
             :return: Timestamp to be used for the next packet.
             """
-            # Aidmar - why to use 0.1/pps?
-            #return timestamp + uniform(0.1 / pps, maxdelay)
             # Aidmar
-            return timestamp + uniform(1 / pps, maxdelay)
+            # To imitate the bursty behavior of traffic
+            randomdelay = Lea.fromValFreqsDict({1 / pps: 70, 2 / pps: 20, 5 / pps: 7, 10 / pps: 3})
+            return timestamp + uniform(1/pps ,  randomdelay.random())
 
         # Aidmar
         def getIntervalPPS(complement_interval_pps, timestamp):
@@ -232,7 +232,7 @@ class PortscanAttack(BaseAttack.BaseAttack):
             destination_win_value = self.statistics.process_db_query("most_used(winSize)")
 
         # Aidmar
-        minDelay,maxDelay = self.get_reply_delay(ip_destination)
+        minDelay,maxDelay, SDDelay = self.get_reply_delay(ip_destination)
 
         for dport in dest_ports:
             # Parameters changing each iteration
@@ -287,7 +287,7 @@ class PortscanAttack(BaseAttack.BaseAttack):
 
             # Aidmar
             pps = max(getIntervalPPS(complement_interval_pps, timestamp_next_pkt),self.minDefaultPPS)
-            timestamp_next_pkt = update_timestamp(timestamp_next_pkt, pps, maxDelay)
+            timestamp_next_pkt = update_timestamp(timestamp_next_pkt, pps, minDelay)
 
         # store end time of attack
         self.attack_end_utime = packets[-1].time