Tshark is optional, falls-back to Wash for WPS-detection.

Should resolve #77
This commit is contained in:
derv82
2018-03-31 18:40:39 -04:00
parent 528741f89f
commit 1ad17472b2
4 changed files with 91 additions and 11 deletions

View File

@@ -17,7 +17,7 @@ class Handshake(object):
''' '''
Tries to find BSSID and ESSID from cap file. Tries to find BSSID and ESSID from cap file.
Sets this instances 'bssid' and 'essid' instance fields. Sets this instances 'bssid' and 'essid' instance fields.
''' '''
# Get list of bssid/essid pairs from cap file # Get list of bssid/essid pairs from cap file
pairs = self.tshark_bssid_essid_pairs() pairs = self.tshark_bssid_essid_pairs()
if len(pairs) == 0: if len(pairs) == 0:
@@ -65,14 +65,12 @@ class Handshake(object):
if len(self.pyrit_handshakes()) > 0: if len(self.pyrit_handshakes()) > 0:
return True return True
# XXX: Disabling these checks since I don't think they are reliable.
'''
if len(self.cowpatty_handshakes()) > 0: if len(self.cowpatty_handshakes()) > 0:
return True return True
if len(self.aircrack_handshakes()) > 0: if len(self.aircrack_handshakes()) > 0:
return True return True
'''
return False return False
@@ -82,7 +80,7 @@ class Handshake(object):
Returns list of tuples: (bssid,essid) Returns list of tuples: (bssid,essid)
''' '''
if not Process.exists('tshark'): if not Process.exists('tshark'):
raise Exception('tshark is required to find ESSID') return []
essids = set() essids = set()

View File

@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from .tshark import Tshark from .tshark import Tshark
from .wash import Wash
from ..util.process import Process from ..util.process import Process
from ..config import Configuration from ..config import Configuration
from ..model.target import Target from ..model.target import Target
@@ -142,7 +143,11 @@ class Airodump(object):
# Check targets for WPS # Check targets for WPS
if not self.skip_wps: if not self.skip_wps:
capfile = csv_filename[:-3] + 'cap' capfile = csv_filename[:-3] + 'cap'
Tshark.check_for_wps_and_update_targets(capfile, targets) try:
Tshark.check_for_wps_and_update_targets(capfile, targets)
except Exception, e:
# No tshark, or it failed. Fall-back to wash
Wash.check_for_wps_and_update_targets(capfile, targets)
if apply_filter: if apply_filter:
# Filter targets based on encryption & WPS capability # Filter targets based on encryption & WPS capability

View File

@@ -10,6 +10,10 @@ class Tshark(object):
def __init__(self): def __init__(self):
pass pass
@staticmethod
def exists():
return Process.exists('tshark')
@staticmethod @staticmethod
def check_for_wps_and_update_targets(capfile, targets): def check_for_wps_and_update_targets(capfile, targets):
''' '''
@@ -21,9 +25,9 @@ class Tshark(object):
capfile - .cap file from airodump containing packets capfile - .cap file from airodump containing packets
targets - list of Targets from scan, to be updated targets - list of Targets from scan, to be updated
''' '''
# Tshark is required to detect WPS networks
if not Process.exists('tshark'): if not Tshark.exists():
return raise Exception('Cannot detect WPS networks: Tshark does not exist')
command = [ command = [
'tshark', 'tshark',
@@ -38,7 +42,6 @@ class Tshark(object):
] ]
p = Process(command) p = Process(command)
try: try:
p.wait() p.wait()
lines = p.stdout() lines = p.stdout()

74
wifite/tools/wash.py Normal file
View File

@@ -0,0 +1,74 @@
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
from ..util.process import Process
import json
class Wash(object):
''' Wrapper for Wash program. '''
def __init__(self):
pass
@staticmethod
def exists():
return Process.exists('wash')
@staticmethod
def check_for_wps_and_update_targets(capfile, targets):
if not Wash.exists():
return
command = [
'wash',
'-f', capfile,
'-j' # json
]
p = Process(command)
try:
p.wait()
lines = p.stdout()
except:
# Failure is acceptable
return
# Find all BSSIDs
bssids = set()
for line in lines.split('\n'):
try:
obj = json.loads(line)
bssid = obj['bssid']
locked = obj['wps_locked']
if locked != True:
bssids.add(bssid)
except:
pass
# Update targets
for t in targets:
t.wps = t.bssid.upper() in bssids
if __name__ == '__main__':
test_file = './tests/files/contains_wps_network.cap'
target_bssid = 'A4:2B:8C:16:6B:3A'
from ..model.target import Target
fields = [
'A4:2B:8C:16:6B:3A', # BSSID
'2015-05-27 19:28:44', '2015-05-27 19:28:46', # Dates
'11', # Channel
'54', # throughput
'WPA2', 'CCMP TKIP', 'PSK', # AUTH
'-58', '2', '0', '0.0.0.0', '9', # ???
'Test Router Please Ignore', # SSID
]
t = Target(fields)
targets = [t]
# Should update 'wps' field of a target
Wash.check_for_wps_and_update_targets(test_file, targets)
print 'Target(BSSID={}).wps = {} (Expected: True)'.format(targets[0].bssid, targets[0].wps)
assert targets[0].wps == True