Massive refactor/renaming. No more upper-case filenames.
This commit is contained in:
82
wifite/tools/aircrack.py
Executable file
82
wifite/tools/aircrack.py
Executable file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ..util.process import Process
|
||||
from ..config import Configuration
|
||||
|
||||
import os
|
||||
|
||||
class Aircrack(object):
|
||||
def __init__(self, ivs_file=None):
|
||||
|
||||
self.cracked_file = Configuration.temp() + 'wepkey.txt'
|
||||
|
||||
# Delete previous cracked files
|
||||
if os.path.exists(self.cracked_file):
|
||||
os.remove(self.cracked_file)
|
||||
|
||||
command = [
|
||||
'aircrack-ng',
|
||||
'-a', '1',
|
||||
'-l', self.cracked_file,
|
||||
ivs_file
|
||||
]
|
||||
|
||||
self.pid = Process(command, devnull=True)
|
||||
|
||||
|
||||
def is_running(self):
|
||||
return self.pid.poll() is None
|
||||
|
||||
def is_cracked(self):
|
||||
return os.path.exists(self.cracked_file)
|
||||
|
||||
def stop(self):
|
||||
''' Stops aircrack process '''
|
||||
if self.pid.poll() is None:
|
||||
self.pid.interrupt()
|
||||
|
||||
def get_key_hex_ascii(self):
|
||||
if not self.is_cracked():
|
||||
raise Exception('Cracked file not found')
|
||||
with open(self.cracked_file, 'r') as fid:
|
||||
hex_raw = fid.read()
|
||||
hex_key = ''
|
||||
ascii_key = ''
|
||||
while len(hex_raw) > 0:
|
||||
# HEX
|
||||
if hex_key != '':
|
||||
hex_key += ':'
|
||||
hex_key += hex_raw[0:2]
|
||||
|
||||
# ASCII
|
||||
# Convert hex to decimal
|
||||
code = int(hex_raw[0:2], 16)
|
||||
if code < 32 or code > 127:
|
||||
# Hex key is non-printable in ascii
|
||||
ascii_key = None
|
||||
continue
|
||||
elif ascii_key is None:
|
||||
# We can't generate an Ascii key
|
||||
continue
|
||||
# Convert decimal to char
|
||||
ascii_key += chr(code)
|
||||
|
||||
# Trim first two characters
|
||||
hex_raw = hex_raw[2:]
|
||||
continue
|
||||
|
||||
return (hex_key, ascii_key)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from time import sleep
|
||||
Configuration.initialize(False)
|
||||
a = Aircrack('tests/files/wep-crackable.ivs')
|
||||
while a.is_running():
|
||||
sleep(1)
|
||||
if a.is_cracked():
|
||||
print "cracked!"
|
||||
print '(hex, ascii) =', a.get_key_hex_ascii()
|
||||
else:
|
||||
print "Not cracked"
|
||||
Configuration.exit_gracefully(0)
|
||||
Reference in New Issue
Block a user