From 099ca877987c833f75d0abe38a5ecd3a9a91e886 Mon Sep 17 00:00:00 2001 From: Null Date: Wed, 6 Mar 2024 15:26:31 +0800 Subject: [PATCH] [IDS] Add support for slider captcha (#12) --- libxduauth/sites/ids.py | 40 ++++++++++++++++++++++++++++++---------- setup.py | 2 +- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/libxduauth/sites/ids.py b/libxduauth/sites/ids.py index 41d9e18..59bf7bb 100644 --- a/libxduauth/sites/ids.py +++ b/libxduauth/sites/ids.py @@ -6,7 +6,6 @@ from ..AuthSession import AuthSession from ..utils.page import parse_form_hidden_inputs -from ..utils.vcode import _process_vcode from ..utils.aes import encrypt @@ -24,19 +23,40 @@ def __init__( self.cookies.clear() page = self.get( 'http://ids.xidian.edu.cn/authserver/login', - params={'service': target, 'type': 'userNameLogin'} + params={'service': target} ).text - is_need_captcha, vcode = self.get( + is_need_captcha = self.get( 'https://ids.xidian.edu.cn/authserver/checkNeedCaptcha.htl', - params={'username': username, '_': int(time.time() * 1000)} - ).json()['isNeed'], None + params={'username': username, '_': str(int(time.time() * 1000))} + ).json()['isNeed'] if is_need_captcha: captcha = self.get( - 'http://ids.xidian.edu.cn/authserver/getCaptcha.htl', - params={str(int(time.time() * 1000)): ''} + 'https://ids.xidian.edu.cn/authserver/common/openSliderCaptcha.htl', + params={'_': str(int(time.time() * 1000))} ) - _process_vcode(Image.open(BytesIO(captcha.content))).show() - vcode = input('验证码:') + # 返回: { + # 'bigImage': ..., # 背景图(base64) + # 'smallImage': ..., # 滑块图(base64) + # 'tagWidth": 93, # 无用, 恒93 + # 'yHeight': 0 # 无用, 恒0 + # } + img = Image.open(BytesIO(captcha.json()['bigImage'])) + img.show() + # move_len: 背景图左侧到滑块目标位置左侧的宽度 + move_len = input('滑块位移:') + # canvasLength: canvas宽度, 硬编码280 + # moveLength: 按比例缩放后的滑块位移, 有容错 + verify = self.post( + 'https://ids.xidian.edu.cn/authserver/common/verifySliderCaptcha.htl', + data={ + 'canvasLength': '280', + 'moveLength': str(move_len * 280 // img.width) + } + ) + # 返回: { + # 'errorCode': ..., # 验证通过时为1 + # 'errorMsg': ... # 验证通过时为'success' + # } page = BeautifulSoup(page, "lxml") form = page.findChild(attrs={'id': 'pwdFromId'}) params = parse_form_hidden_inputs(form) @@ -47,7 +67,7 @@ def __init__( data=dict(params, **{ 'username': username, 'password': encrypt(password.encode(), enc.encode()), - 'captcha': vcode, + 'captcha': '', 'rememberMe': 'true' }) ) diff --git a/setup.py b/setup.py index ca6fd45..cadf5e9 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="libxduauth", - version="1.7.6", + version="1.8.0", author="Frank", author_email="frankli0324@hotmail.com", description="login utilities for XDU",