JS混淆与动态Cookie分析
题目链接:https://match.yuanrenxue.cn/match/2
问题背景
这题卡我几天了,虽然知道是通过正则检测格式化代码的问题,但是我自己就是搞不出来,能力不够还得研究。
但是昨天魔改算法的处理方式给了我灵感,我是不是也可以通过那样的方式获取这题cookie的加密参数。
分析思路
因为之前研究过这题,我知道加密参数是m,通过第一次访问网页返回的js代码生成,没有涉及到其他js,所以直接将生成cookie的js代码复制到本地,通过调用js原本的内容尝试将加密参数输出。
且该代码进行了格式化检测,所以压缩代码直接,这样就能直接绕过环境检测的部分了。唯一要做的就是进行浏览器环境的模拟。
基于以上理论,开始对网站进行抓包。
Hook加密参数
对m进行hook
浏览器hook的时候一直出问题,所以就用了fiddler进行了hook。只需要在示例代码中加入红框中的判断条件即可。
定位加密位置
这里我们就hook到了cookie,之后开始跟栈找到其生成的位置。
绕过格式化检测
因为代码中存在格式化检测,所以进行压缩代码
环境补全
运行,开始补环境
报错,给ai解释
本质上是因为调用了setInterval,参数格式不正确导致的错误,下面也给出了绕过的方案,那我就先选择进行绕过吧,出问题了再处理。
TypeError: console.warn is not a function
换成log打印
依旧报错,console中history is not defined
可能是console被重写了,模拟环境开头先保存console。
同时将之前混淆代码中我们调用的console给改了
补充DOM环境
Ok,现在补充document,直接交给ai
成功获取参数
m参数出现,python模拟
代码示例
import requests
import subprocess
import re
def get_m():
result = subprocess.run(
['node', 'js.js'],
text=True,
capture_output=True,
encoding='utf-8'
)
m = re.search('mundefined=(.*?); path=/',result.stdout).group(1)
return m
headers = {}
url = "https://match.yuanrenxue.cn/api/match/2"
lst = []
for page in range(1,6):
params = {
"page": str(page)
}
cookies = {"m": get_m()}
response = requests.get(url, headers=headers, cookies=cookies, params=params)
values = [int(_['value']) for _ in response.json()['data']]
print(f'第{page}页的值为',values)
lst.extend(values)
print(sum(lst))
Console = console
navigator = {}
global.setInterval = new Proxy(setInterval, {
apply(target, thisArg, args) {
if (typeof args[0] !== 'function') {
Console.log('setInterval 被传入了非函数参数,已跳过:', args[0]);
return;
}
return Reflect.apply(target, thisArg, args);
}
});
global.document = {
cookie: '',
createElement: function(tag) {
return {
tagName: tag.toUpperCase(),
style: {},
appendChild: () => {},
setAttribute: () => {},
};
},
body: {
appendChild: () => {},
},
addEventListener: () => {},
};
global.location = {
href: 'https://match.yuanrenxue.com/',
origin: 'https://match.yuanrenxue.com',
};
require('./原版js')

