Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter for port scan duration #116

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion code/Attack/PortscanAttack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down