-
Notifications
You must be signed in to change notification settings - Fork 5
/
deauthalyzer.py
138 lines (114 loc) · 5.29 KB
/
deauthalyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import subprocess
import psutil
import argparse
import signal
import sys
import time
import datetime
import threading
from termcolor import colored
print("\n")
print(colored(" ▄████▀▀█▄", 'green'))
print(colored(" ▄█████████████████▄▄▄", 'green'))
print(colored(" ▄█████.▼.▼.▼.▼.▼.▼▼▼▼", 'green'))
print(" ▒█ ▀▀▄ █▀▀ █▀▀█ █░░█ ▀▀█▀▀ █░░█ █▀▀█ █░░ █░░█ ▀▀█ █▀▀ █▀▀█ ")
print(" ▒█░▒ █ █▀▀ █▄▄█ █░░█ ░░█░░ █▀▀█ █▄▄█ █░░ █▄▄█ ▄▀░ █▀▀ █▄▄▀ ")
print(" █▄▄▀▀ ▀▀▀ ▀░░▀ ░▀▀▀ ░░▀░░ ▀░░▀ ▀░░▀ ▀▀▀ ▄▄▄█ ▀▀▀ ▀▀▀ ▀░▀▀")
print(colored(" ███████▄.▲.▲.▲.▲▲▲▲▲▲", 'green'))
print(colored(" ██████████████████▀▀▀ (v1)\n", 'green'))
print(" A tool to monitor and log Wifi-Deauthentication attacks")
print(" ~By: Pranjal Goel (z0m31en7) ")
def check_root_privileges():
if not subprocess.check_output(['id', '-u']).decode().strip() == '0':
print(colored('\n[x] Need higher privileges, run as root!!!', 'red'))
sys.exit()
def get_wifi_interfaces():
interfaces = psutil.net_if_addrs()
wifi_interfaces = []
for interface, addresses in interfaces.items():
if interface.startswith('wl'):
wifi_interfaces.append(interface)
return wifi_interfaces
def enable_monitor_mode(interface, stealth_mode):
subprocess.run(['sudo', 'airmon-ng', 'check', 'kill'])
command = ['sudo', 'airmon-ng', 'start', interface]
if stealth_mode:
command.append('1')
subprocess.run(command)
def extract_mac_address(line):
mac_index = line.find('SA:') + 4
mac_address = line[mac_index:mac_index + 17]
return mac_address
def animate_loading():
while True:
for symbol in '|/-\\':
sys.stdout.write(f'\r{colored("[+] Monitoring deauth packets...", "yellow")} {symbol}')
sys.stdout.flush()
time.sleep(0.1)
def detect_deauth_attack(interface, stealth_mode):
enable_monitor_mode(interface, stealth_mode)
monitor_interface = f'{interface}mon'
print(f'{colored("[+] Monitor mode enabled for interface", "green")} {colored(monitor_interface, "cyan")}.')
command = ['tshark', '-i', monitor_interface, '-Y', 'wlan.fc.type_subtype == 0x0c']
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
def signal_handler(sig, frame):
print('\nExiting...')
disable_monitor_mode(interface)
process.terminate()
sys.exit()
signal.signal(signal.SIGINT, signal_handler)
loading_thread = threading.Thread(target=animate_loading)
loading_thread.daemon = True
loading_thread.start()
try:
for line in process.stdout:
line = line.decode().strip()
if line.startswith('Radio tap'):
loading_thread.join()
print(f'\n{colored("[!] Deauthentication attack detected!", "red")}')
print(colored(line, "cyan"))
mac_address = extract_mac_address(line)
print(f'{colored("Source MAC address:", "green")} {colored(mac_address, "yellow")}')
attack_details = [line, f'Source MAC address: {mac_address}']
write_attack_details(attack_details)
for _ in range(4):
next_line = process.stdout.readline().decode().strip()
print(next_line)
attack_details.append(next_line)
write_attack_details(attack_details)
break
except KeyboardInterrupt:
print('\nExiting...')
finally:
disable_monitor_mode(interface)
process.terminate()
def disable_monitor_mode(interface):
subprocess.run(['sudo', 'airmon-ng', 'stop', interface])
def write_attack_details(details):
now = datetime.datetime.now()
filename = f"deauthlog_{now.strftime('%Y%m%d%H%M%S')}.txt"
with open(filename, 'a') as file:
for detail in details:
file.write(detail + '\n')
parser = argparse.ArgumentParser(description='Detect WiFi deauthentication attacks.')
parser.add_argument('-m', '--mode', dest='stealth', action='store_true', help='Enable stealth mode')
args = parser.parse_args()
# Check root privileges
check_root_privileges()
wifi_interfaces = get_wifi_interfaces()
if not wifi_interfaces:
print(colored('\n[x] No wireless interfaces found.', 'red'))
sys.exit()
print(colored('[!] Available WiFi interfaces:', 'green'))
for i, interface in enumerate(wifi_interfaces, 1):
print(f'{i}. {interface}')
interface_num = input('Enter the number corresponding to the interface to use for monitor mode: ')
try:
interface_num = int(interface_num)
if interface_num < 1 or interface_num > len(wifi_interfaces):
raise ValueError
except ValueError:
print(colored('Invalid input. Exiting...', 'red'))
sys.exit()
selected_interface = wifi_interfaces[interface_num - 1]
detect_deauth_attack(selected_interface, args.stealth)