【简单】 猿人学web第一届 第15题 备周则意怠,常见则不疑
数据接口分析
数据接口 https://match.yuanrenxue.cn/api/match/15
请求时需要携带 page 页码,m为加密参数
cookie中没有加密信息,携带 SessionId请求即可
加密参数还原
查看数据接口对应的 requests 栈
m参数 是通过 window.m() 方法执行后得到的
打上断点,查看 window.m() 方法执行了什么
instance = results.instance;
window.q = instance.exports.encode;
window.m = function (){
t1 = parseInt(Date.parse(new Date())/1000/2);
t2 = parseInt(Date.parse(new Date())/1000/2 - Math.floor(Math.random() * (50) + 1));
return window.q(t1, t2).toString() + '|' + t1 + '|' + t2;
};
window.q = instance.exports.encode;
window.q 是请求 wasm 文件编译成的,可以在 python 调用 wasm 文件
# 首先将 wasm 二进制的文件保存到本地
import requests
response = requests.get('https://match.yuanrenxue.cn/static/match/match15/main.wasm').content
open('15.wasm', 'wb').write(response)
调用
def get_m():
t1 = int((int(time.time()) * 1000) / 1000 / 2)
t2 = int((int(time.time()) * 1000) / 1000 / 2 - random.randint(10, 60))
result = pywasm.load('15.wasm')
results = result.exec("encode", [t1, t2])
return f'{results}|{t1}|{t2}'
python 代码
import requests
import pywasm
import random
import time
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
}
cookies = {
"sessionid": "你的sessionId",
}
def get_m():
t1 = int((int(time.time()) * 1000) / 1000 / 2)
t2 = int((int(time.time()) * 1000) / 1000 / 2 - random.randint(10, 60))
result = pywasm.load('15.wasm')
results = result.exec("encode", [t1, t2])
return f'{results}|{t1}|{t2}'
def get_math15(page):
url = "https://match.yuanrenxue.cn/api/match/15"
params = {
"m": get_m(),
"page": f"{page}"
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)
return response.json()['data']
if __name__ == '__main__':
nums = 0
for page_ in range(1, 6):
nums_list = get_math15(page_)
for num in nums_list:
nums += num['value']
print('page: ', page_, 'nums: ', nums)