diff --git a/code/Attack/PortscanAttack.py b/code/Attack/PortscanAttack.py index 0b7b283b..f067a75a 100755 --- a/code/Attack/PortscanAttack.py +++ b/code/Attack/PortscanAttack.py @@ -22,6 +22,7 @@ class PortscanAttack(BaseAttack.BaseAttack): PORT_DEST_ORDER_DESC = 'port.dst.order-desc' IP_SOURCE_RANDOMIZE = 'ip.src.shuffle' PORT_SOURCE_RANDOMIZE = 'port.src.shuffle' + SCAN_DURATION = "scan.duration" def __init__(self): """ @@ -45,7 +46,8 @@ def __init__(self): Parameter(self.PORT_DEST_ORDER_DESC, Boolean()), Parameter(self.IP_SOURCE_RANDOMIZE, Boolean()), Parameter(self.PACKETS_PER_SECOND, Float()), - Parameter(self.PORT_SOURCE_RANDOMIZE, Boolean()) + Parameter(self.PORT_SOURCE_RANDOMIZE, Boolean()), + Parameter(self.SCAN_DURATION, Float()), ]) def init_param(self, param: str) -> bool: @@ -95,6 +97,8 @@ def init_param(self, param: str) -> bool: value = rnd.randint(0, self.statistics.get_packet_count()) if value is None: return False + if value == self.SCAN_DURATION: + value = 0.0 return self.add_param_value(param, value) def generate_attack_packets(self): @@ -246,6 +250,12 @@ def generate_attack_packets(self): self.timestamp_controller.set_timestamp(timestamp_next_pkt) timestamp_next_pkt = self.timestamp_controller.next_timestamp() + duration = self.get_param_value(self.SCAN_DURATION) + last_timestamp = self.timestamp_controller.first_timestamp + duration + + if duration > 0 and timestamp_next_pkt > last_timestamp: + break + def generate_attack_pcap(self): """ Creates a pcap containing the attack packets.