diff --git a/wifite/model/handshake.py b/wifite/model/handshake.py index a93df72..609c0aa 100755 --- a/wifite/model/handshake.py +++ b/wifite/model/handshake.py @@ -17,7 +17,7 @@ class Handshake(object): ''' Tries to find BSSID and ESSID from cap file. Sets this instances 'bssid' and 'essid' instance fields. - ''' + ''' # Get list of bssid/essid pairs from cap file pairs = self.tshark_bssid_essid_pairs() if len(pairs) == 0: @@ -65,14 +65,12 @@ class Handshake(object): if len(self.pyrit_handshakes()) > 0: return True - - # XXX: Disabling these checks since I don't think they are reliable. - ''' if len(self.cowpatty_handshakes()) > 0: return True + if len(self.aircrack_handshakes()) > 0: return True - ''' + return False @@ -82,7 +80,7 @@ class Handshake(object): Returns list of tuples: (bssid,essid) ''' if not Process.exists('tshark'): - raise Exception('tshark is required to find ESSID') + return [] essids = set() diff --git a/wifite/tools/airodump.py b/wifite/tools/airodump.py index 7e52d7d..9966c5a 100755 --- a/wifite/tools/airodump.py +++ b/wifite/tools/airodump.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from .tshark import Tshark +from .wash import Wash from ..util.process import Process from ..config import Configuration from ..model.target import Target @@ -142,7 +143,11 @@ class Airodump(object): # Check targets for WPS if not self.skip_wps: 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: # Filter targets based on encryption & WPS capability diff --git a/wifite/tools/tshark.py b/wifite/tools/tshark.py index 36a0d0f..f5f949e 100755 --- a/wifite/tools/tshark.py +++ b/wifite/tools/tshark.py @@ -10,6 +10,10 @@ class Tshark(object): def __init__(self): pass + @staticmethod + def exists(): + return Process.exists('tshark') + @staticmethod def check_for_wps_and_update_targets(capfile, targets): ''' @@ -21,9 +25,9 @@ class Tshark(object): capfile - .cap file from airodump containing packets targets - list of Targets from scan, to be updated ''' - # Tshark is required to detect WPS networks - if not Process.exists('tshark'): - return + + if not Tshark.exists(): + raise Exception('Cannot detect WPS networks: Tshark does not exist') command = [ 'tshark', @@ -38,7 +42,6 @@ class Tshark(object): ] p = Process(command) - try: p.wait() lines = p.stdout() diff --git a/wifite/tools/wash.py b/wifite/tools/wash.py new file mode 100644 index 0000000..914477d --- /dev/null +++ b/wifite/tools/wash.py @@ -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 +