From 1d6d0aedb3015a90484b4713dfc513c8ab3816a4 Mon Sep 17 00:00:00 2001 From: derv82 Date: Sun, 31 May 2015 11:12:17 -0700 Subject: [PATCH] Restart aireplay and aircrack after X seconds --- py/Aircrack.py | 8 ++++++-- py/AttackWEP.py | 48 +++++++++++++++++++++------------------------ py/Configuration.py | 2 ++ py/Process.py | 2 +- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/py/Aircrack.py b/py/Aircrack.py index 43b97a7..711d881 100644 --- a/py/Aircrack.py +++ b/py/Aircrack.py @@ -6,7 +6,8 @@ from Configuration import Configuration import os class Aircrack(object): - def __init__(self, ivs_file): + def __init__(self, ivs_file=None): + self.cracked_file = Configuration.temp() + 'wepkey.txt' # Delete previous cracked files @@ -26,10 +27,13 @@ class Aircrack(object): def is_running(self): return self.pid.poll() == None - def is_cracked(self): return os.path.exists(self.cracked_file) + def stop(self): + ''' Stops aircrack process ''' + if self.pid.poll() == None: + self.pid.interrupt() def get_key_hex_ascii(self): if not self.is_cracked(): diff --git a/py/AttackWEP.py b/py/AttackWEP.py index 4f67a4f..4f59462 100644 --- a/py/AttackWEP.py +++ b/py/AttackWEP.py @@ -105,37 +105,30 @@ class AttackWEP(Attack): # Check number of IVs, crack if necessary if airodump_target.ivs > Configuration.wep_crack_at_ivs: if not aircrack: - # Aircrack hasn't started yet. - # Find the .ivs file. - ivs_file = None - for fil in airodump.find_files(endswith='.ivs'): - ivs_file = fil - break - if not ivs_file: - Color.pl('{!} {O}no .ivs file found, stopping{W}') - break - else: - Color.pl('\n{+} started {C}cracking{W}') - aircrack = Aircrack(ivs_file) + # Aircrack hasn't started yet. Start it. + ivs_file = airodump.find_files(endswith='.ivs')[0] + Color.pl('\n{+} started {C}cracking{W}') + aircrack = Aircrack(ivs_file) elif not aircrack.is_running(): # Aircrack stopped running. Color.pl('\n{!} {O}aircrack stopped running!{W}') - ivs_file = None - for fil in airodump.find_files(endswith='.ivs'): - ivs_file = fil - break - if ivs_file: - Color.pl('{+} restarting {C}aircrack{W}') + ivs_file = airodump.find_files(endswith='.ivs')[0] + Color.pl('{+} {C}aircrack{W} stopped,' + + ' restarting {C}aircrack{W}') + aircrack = Aircrack(ivs_file) + + elif aircrack.is_running() and \ + Configuration.wep_restart_aircrack > 0: + # Restart aircrack after X seconds + if aircrack.pid.running_time() > Configuration.wep_restart_aircrack: + aircrack.stop() + ivs_file = airodump.find_files(endswith='.ivs')[0] + Color.pl('{+} {C}aircrack{W} running more than' + + ' {C}%d{W} seconds, restarting' + % Configuration.wep_restart_aircrack) aircrack = Aircrack(ivs_file) - else: - # No .ivs file and aircrack stopped, error? - Color.pl('{!} {O}no .ivs file found, stopping{W}') - break - elif aircrack.is_running(): - # TODO: Restart aircrack after X seconds - pass - + if not aireplay.is_running(): # Some Aireplay attacks loop infinitely @@ -168,6 +161,9 @@ class AttackWEP(Attack): if stale_seconds > Configuration.wep_restart_stale_ivs: # No new IVs within threshold, restart aireplay aireplay.stop() + Color.pl('{!} 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) diff --git a/py/Configuration.py b/py/Configuration.py index 02b747d..4773521 100644 --- a/py/Configuration.py +++ b/py/Configuration.py @@ -37,6 +37,8 @@ class Configuration(object): Configuration.wep_restart_stale_ivs = 30 # Seconds to wait before restarting # Aireplay if IVs don't increaes. # "0" means never restart. + Configuration.wep_restart_aircrack = 180 # Seconds to give aircrack to crack + # before restarting the process. # WEP-specific attacks Configuration.wep_fragment = True Configuration.wep_caffelatte = True diff --git a/py/Process.py b/py/Process.py index bef0071..2ef8a38 100644 --- a/py/Process.py +++ b/py/Process.py @@ -86,7 +86,7 @@ class Process(object): ''' Returns exit code if process is dead, otherwise "None" ''' return self.pid.poll() - def time_running(self): + def running_time(self): ''' Returns number of seconds since process was started ''' return int(time.time() - self.start_time)