js滑动轨迹验证破解
为什么显示验证错误啊?
""" 滑动验证的请求:snapshot_payload
appCode: "register_pc"
cs: "pc"
data: "px6LLusyhXNArORTkCYroqsg80qEHQIsmZMGOtaGHZBEVRKwF" (未知,每次会变)
orca: 2
经分析,data是获取滑动信息sliderInfo,通过Aes对称加密得到的结果
滑动轨迹信息组成:"56345;205.00;377.00;1.00",时间戳的后五位(精确到毫秒);滑块x轴坐标;滑块y轴坐标;滑动的距离
"""
""" 滑动信息
sliderInfo = {
"openTime":1724853055305,
"startTime":1724853056261,
"endTime":1724853056851,
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36","uid":"0000ec00306c642d6db011ce",
"track":[
"56345;205.00;377.00;1.00",
"56386;244.00;385.00;40.00",
"56466;334.00;391.00;130.00",
"56566;437.00;393.00;233.00",
"56586;456.00;391.00;252.00",
"56626;482.00;389.00;278.00",
"56726;568.00;384.00;364.00",
"56746;581.00;384.00;377.00",
"56807;616.00;384.00;412.00",
"56848;635.00;384.00;431.00"
],
"acc":[],
"ori":[],
"deviceMotion":[
{"isTrusted":True},
{"isTrusted":True},
{"isTrusted":True},
{"isTrusted":True},
{"isTrusted":True},
{"isTrusted":True},
{"isTrusted":True},
{"isTrusted":True},
{"isTrusted":True}
]
}
"""
import json
import time
import random
import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import requests
from jsonpath import jsonpath
"""获取(滑动信息sliderInfo里面的)uid"""
session = requests.session()
def get_uid():
response = session.get('https://user.qunar.com/passport/login.jsp')
cookie = response.cookies
uid = cookie['QN1']
return uid
"""模拟生成浏览器(滑动信息sliderInfo里面的)轨迹信息"""
def get_track(st): # st为开始滑动的时间
x, y = 200, 300 # 定义X轴Y轴起始位置
width = random.randint(430, 440) # 定义滑动的总宽度
track = ['{};200.00;300.00;0.00'.format(str(st)[-5:])] # 保存轨迹信息的列表
s = 0 # 滑动的长度
while s < width:
st = st + random.randint(20, 40) # 随机生成时间戳
s = s + random.randint(10, 50) # 随机生成滑动的距离
x = x + s
if s > width:
s = width
track.append('{};{:.2f};{:.2f};{:.2f}'.format(str(st)[-5:], x, y, s))
"""获取滑动信息sliderInfo"""
def get_sliderInfo():
ot = int(time.time() * 1000)
st = ot + random.randint(1000, 3000) # 打开后1s到3s内开始滑动
sliderInfo = {
"openTime": ot,
"startTime": st,
"endTime": int(time.time() * 1000), # 结束的时间自己获取
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"uid": get_uid(),
"track": get_track(st),
"acc": [],
"ori": [],
"deviceMotion": [{"isTrusted": True} for i in range(10, 200)]
}
return sliderInfo
"""定义AES加密函数"""
def aes_encrypt(sliderInfo):
# 将 sliderInfo 转换成 JSON 字符串
data_json = json.dumps(sliderInfo)
# 设置密钥
key = "227V2xYeHTARSh1R".encode('utf-8') # 等价于 b"227V2xYeHTARSh1R"
# 创建 AES 加密器
cipher = AES.new(key, AES.MODE_ECB) # 加密模式使用 ECB 模式
# 对数据进行填充
padded_data = pad(data_json.encode('utf-8'), 16)
# 加密数据
encrypted_data = cipher.encrypt(padded_data)
# 将加密后的数据转换为 base64 编码的字符串,以便进行传输或存储
encrypted_str = base64.b64encode(encrypted_data).decode()
# 打印加密后的结果
return encrypted_str
"""获取滑动验证请求的参数"""
def get_params():
sliderInfo = get_sliderInfo()
encrypted_str = aes_encrypt(sliderInfo)
params = {
"appCode": "register_pc",
"cs": "pc",
"data": encrypted_str,
"orca": 2
}
return params
"""模拟滑动验证的请求"""
def main():
# 1.发送请求模拟滑动验证
params1 = get_params()
response1 = session.post(url='https://vercode.qunar.com/inner/captcha/snapshot', json=params1)
print(response1.json())
slideToken = jsonpath(response1.json(), '$..cst')[0] # 获取滑动的token,加[0]是为了提取出内容,否则展示为列表
print(slideToken)
# 2.发送请求获取手机验证码
mobile = '157********'
params2 = {
"usersource": '',
"source": '',
"ret": '',
"ref": '',
"business": '',
"pid": '',
"originChannel": '',
"activityCode": '',
"origin": '',
"mobile": mobile,
"prenum": "86",
"loginSource:": 1,
"slideToken": slideToken,
"smsType": 0,
"appcode": "register_pc",
"bella": '1683616182042##aa61064fe5832cf99c7129850219a38ebc406ad0',
"captchaType": ''
}
response2 = session.post(url='https://user.qunar.com/weblogin/sendLoginCode', data=params2)
print(response2.json())
# 3.登录
vcode = input('请输入手机验证码:')
params3 = {
"activityCode":"" ,
'appcode': "register_pc",
'business': "",
'captchaType': "",
'loginSource': 1,
'mobile': mobile,
'originChannel': "",
'piccoloT': "login_register_pc",
'pid': "",
'prenum': "86",
'ref': "",
'ret': "",
'slideToken': slideToken,
'source': "",
'type': "3",
'usersource': "",
'vcode': vcode
}
response3 = session.post(url='https://user.qunar.com/weblogin/verifyMobileVcode', json=params3)
print(response3.json())
if __name__ == '__main__':
main()