Skip to content

Commit

Permalink
Merge pull request #44 from angeloc/connected_delay
Browse files Browse the repository at this point in the history
research/fragattack: implement --pre-test-delay
  • Loading branch information
vanhoefm authored Mar 31, 2022
2 parents 95a0122 + 0375781 commit baa1c93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion research/fragattack.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def prepare_tests(opt):
else: return None

# If requested, override delay and inc_pn parameters in the test.
test.set_general_options(opt.delay, opt.inc_pn)
test.set_general_options(opt.delay, opt.inc_pn, opt.pre_test_delay)

# If requested, override the ptype
if opt.ptype != None:
Expand Down Expand Up @@ -215,6 +215,7 @@ def get_expected_scapy_ver():
parser.add_argument('--no-qos', default=False, action='store_true', help="Don't send QoS data frames (experimental - may break some tests).")
parser.add_argument('--freebsd-cache', default=False, action='store_true', help="Sent EAP(OL) frames as (malformed) broadcast EAPOL/A-MSDUs.")
parser.add_argument('--connected-delay', type=float, default=1, help="Second to wait after AfterAuth before triggering Connected event")
parser.add_argument('--pre-test-delay', type=int, default=0, help="Delay before launching the test")
parser.add_argument('--to-self', default=False, action='store_true', help="Send ARP/DHCP/ICMP with same src and dst MAC address.")
parser.add_argument('--no-drivercheck', default=False, action='store_true', help="Don't check if patched drivers are being used.")
parser.add_argument('--stay-up', default=False, action='store_true', help="Don't quit when test has finished.")
Expand Down
24 changes: 16 additions & 8 deletions research/fraginternals.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class Test(metaclass=abc.ABCMeta):
def __init__(self, actions=None):
self.actions = actions if actions != None else []
self.generated = False
self.pre_delay = None
self.delay = None
self.inc_pn = None
self.check_fn = None
Expand Down Expand Up @@ -260,25 +261,32 @@ def prepare(self, station):

def generate(self, station):
self.prepare(station)
self.enforce_delay()
self.enforce_delays()
self.enforce_inc_pn()

def check(self, p):
if self.check_fn == None:
return False
return self.check_fn(p)

def set_general_options(self, delay=None, inc_pn=None):
def set_general_options(self, delay=None, inc_pn=None, pre_delay=None):
self.pre_delay = pre_delay
self.delay = delay
self.inc_pn = inc_pn

def enforce_delay(self):
if self.delay == None or self.delay <= 0:
return
def enforce_delays(self):
inject_frags = self.get_actions(Action.Inject)

# Add a delay between injected fragments if requested
for frag in self.get_actions(Action.Inject)[1:]:
frag.delay = self.delay
# Add a delay before executing the first Inject action. This means a delay is added after
# possibly getting an IP via DHCP but before injecting the first test fragment/frame.
if self.pre_delay is not None and self.pre_delay > 0:
assert len(inject_frags) > 0
inject_frags[0].delay = self.pre_delay

# Add a delay between every next injected fragments if requested
if self.delay is not None and self.delay > 0:
for frag in inject_frags[1:]:
frag.delay = self.delay

def enforce_inc_pn(self):
if self.inc_pn == None:
Expand Down

0 comments on commit baa1c93

Please sign in to comment.