Skip to content

Commit

Permalink
Some python3 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kimocoder committed May 24, 2020
1 parent 09d2602 commit 74f706f
Show file tree
Hide file tree
Showing 29 changed files with 226 additions and 201 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![GitHub version](https://img.shields.io/badge/version-2.5.4-informational.svg)](#)
[![GitHub version](https://img.shields.io/badge/version-2.5.5-informational.svg)](#)
[![GitHub issues](https://img.shields.io/github/issues/kimocoder/wifite2.svg)](https://github.com/kimocoder/wifite2/issues)
[![GitHub forks](https://img.shields.io/github/forks/kimocoder/wifite2.svg)](https://github.com/kimocoder/wifite2/network)
[![GitHub stars](https://img.shields.io/github/stars/kimocoder/wifite2.svg)](https://github.com/kimocoder/wifite2/stargazers)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_Airmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import unittest


class TestAirmon(unittest.TestCase):
def test_airmon_start(self):
# From https://github.com/derv82/wifite2/issues/67
Expand All @@ -21,4 +22,3 @@ def test_airmon_start(self):
'''
mon_iface = Airmon._parse_airmon_start(stdout)
assert mon_iface == 'wlan0mon', 'Expected monitor-mode interface to be "wlan0mon" but got "{}"'.format(mon_iface)

6 changes: 3 additions & 3 deletions tests/test_Airodump.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import unittest


class TestAirodump(unittest.TestCase):
''' Test suite for Wifite's interaction with the Airodump tool '''


def test_airodump_weird_characters(self):
csv_filename = self.getFile('airodump-weird-ssids.csv')
targets = Airodump.get_targets_from_csv(csv_filename)
Expand Down Expand Up @@ -39,10 +39,10 @@ def test_airodump_weird_characters(self):
assert target.essid == expected, 'Expected ESSID (%s) but got (%s)' % (expected, target.essid)
assert target.essid_len == 19, 'ESSID length shold be 19, but got %s' % target.essid_len


def getFile(self, filename):
''' Helper method to parse targets from filename '''
import os, inspect
import os
import inspect
this_file = os.path.abspath(inspect.getsourcefile(self.getFile))
this_dir = os.path.dirname(this_file)
return os.path.join(this_dir, 'files', filename)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_Handshake.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.path.insert(0, '..')

from wifite.model.handshake import Handshake
from wifite.util.process import Process

import sys
sys.path.insert(0, '..')

import unittest


class TestHandshake(unittest.TestCase):
''' Test suite for Target parsing an generation '''

Expand Down Expand Up @@ -55,4 +56,3 @@ def testHandshakeAircrack(self):

if __name__ == '__main__':
unittest.main()

3 changes: 2 additions & 1 deletion tests/test_Target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-

from wifite.tools.airodump import Airodump

import unittest


class TestTarget(unittest.TestCase):
''' Test suite for Target parsing an generation '''

Expand All @@ -31,5 +31,6 @@ def testTargetClients(self):
if t.bssid == '00:1D:D5:9B:11:00':
assert(len(t.clients) > 0)


if __name__ == '__main__':
unittest.main()
3 changes: 2 additions & 1 deletion wifite/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import os


class Wifite(object):

def __init__(self):
Expand Down Expand Up @@ -89,7 +90,6 @@ def scan_and_attack(self):

Color.pl('{+} Finished attacking {C}%d{W} target(s), exiting' % attacked_targets)

##############################################################

def entry_point():
try:
Expand All @@ -104,5 +104,6 @@ def entry_point():

Configuration.exit_gracefully(0)


if __name__ == '__main__':
entry_point()
8 changes: 5 additions & 3 deletions wifite/args.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from .util.color import Color

import argparse, sys
import argparse
import sys


class Arguments(object):
''' Holds arguments used by the Wifite '''
Expand Down Expand Up @@ -535,5 +537,5 @@ def _add_command_args(self, commands):
Configuration.initialize(False)
a = Arguments(Configuration)
args = a.args
for (key,value) in sorted(args.__dict__.items()):
Color.pl('{C}%s: {G}%s{W}' % (key.ljust(21),value))
for (key, value) in sorted(args.__dict__.items()):
Color.pl('{C}%s: {G}%s{W}' % (key.ljust(21), value))
5 changes: 3 additions & 2 deletions wifite/attack/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..config import Configuration
from ..util.color import Color


class AttackAll(object):

@classmethod
Expand Down Expand Up @@ -65,7 +66,7 @@ def attack_single(cls, target, targets_remaining):

# WPS
if not Configuration.use_pmkid_only:
if target.wps != False and AttackWPS.can_attack_wps():
if target.wps is not False and AttackWPS.can_attack_wps():
# Pixie-Dust
if Configuration.wps_pixie:
attacks.append(AttackWPS(target, pixie_dust=True))
Expand Down Expand Up @@ -161,6 +162,6 @@ def user_wants_to_continue(cls, targets_remaining, attacks_remaining=0):
if answer.startswith('s'):
return None # Skip
elif answer.startswith('e') or answer.startswith('r'):
return False # Exit/Return
return False # Exit/Return
else:
return True # Continue
4 changes: 2 additions & 2 deletions wifite/attack/pmkid.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import re
from shutil import copy


class AttackPMKID(Attack):

def __init__(self, target):
Expand Down Expand Up @@ -53,7 +54,6 @@ def get_existing_pmkid_file(self, bssid):
return pmkid_filename
return None


def run_hashcat(self):
'''
Performs PMKID attack, if possible.
Expand Down Expand Up @@ -285,7 +285,7 @@ def crack_pmkid_file(self, pmkid_file):
'because there is no {R}wordlist{O} (re-run with {C}--dict{O})')

# TODO: Uncomment once --crack is updated to support recracking PMKIDs.
#Color.pl('{!} {O}Run Wifite with the {R}--crack{O} and {R}--dict{O} options to try again.')
# Color.pl('{!} {O}Run Wifite with the {R}--crack{O} and {R}--dict{O} options to try again.')

key = None
else:
Expand Down
26 changes: 14 additions & 12 deletions wifite/attack/wep.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import time


class AttackWEP(Attack):
'''
Contains logic for attacking a WEP-encrypted access point.
Expand All @@ -32,7 +33,7 @@ def run(self):
Returns: True if attack is successful, false otherwise
'''

aircrack = None # Aircrack process, not started yet
aircrack = None # Aircrack process, not started yet
fakeauth_proc = None
replay_file = None
airodump_target = None
Expand All @@ -54,8 +55,8 @@ def run(self):
# Start Airodump process
with Airodump(channel=self.target.channel,
target_bssid=self.target.bssid,
ivs_only=True, # Only capture IVs packets
skip_wps=True, # Don't check for WPS-compatibility
ivs_only=True, # Only capture IVs packets
skip_wps=True, # Don't check for WPS-compatibility
output_file_prefix='wep',
delete_existing_files=not keep_ivs) as airodump:

Expand Down Expand Up @@ -90,7 +91,7 @@ def run(self):
client_mac=client_mac,
replay_file=replay_file)

time_unchanged_ivs = time.time() # Timestamp when IVs last changed
time_unchanged_ivs = time.time() # Timestamp when IVs last changed
last_ivs_count = 0

# Loop until attack completes.
Expand Down Expand Up @@ -156,7 +157,7 @@ def run(self):

elif 0 < Configuration.wep_restart_aircrack < aircrack.pid.running_time():
# Restart aircrack after X seconds
#Color.pl('\n{+} {C}aircrack{W} ran for more than {C}%d{W} seconds, restarting' % Configuration.wep_restart_aircrack)
# Color.pl('\n{+} {C}aircrack{W} ran for more than {C}%d{W} seconds, restarting' % Configuration.wep_restart_aircrack)
aircrack.stop()
ivs_files = airodump.find_files(endswith='.ivs')
ivs_files.sort()
Expand Down Expand Up @@ -206,7 +207,7 @@ def run(self):
Color.pl('\n{!} {O}aireplay-ng exited unexpectedly{W}')
Color.pl('{?} {O}Command: {R}%s{W}' % ' '.join(aireplay.cmd))
Color.pl('{?} {O}Output:\n{R}%s{W}' % aireplay.get_output())
break # Continue to other attacks
break # Continue to other attacks

# Check if IVs stopped flowing (same for > N seconds)
if airodump_target.ivs > last_ivs_count:
Expand All @@ -221,9 +222,9 @@ def run(self):
Color.pl('\n{!} restarting {C}aireplay{W} after' +
' {C}%d{W} seconds of no new IVs'
% stale_seconds)
aireplay = Aireplay(self.target, \
wep_attack_type, \
client_mac=client_mac, \
aireplay = Aireplay(self.target,
wep_attack_type,
client_mac=client_mac,
replay_file=replay_file)
time_unchanged_ivs = time.time()
last_ivs_count = airodump_target.ivs
Expand Down Expand Up @@ -318,13 +319,13 @@ def user_wants_to_stop(self, current_attack, attacks_remaining, target):

# Re-insert current attack to top of list of attacks remaining
attacks_remaining.insert(0, current_attack)
return False # Don't stop
return False # Don't stop
elif answer == attack_index:
return True # Stop attacking
return True # Stop attacking
elif answer > 1:
# User selected specific attack: Re-order attacks based on desired next-step
attacks_remaining.insert(0, attacks_remaining.pop(answer-2))
return False # Don't stop
return False # Don't stop

def fake_auth(self):
'''
Expand All @@ -351,6 +352,7 @@ def fake_auth(self):
' {G}--require-fakeauth{W} was not set')
return fakeauth


if __name__ == '__main__':
Configuration.initialize(True)
from ..model.target import Target
Expand Down
8 changes: 4 additions & 4 deletions wifite/attack/wpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import re
from shutil import copy


class AttackWPA(Attack):
def __init__(self, target):
super(AttackWPA, self).__init__(target)
Expand All @@ -27,7 +28,7 @@ def run(self):
'''Initiates full WPA handshake capture attack.'''

# Skip if target is not WPS
if Configuration.wps_only and self.target.wps == False:
if Configuration.wps_only and self.target.wps is False:
Color.pl('\r{!} {O}Skipping WPA-Handshake attack on {R}%s{O} because {R}--wps-only{O} is set{W}' % self.target.essid)
self.success = False
return self.success
Expand Down Expand Up @@ -83,7 +84,6 @@ def run(self):
self.success = True
return self.success


def capture_handshake(self):
'''Returns captured or stored handshake, otherwise None.'''
handshake = None
Expand Down Expand Up @@ -172,7 +172,7 @@ def capture_handshake(self):

# Sleep for at-most 1 second
time.sleep(step_timer.remaining())
continue # Handshake listen+deauth loop
continue # Handshake listen+deauth loop

if handshake is None:
# No handshake, attack failed.
Expand Down Expand Up @@ -234,7 +234,6 @@ def save_handshake(self, handshake):
# Update handshake to use the stored handshake file for future operations
handshake.capfile = cap_filename


def deauth(self, target):
'''
Sends deauthentication request to broadcast and every client of target.
Expand All @@ -255,6 +254,7 @@ def deauth(self, target):
'Deauthing {O}%s{W}' % target_name)
Aireplay.deauth(target.bssid, client_mac=client, timeout=2)


if __name__ == '__main__':
Configuration.initialize(True)
from ..model.target import Target
Expand Down
1 change: 1 addition & 0 deletions wifite/attack/wps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..tools.bully import Bully
from ..tools.reaver import Reaver


class AttackWPS(Attack):

@staticmethod
Expand Down
Loading

0 comments on commit 74f706f

Please sign in to comment.