Support for Python3
That was fun.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from util.color import Color
|
||||
from .util.color import Color
|
||||
|
||||
import argparse, sys
|
||||
|
||||
@@ -366,11 +366,11 @@ class Arguments(object):
|
||||
help=Color.s('Show commands to crack a captured handshake'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
from util.color import Color
|
||||
from .util.color import Color
|
||||
from config import Configuration
|
||||
Configuration.initialize(False)
|
||||
a = Arguments(Configuration)
|
||||
args = a.args
|
||||
for (key,value) in sorted(args.__dict__.iteritems()):
|
||||
for (key,value) in sorted(args.__dict__.items()):
|
||||
Color.pl('{C}%s: {G}%s{W}' % (key.ljust(21),value))
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from ..tools.aircrack import Aircrack
|
||||
from ..config import Configuration
|
||||
from ..model.interface import Interface
|
||||
from ..util.color import Color
|
||||
from ..util.input import raw_input
|
||||
from ..model.wep_result import CrackResultWEP
|
||||
|
||||
import time
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from util.color import Color
|
||||
from tools.macchanger import Macchanger
|
||||
from .util.color import Color
|
||||
from .tools.macchanger import Macchanger
|
||||
|
||||
import os
|
||||
|
||||
@@ -108,7 +108,7 @@ class Configuration(object):
|
||||
def get_interface():
|
||||
if Configuration.interface is None:
|
||||
# Interface wasn't defined, select it!
|
||||
from tools.airmon import Airmon
|
||||
from .tools.airmon import Airmon
|
||||
Configuration.interface = Airmon.ask()
|
||||
if Configuration.random_mac:
|
||||
Macchanger.random()
|
||||
@@ -117,7 +117,7 @@ class Configuration(object):
|
||||
@staticmethod
|
||||
def load_from_arguments():
|
||||
''' Sets configuration values based on Argument.args object '''
|
||||
from args import Arguments
|
||||
from .args import Arguments
|
||||
|
||||
args = Arguments(Configuration).args
|
||||
if args.random_mac:
|
||||
@@ -315,7 +315,7 @@ class Configuration(object):
|
||||
''' Deletes temp and exist with the given code '''
|
||||
Configuration.delete_temp()
|
||||
Macchanger.reset_if_changed()
|
||||
from tools.airmon import Airmon
|
||||
from .tools.airmon import Airmon
|
||||
if hasattr(Configuration, "interface") and Configuration.interface is not None and Airmon.base_interface is not None:
|
||||
Airmon.stop(Configuration.interface)
|
||||
Airmon.put_interface_up(Airmon.base_interface)
|
||||
@@ -328,7 +328,7 @@ class Configuration(object):
|
||||
@staticmethod
|
||||
def dump():
|
||||
''' (Colorful) string representation of the configuration '''
|
||||
from util.color import Color
|
||||
from .util.color import Color
|
||||
|
||||
max_len = 20
|
||||
for key in Configuration.__dict__.keys():
|
||||
@@ -337,7 +337,7 @@ class Configuration(object):
|
||||
result = Color.s('{W}%s Value{W}\n' % 'Configuration Key'.ljust(max_len))
|
||||
result += Color.s('{W}%s------------------{W}\n' % ('-' * max_len))
|
||||
|
||||
for (key,val) in sorted(Configuration.__dict__.iteritems()):
|
||||
for (key,val) in sorted(Configuration.__dict__.items()):
|
||||
if key.startswith('__') or type(val) == staticmethod or val is None:
|
||||
continue
|
||||
result += Color.s("{G}%s {W} {C}%s{W}\n" % (key.ljust(max_len),val))
|
||||
@@ -345,4 +345,4 @@ class Configuration(object):
|
||||
|
||||
if __name__ == '__main__':
|
||||
Configuration.initialize(False)
|
||||
print Configuration.dump()
|
||||
print(Configuration.dump())
|
||||
|
||||
@@ -30,7 +30,7 @@ class Client(object):
|
||||
def __str__(self):
|
||||
''' String representation of a Client '''
|
||||
result = ''
|
||||
for (key,value) in self.__dict__.iteritems():
|
||||
for (key,value) in self.__dict__.items():
|
||||
result += key + ': ' + str(value)
|
||||
result += ', '
|
||||
return result
|
||||
@@ -39,4 +39,4 @@ class Client(object):
|
||||
if __name__ == '__main__':
|
||||
fields = 'AA:BB:CC:DD:EE:FF, 2015-05-27 19:43:47, 2015-05-27 19:43:47, -67, 2, (not associated) ,HOME-ABCD'.split(',')
|
||||
c = Client(fields)
|
||||
print c
|
||||
print('Client', c)
|
||||
|
||||
@@ -186,7 +186,7 @@ class Handshake(object):
|
||||
|
||||
bssids = set()
|
||||
# Check if we have all 4 messages for the handshake between the same MACs
|
||||
for (client_target, num) in target_client_msg_nums.iteritems():
|
||||
for (client_target, num) in target_client_msg_nums.items():
|
||||
if num == 4:
|
||||
# We got a handshake!
|
||||
bssid = client_target.split(',')[0]
|
||||
@@ -358,7 +358,6 @@ class Handshake(object):
|
||||
|
||||
if __name__ == '__main__':
|
||||
hs = Handshake('./tests/files/handshake_exists.cap', bssid='A4:2B:8C:16:6B:3A')
|
||||
|
||||
hs.analyze()
|
||||
print "has_hanshake() =", hs.has_handshake()
|
||||
print("has_hanshake() =", hs.has_handshake())
|
||||
|
||||
|
||||
@@ -98,4 +98,4 @@ class Interface(object):
|
||||
|
||||
if __name__ == '__main__':
|
||||
mac = Interface.get_mac()
|
||||
print 'wlan0mon mac address:', mac
|
||||
print('wlan0mon mac address:', mac)
|
||||
|
||||
@@ -31,7 +31,7 @@ class CrackResult(object):
|
||||
text = fid.read()
|
||||
try:
|
||||
json = loads(text)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
Color.pl('{!} error while loading %s: %s' % (name, str(e)))
|
||||
json.append(self.to_dict())
|
||||
with open(name, 'w') as fid:
|
||||
|
||||
@@ -147,5 +147,5 @@ if __name__ == '__main__':
|
||||
t = Target(fields)
|
||||
t.clients.append("asdf")
|
||||
t.clients.append("asdf")
|
||||
print t.to_str()
|
||||
print(t.to_str())
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ if __name__ == '__main__':
|
||||
w.dump()
|
||||
|
||||
w = CrackResultWPA('AA:BB:CC:DD:EE:FF', 'Test Router', 'hs/capfile.cap', 'Key')
|
||||
print '\n'
|
||||
print('\n')
|
||||
w.dump()
|
||||
w.save()
|
||||
print w.__dict__['bssid']
|
||||
print(w.__dict__['bssid'])
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ..util.process import Process
|
||||
from ..util.input import xrange
|
||||
from ..config import Configuration
|
||||
|
||||
import os
|
||||
@@ -80,17 +81,17 @@ if __name__ == '__main__':
|
||||
Configuration.initialize(False)
|
||||
|
||||
ivs_file = 'tests/files/wep-crackable.ivs'
|
||||
print "Running aircrack on %s ..." % ivs_file
|
||||
print("Running aircrack on %s ..." % ivs_file)
|
||||
|
||||
aircrack = Aircrack(ivs_file)
|
||||
while aircrack.is_running():
|
||||
sleep(1)
|
||||
|
||||
assert aircrack.is_cracked(), "Aircrack should have cracked %s" % ivs_file
|
||||
print "aircrack process completed."
|
||||
print("aircrack process completed.")
|
||||
|
||||
(hexkey, asciikey) = aircrack.get_key_hex_ascii()
|
||||
print "aircrack found HEX key: (%s) and ASCII key: (%s)" % (hexkey, asciikey)
|
||||
print("aircrack found HEX key: (%s) and ASCII key: (%s)" % (hexkey, asciikey))
|
||||
assert hexkey == '75:6E:63:6C:65', 'hexkey was "%s", expected "75:6E:63:6C:65"' % hexkey
|
||||
assert asciikey == 'uncle', 'asciikey was "%s", expected "uncle"' % asciikey
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class WEPAttackType(object):
|
||||
self.value = None
|
||||
self.name = None
|
||||
if type(var) is int:
|
||||
for (name,value) in WEPAttackType.__dict__.iteritems():
|
||||
for (name,value) in WEPAttackType.__dict__.items():
|
||||
if type(value) is int:
|
||||
if value == var:
|
||||
self.name = name
|
||||
@@ -37,7 +37,7 @@ class WEPAttackType(object):
|
||||
return
|
||||
raise Exception("Attack number %d not found" % var)
|
||||
elif type(var) is str:
|
||||
for (name,value) in WEPAttackType.__dict__.iteritems():
|
||||
for (name,value) in WEPAttackType.__dict__.items():
|
||||
if type(value) is int:
|
||||
if name == var:
|
||||
self.name = name
|
||||
@@ -438,12 +438,12 @@ class Aireplay(Thread):
|
||||
|
||||
if __name__ == '__main__':
|
||||
t = WEPAttackType(4)
|
||||
print t.name, type(t.name), t.value
|
||||
print(t.name, type(t.name), t.value)
|
||||
t = WEPAttackType('caffelatte')
|
||||
print t.name, type(t.name), t.value
|
||||
print(t.name, type(t.name), t.value)
|
||||
|
||||
t = WEPAttackType(t)
|
||||
print t.name, type(t.name), t.value
|
||||
print(t.name, type(t.name), t.value)
|
||||
|
||||
from ..model.target import Target
|
||||
fields = 'A4:2B:8C:16:6B:3A, 2015-05-27 19:28:44, 2015-05-27 19:28:46, 6, 54e, WEP, WEP, , -58, 2, 0, 0. 0. 0. 0, 9, Test Router Please Ignore, '.split(',')
|
||||
@@ -455,13 +455,13 @@ if __name__ == '__main__':
|
||||
from time import sleep
|
||||
sleep(0.1)
|
||||
stdout, stderr = aireplay.get_output()
|
||||
print "STDOUT>", stdout
|
||||
print "STDERR>", stderr
|
||||
print("STDOUT>", stdout)
|
||||
print("STDERR>", stderr)
|
||||
'''
|
||||
|
||||
'''
|
||||
forge = Aireplay.forge_packet('/tmp/replay_dec-0605-060243.xor', \
|
||||
'A4:2B:8C:16:6B:3A', \
|
||||
'00:C0:CA:4E:CA:E0')
|
||||
print forge
|
||||
print(forge)
|
||||
'''
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from ..model.interface import Interface
|
||||
from ..util.process import Process
|
||||
from ..util.color import Color
|
||||
from ..util.input import raw_input
|
||||
from ..config import Configuration
|
||||
|
||||
import re
|
||||
@@ -28,7 +29,7 @@ class Airmon(object):
|
||||
|
||||
def print_menu(self):
|
||||
''' Prints menu '''
|
||||
print Interface.menu_header()
|
||||
print(Interface.menu_header())
|
||||
for idx, iface in enumerate(self.interfaces, start=1):
|
||||
Color.pl(" {G}%d{W}. %s" % (idx, iface))
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ class Airodump(object):
|
||||
capfile = csv_filename[:-3] + 'cap'
|
||||
try:
|
||||
Tshark.check_for_wps_and_update_targets(capfile, targets)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
# No tshark, or it failed. Fall-back to wash
|
||||
Wash.check_for_wps_and_update_targets(capfile, targets)
|
||||
|
||||
@@ -180,8 +180,13 @@ class Airodump(object):
|
||||
targets = []
|
||||
import csv
|
||||
with open(csv_filename, 'rb') as csvopen:
|
||||
lines = (line.replace('\0', '') for line in csvopen)
|
||||
lines = []
|
||||
for line in csvopen:
|
||||
if type(line) is bytes: line = line.decode('utf-8')
|
||||
line = line.replace('\0', '')
|
||||
lines.append(line)
|
||||
csv_reader = csv.reader(lines, delimiter=',')
|
||||
|
||||
hit_clients = False
|
||||
for row in csv_reader:
|
||||
# Each "row" is a list of fields for a target/client
|
||||
|
||||
@@ -254,7 +254,7 @@ if __name__ == '__main__':
|
||||
fields = '34:21:09:01:92:7C,2015-05-27 19:28:44,2015-05-27 19:28:46,1,54,WPA2,CCMP TKIP,PSK,-58,2,0,0.0.0.0,9,AirLink89300,'.split(',')
|
||||
target = Target(fields)
|
||||
psk = Bully.get_psk_from_pin(target, '01030365')
|
||||
print "psk", psk
|
||||
print("psk", psk)
|
||||
|
||||
'''
|
||||
stdout = " [*] Pin is '11867722', key is '9a6f7997'"
|
||||
|
||||
@@ -268,7 +268,7 @@ executing pixiewps -e d0141b15656e96b85fcead2e8e76330d2b1ac1576bb026e7a328c0e1ba
|
||||
result = CrackResultWPS('AA:BB:CC:DD:EE:FF', ssid, pin, psk)
|
||||
result.dump()
|
||||
|
||||
print ""
|
||||
print("")
|
||||
|
||||
(pin, psk, ssid) = Reaver.get_pin_psk_ssid(new_stdout)
|
||||
assert pin == '11867722', 'pin was "%s", should have been "11867722"' % pin
|
||||
|
||||
@@ -82,6 +82,6 @@ if __name__ == '__main__':
|
||||
# Should update 'wps' field of a target
|
||||
Tshark.check_for_wps_and_update_targets(test_file, targets)
|
||||
|
||||
print 'Target(BSSID={}).wps = {} (Expected: True)'.format(targets[0].bssid, targets[0].wps)
|
||||
print('Target(BSSID={}).wps = {} (Expected: True)'.format(targets[0].bssid, targets[0].wps))
|
||||
assert targets[0].wps == True
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ if __name__ == '__main__':
|
||||
# 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)
|
||||
print('Target(BSSID={}).wps = {} (Expected: True)'.format(targets[0].bssid, targets[0].wps))
|
||||
|
||||
assert targets[0].wps == True
|
||||
|
||||
|
||||
@@ -63,9 +63,9 @@ class Color(object):
|
||||
def s(text):
|
||||
''' Returns colored string '''
|
||||
output = text
|
||||
for (key,value) in Color.replacements.iteritems():
|
||||
for (key,value) in Color.replacements.items():
|
||||
output = output.replace(key, value)
|
||||
for (key,value) in Color.colors.iteritems():
|
||||
for (key,value) in Color.colors.items():
|
||||
output = output.replace("{%s}" % key, value)
|
||||
return output
|
||||
|
||||
@@ -96,7 +96,7 @@ class Color(object):
|
||||
|
||||
if __name__ == '__main__':
|
||||
Color.pl("{R}Testing{G}One{C}Two{P}Three{W}Done")
|
||||
print Color.s("{C}Testing{P}String{W}")
|
||||
print(Color.s("{C}Testing{P}String{W}"))
|
||||
Color.pl("{+} Good line")
|
||||
Color.pl("{!} Danger")
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from ..util.process import Process
|
||||
from ..util.color import Color
|
||||
from ..util.input import raw_input
|
||||
from ..config import Configuration
|
||||
from ..model.result import CrackResult
|
||||
|
||||
|
||||
17
wifite/util/input.py
Normal file
17
wifite/util/input.py
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Fix for raw_input on python3: https://stackoverflow.com/a/7321970
|
||||
try:
|
||||
input = raw_input
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
raw_input = input
|
||||
|
||||
try:
|
||||
range = xrange
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
xrange = range
|
||||
@@ -36,6 +36,11 @@ class Process(object):
|
||||
pid.wait()
|
||||
(stdout, stderr) = pid.communicate()
|
||||
|
||||
# Python 3 compatibility
|
||||
if type(stdout) is bytes: stdout = stdout.decode('utf-8')
|
||||
if type(stderr) is bytes: stderr = stderr.decode('utf-8')
|
||||
|
||||
|
||||
if Configuration.verbose > 1 and stdout is not None and stdout.strip() != '':
|
||||
Color.pe("{P} [stdout] %s{W}" % '\n [stdout] '.join(stdout.strip().split('\n')))
|
||||
if Configuration.verbose > 1 and stderr is not None and stderr.strip() != '':
|
||||
@@ -114,6 +119,13 @@ class Process(object):
|
||||
self.pid.wait()
|
||||
if self.out is None:
|
||||
(self.out, self.err) = self.pid.communicate()
|
||||
|
||||
if type(self.out) is bytes:
|
||||
self.out = self.out.decode('utf-8')
|
||||
|
||||
if type(self.err) is bytes:
|
||||
self.err = self.err.decode('utf-8')
|
||||
|
||||
return (self.out, self.err)
|
||||
|
||||
def poll(self):
|
||||
@@ -151,7 +163,7 @@ class Process(object):
|
||||
self.pid.terminate()
|
||||
break
|
||||
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if 'No such process' in e.__str__():
|
||||
return
|
||||
raise e # process cannot be killed
|
||||
@@ -159,20 +171,20 @@ class Process(object):
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = Process('ls')
|
||||
print p.stdout(), p.stderr()
|
||||
print(p.stdout(), p.stderr())
|
||||
p.interrupt()
|
||||
|
||||
# Calling as list of arguments
|
||||
(out, err) = Process.call(['ls', '-lah'])
|
||||
print out, err
|
||||
print(out, err)
|
||||
|
||||
print '\n---------------------\n'
|
||||
print('\n---------------------\n')
|
||||
|
||||
# Calling as string
|
||||
(out, err) = Process.call('ls -l | head -2')
|
||||
print out, err
|
||||
print(out, err)
|
||||
|
||||
print '"reaver" exists:', Process.exists('reaver')
|
||||
print('"reaver" exists:', Process.exists('reaver'))
|
||||
|
||||
# Test on never-ending process
|
||||
p = Process('yes')
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from ..tools.airodump import Airodump
|
||||
from ..util.color import Color
|
||||
from ..util.input import raw_input, xrange
|
||||
from ..model.target import Target
|
||||
from ..config import Configuration
|
||||
|
||||
@@ -40,7 +41,7 @@ class Scanner(object):
|
||||
|
||||
try:
|
||||
self.targets = airodump.get_targets()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
break
|
||||
|
||||
if self.found_target():
|
||||
@@ -219,7 +220,7 @@ if __name__ == '__main__':
|
||||
try:
|
||||
s = Scanner()
|
||||
targets = s.select_targets()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
Color.pl('\r {!} {R}Error{W}: %s' % str(e))
|
||||
Configuration.exit_gracefully(0)
|
||||
for t in targets:
|
||||
|
||||
@@ -2,19 +2,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
try:
|
||||
from config import Configuration
|
||||
from .config import Configuration
|
||||
except (ValueError, ImportError) as e:
|
||||
raise Exception('You may need to run wifite from the root directory (which includes README.md)')
|
||||
|
||||
from util.scanner import Scanner
|
||||
from util.process import Process
|
||||
from util.color import Color
|
||||
from util.crack import CrackHandshake
|
||||
from attack.wep import AttackWEP
|
||||
from attack.wpa import AttackWPA
|
||||
from attack.wps import AttackWPS
|
||||
from model.result import CrackResult
|
||||
from model.handshake import Handshake
|
||||
from .util.scanner import Scanner
|
||||
from .util.process import Process
|
||||
from .util.color import Color
|
||||
from .util.crack import CrackHandshake
|
||||
from .util.input import raw_input
|
||||
from .attack.wep import AttackWEP
|
||||
from .attack.wpa import AttackWPA
|
||||
from .attack.wps import AttackWPS
|
||||
from .model.result import CrackResult
|
||||
from .model.handshake import Handshake
|
||||
|
||||
import json
|
||||
import os
|
||||
@@ -95,7 +96,7 @@ class Wifite(object):
|
||||
Color.pl('{+} checking all handshakes in {G}"./hs"{W} directory\n')
|
||||
try:
|
||||
capfiles = [os.path.join('hs', x) for x in os.listdir('hs') if x.endswith('.cap')]
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
capfiles = []
|
||||
if len(capfiles) == 0:
|
||||
Color.pl('{!} {R}no .cap files found in {O}"./hs"{W}\n')
|
||||
@@ -173,7 +174,7 @@ class Wifite(object):
|
||||
|
||||
try:
|
||||
attack.run()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
Color.pl("\n{!} {R}Error: {O}%s" % str(e))
|
||||
if Configuration.verbose > 0 or True:
|
||||
Color.pl('\n{!} {O}Full stack trace below')
|
||||
@@ -234,7 +235,7 @@ def run():
|
||||
try:
|
||||
w.main()
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
Color.pl('\n{!} {R}Error:{O} %s{W}' % str(e))
|
||||
|
||||
if Configuration.verbose > 0 or True:
|
||||
|
||||
Reference in New Issue
Block a user