Skip to content

Commit

Permalink
support captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
naivekun committed May 1, 2020
1 parent 1289584 commit e4fe4e5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode/
.vscode/
naivekun_test.py
libhustpass/__pycache__
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ __pc1 = [56, 48, 40, 32, 24, 16, 8,

So I modified pyDes.py(from the python library `pyDes`) to sbDes.py

#### changelog

##### 20200501 support captcha

`pass.hust.edu.cn` force user input captcha since 20200501

`captcha.py` uses library [Tesseract](https://tesseract-ocr.github.io/) to auto-fuck captcha

Install Tesseract first !

#### License

WTFPL
51 changes: 51 additions & 0 deletions libhustpass/captcha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from PIL import Image, GifImagePlugin
from pytesseract import image_to_string

def Fuckit(imageContent):
imageObject = Image.open(imageContent)
for frame in range(imageObject.n_frames):
if frame == 1:
imageObject.seek(frame)
binarizedImage = binarizing(imageObject, 255)
depointedImage = depoint(binarizedImage)
code = image_to_string(depointedImage, config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
return code

def binarizing(img,threshold):
img = img.convert("L")
pixdata = img.load()
w, h = img.size
for y in range(h):
for x in range(w):
if pixdata[x, y] < threshold:
pixdata[x, y] = 0
else:
pixdata[x, y] = 255
return img

def depoint(img):
pixdata = img.load()
w,h = img.size
for y in range(1,h-1):
for x in range(1,w-1):
count = 0
if pixdata[x,y-1] > 245:#上
count = count + 1
if pixdata[x,y+1] > 245:#下
count = count + 1
if pixdata[x-1,y] > 245:#左
count = count + 1
if pixdata[x+1,y] > 245:#右
count = count + 1
if pixdata[x-1,y-1] > 245:#左上
count = count + 1
if pixdata[x-1,y+1] > 245:#左下
count = count + 1
if pixdata[x+1,y-1] > 245:#右上
count = count + 1
if pixdata[x+1,y+1] > 245:#右下
count = count + 1
if count > 4:
pixdata[x,y] = 255
return img

5 changes: 5 additions & 0 deletions libhustpass/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import libhustpass.sbDes as sbDes
import libhustpass.captcha as FuckCaptcha
import requests
import re
import random

proxies = {"http": "http://127.0.0.1:8080", "https": "http://127.0.0.1:8080"}

Expand Down Expand Up @@ -53,13 +55,16 @@ def strenc(data, first_key, second_key, third_key):
def doLogin(username, password, url):
r = requests.session()
login_html = r.get(url)
captcha_content = r.get("https://pass.hust.edu.cn/cas/code?"+str(random.random()), stream=True)
captcha_content.raw.decode_content = True
nonce = re.search(
'<input type="hidden" id="lt" name="lt" value="(.*)" />', login_html.text
).group(1)
action = re.search(
'<form id="loginForm" action="(.*)" method="post">', login_html.text
).group(1)
post_params = {
"code": FuckCaptcha.Fuckit(captcha_content.raw),
"rsa": strenc(username + password + nonce, "1", "2", "3"),
"ul": len(username),
"pl": len(password),
Expand Down

0 comments on commit e4fe4e5

Please sign in to comment.