js逆向实战之weibotop.cn返回数据解密

url:https://www.weibotop.cn/2.0/

分析过程

  1. 打开开发者工具,页面直接进入了debugger模式。
    image
    想要跳过这个debugger模式,可以在debugger这行代码的前面右键,选择never pause here
    image
    重新刷新界面,就不会进入debugger模式了。抓流量包。
    image
    主要关注currentitems,它的响应数据是加密字符串,需要找到其的解密过程。

  2. 由于还是寻找响应数据的解密过程,经过前面两篇文章,立马去搜索interceptors,但是很遗憾,这里没有。
    image
    这个方法行不通,只能搜索url关键字了,只有一条记录。
    image

  3. 定位到该函数,上下文看看,就看到了加密和解密的地方。
    image

  4. 是老朋友了,AES算法,主要需要找到keyivmode,在解密的地方打断点,刷新界面。
    image
    单步调试。
    i = t = String(t),把加密的字符串赋值给i
    o = n.enc.Base64.parse(i),对i进行base64解码,赋值给o
    r = aa在上面有定义,是通过一个固定字符串计算SHA1值之后截取前32位得到,是一个固定值。
    image
    下面就是AES解密,o是需要解密的字符串,r是key,modeECBiv不需要。

n.AES.decrypt({
    ciphertext: o
}, r, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
}).toString(CryptoJS.enc.Utf8)

image

  1. 编写python代码,开始爬取数据,但是这里没成功,经过不断的调试,是python的base64解码和JS中的base64解码的结果不一致导致,暂时没找到解决办法,所以只能采用python调用js代码的方式实现。
var CryptoJS = require("crypto-js");

let s = CryptoJS.SHA1(CryptoJS.enc.Utf8.parse("tSdGtmwh49BcR1irt18mxG41dGsBuGKS"))
          , a = CryptoJS.enc.Hex.parse(s.toString(CryptoJS.enc.Hex).substr(0, 32));

function h(t) {
    let e = (i = t = String(t),
    o = CryptoJS.enc.Base64.parse(i),
    r = a,
    CryptoJS.AES.decrypt({
        ciphertext: o
    }, r, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    }).toString(CryptoJS.enc.Utf8));
    var i, o, r;
    return JSON.parse(e)
}
from functools import partial   # 锁定参数
import subprocess

subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")

import requests
import execjs

url = "https://api.weibotop.cn/currentitems"
resp = requests.get(url, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
                                         "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"})
mi_str = resp.text
# print(mi_str)
file_object = open("解密.js", mode="r")
exec_code = file_object.read()

exec_js = execjs.compile(exec_code)
call = exec_js.call("h", mi_str)
print(call)

运行结果如下:
image
成功获取到数据。

posted @ 2024-04-30 08:54  死不悔改奇男子  阅读(50)  评论(0编辑  收藏  举报