接上节课内容
JS逆向 -- 某新闻数据包中sign值加密分析
一、将补环境代码复制到上节课那个js文件里面
const jsdom = require("jsdom");
const { JSDOM } = jsdom;//导入jsdom模块
const html = "<!DOCTYPE html><p>逆向有你</p>";
const resourceLoader = new jsdom.ResourceLoader({
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
});
const dom = new JSDOM(html,{
url: "https://www.toutiao.com",
referrer: "https://www.toutiao.com",
contentType: "text/html",
resources: resourceLoader,
})
window = global
document = dom.window.document
const params = {
location: {
hash: "",
host: "www.toutiao.com",
hostname: "www.toutiao.com",
href: "https://www.toutiao.com",
origin: "https://www.toutiao.com",
pathname: "/",
port: "",
protocol: "https:",
search: "",
},
navigator: {
appCodeName: "Mozilla",
appName: "Netscape",
appVersion: "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
cookieEnabled: true,
deviceMemory: 8,
doNotTrack: null,
hardwareConcurrency: 12,
language: "zh-CN",
languages: ["zh-CN", "zh"],
maxTouchPoints: 0,
onLine: true,
platform: "Win112",
product: "Gecko",
productSub: "20030107",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
vendor: "Google Inc.",
vendorSub: "",
webdriver: false
}
};
Object.assign(global,params)
二、打印我们要的结果
console.log(window.byted_acrawler.sign({'url':'https://www.toutiao.com/toutiaohttps://lf3-config.bytetcc.com/obj/tcc-config-web/tcc-v2-data-toutiao.fe.toutiao_web_pc-common'}))
三、提示报错,找不到sign函数,上面函数中,e参数里面有一个exports导致
四、将该三目运算复制到网站的控制台,结果是undefined,所以直接将该运算替换成void 0
五、重新运行JS代码,成功获取sign值
六、Python代码实现加载数据
1、由于sign函数参数不是固定,为了增加通用性,所以我们继续修改成如下代码
console.log(window.byted_acrawler.sign({'url':process.argv[2]}))
2、调用方式如下,将url地址直接写到后面
3、python代码实现获取sign
import subprocess
url='https://www.toutiao.com/api/pc/list/feed?channel_id=3189398996&max_behot_time=1684844002&offset=0&category=pc_profile_channel&client_extra_params=%7B%22short_video_item%22:%22filter%22%7D&aid=24&app_name=toutiao_web'
sign=subprocess.getoutput('node jiami.js %s' % url)
print(sign)