Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kimocoder committed Aug 24, 2023
1 parent 1850fd7 commit 857eb5b
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 49 deletions.
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "wifite2"
version = "0.1.0"
description = ""
authors = ["kimocoder <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1 change: 0 additions & 1 deletion wifite/attack/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class AttackAll(object):

@classmethod
def attack_multiple(cls, targets):
"""
Expand Down
2 changes: 0 additions & 2 deletions wifite/attack/pmkid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from ..util.timer import Timer
from ..model.pmkid_result import CrackResultPMKID
from ..tools.airodump import Airodump

from threading import Thread
import os
import time
Expand All @@ -17,7 +16,6 @@


class AttackPMKID(Attack):

def __init__(self, target):
super(AttackPMKID, self).__init__(target)
self.crack_result = None
Expand Down
2 changes: 0 additions & 2 deletions wifite/attack/wpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ..util.timer import Timer
from ..model.handshake import Handshake
from ..model.wpa_result import CrackResultWPA

import time
import os
import re
Expand Down Expand Up @@ -178,7 +177,6 @@ def capture_handshake(self):

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

if handshake is None:
# No handshake, attack failed.
Expand Down
1 change: 0 additions & 1 deletion wifite/attack/wps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class AttackWPS(Attack):

@staticmethod
def can_attack_wps():
return Reaver.exists() or Bully.exists()
Expand Down
4 changes: 2 additions & 2 deletions wifite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import os
import re

from .util.color import Color
from .tools.macchanger import Macchanger

Expand Down Expand Up @@ -37,7 +36,7 @@ class Configuration(object):
min_power = None
no_deauth = None
no_wps = None
no_nullpin = None
wps_no_nullpin = None
num_deauths = None
pmkid_timeout = None
print_stack_traces = None
Expand Down Expand Up @@ -630,6 +629,7 @@ def delete_temp(cls):
@classmethod
def exit_gracefully(cls, code=0):
""" Deletes temp and exist with the given code """
code = 0
cls.delete_temp()
Macchanger.reset_if_changed()
from .tools.airmon import Airmon
Expand Down
2 changes: 1 addition & 1 deletion wifite/util/crack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import os
from json import loads

from ..config import Configuration
from ..model.handshake import Handshake
from ..model.pmkid_result import CrackResultPMKID
Expand Down Expand Up @@ -256,6 +255,7 @@ def crack(cls, hs, tool):
@classmethod
def crack_4way(cls, hs, tool):

global key
handshake = Handshake(hs['filename'],
bssid=hs['bssid'],
essid=hs['essid'])
Expand Down
62 changes: 31 additions & 31 deletions wifite/util/process.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import contextlib
import time
import signal
import os

from subprocess import Popen, PIPE

from ..util.color import Color
from ..config import Configuration

Expand Down Expand Up @@ -97,11 +96,9 @@ def __del__(self):
Ran when object is GC'd.
If process is still running at this point, it should die.
"""
try:
with contextlib.suppress(AttributeError):
if self.pid and self.pid.poll() is None:
self.interrupt()
except AttributeError:
pass

def stdout(self):
""" Waits for process to finish, returns stdout output """
Expand Down Expand Up @@ -160,37 +157,40 @@ def interrupt(self, wait_time=2.0):
If process fails to exit within `wait_time` seconds, terminates it.
"""
try:
pid = self.pid.pid
cmd = self.command
if type(cmd) is list:
cmd = ' '.join(cmd)

if Configuration.verbose > 1:
Color.pe('\n {C}[?] {W} sending interrupt to PID %d (%s)' % (pid, cmd))

os.kill(pid, signal.SIGINT)

start_time = time.time() # Time since Interrupt was sent
while self.pid.poll() is None:
# Process is still running
try:
time.sleep(0.1)
if time.time() - start_time > wait_time:
# We waited too long for process to die, terminate it.
if Configuration.verbose > 1:
Color.pe('\n {C}[?] {W} Waited > %0.2f seconds for process to die, killing it' % wait_time)
os.kill(pid, signal.SIGTERM)
self.pid.terminate()
break
except KeyboardInterrupt:
# wait the cleanup
continue

self._extracted_from_interrupt_7(wait_time)
except OSError as e:
if 'No such process' in e.__str__():
return
raise e # process cannot be killed

# TODO Rename this here and in `interrupt`
def _extracted_from_interrupt_7(self, wait_time):
pid = self.pid.pid
cmd = self.command
if type(cmd) is list:
cmd = ' '.join(cmd)

if Configuration.verbose > 1:
Color.pe('\n {C}[?] {W} sending interrupt to PID %d (%s)' % (pid, cmd))

os.kill(pid, signal.SIGINT)

start_time = time.time() # Time since Interrupt was sent
while self.pid.poll() is None:
# Process is still running
try:
time.sleep(0.1)
if time.time() - start_time > wait_time:
# We waited too long for process to die, terminate it.
if Configuration.verbose > 1:
Color.pe('\n {C}[?] {W} Waited > %0.2f seconds for process to die, killing it' % wait_time)
os.kill(pid, signal.SIGTERM)
self.pid.terminate()
break
except KeyboardInterrupt:
# wait the cleanup
continue


if __name__ == '__main__':
Configuration.initialize(False)
Expand Down
22 changes: 13 additions & 9 deletions wifite/util/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,22 @@ def find_targets(self):
sleep(1)

except KeyboardInterrupt:
if not Configuration.infinite_mode:
return True
return self._extracted_from_find_targets_50()

options = '({G}s{W}{D}, {W}{R}e{W})'
prompt = '{+} Do you want to {G}start attacking{W} or {R}exit{W}%s?' % options
# TODO Rename this here and in `find_targets`
def _extracted_from_find_targets_50(self):
if not Configuration.infinite_mode:
return True

self.print_targets()
Color.clear_entire_line()
Color.p(prompt)
answer = input().lower()
options = '({G}s{W}{D}, {W}{R}e{W})'
prompt = '{+} Do you want to {G}start attacking{W} or {R}exit{W}%s?' % options

self.print_targets()
Color.clear_entire_line()
Color.p(prompt)
answer = input().lower()

return not answer.startswith('e')
return not answer.startswith('e')

def update_targets(self):
"""
Expand Down

0 comments on commit 857eb5b

Please sign in to comment.