python里面加载js代码

第一组-请求加密
有一段js代码

const CryptoJS = require("crypto-js")

function l(t, e) {
    return t.toString().toUpperCase() > e.toString().toUpperCase() ? 1 : t.toString().toUpperCase() == e.toString().toUpperCase() ? 0 : -1
}
function u(t) {
    for (var e = Object.keys(t).sort(l), n = "", a = 0; a < e.length; a++)
        if (void 0 !== t[e[a]])
            if (t[e[a]] && t[e[a]]instanceof Object || t[e[a]]instanceof Array) {
                var i = JSON.stringify(t[e[a]]);
                n += e[a] + i
            } else
                n += e[a] + t[e[a]];
    return n
}

function d(t) {
    for (var e in t)
        "" !== t[e] && void 0 !== t[e] || delete t[e];
    var n = "B3978D054A72A7002063637CCDF6B2E5" + u(t);
    return CryptoJS.MD5(n).toString().toLocaleLowerCase()
}

python 调用

import execjs

# 读文件
js_code = open("1.js").read()
#  execjs.compile运行代码
js_compile = execjs.compile(js_code)

# 参数
json_data = {
    'pageSize': 8,
    'type': '12',
    'ts': 1721372555517,
}

sign = js_compile.call("d", json_data) # 调用d函数,传参数
print(sign)

第二组-响应解密
有一段js代码

const CryptoJS = require("crypto-js")
// 响应解密

function b(t) {
    var e = CryptoJS.enc.Utf8.parse("EB444973714E4A40876CE66BE45D5930")
    , n = CryptoJS.enc.Utf8.parse("B5A8904209931867")
      , a = CryptoJS.AES.decrypt(t, e, {
        iv: n,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
    return a.toString(CryptoJS.enc.Utf8)
}

python

import execjs

js_code = open("2.js").read()
js_compile = execjs.compile(js_code)


t = "MZphJmFlelDpw2aSCfdFb5kX4V2ly++6RL2qxtG4A9KQJfU4oM3z1Lomr9xzGA8QYZJXSx3a2tTElK/blrPo5ZYEea/40BthzQog2dEijtH2MybKVu73bkcBKJZUd2n4OXyqjRkduqSxsMl/8urQVv0227G7eCQ2DLxx+04UjBN//j0qhXn0GP5ualcNryBYUijyYW22/adHzcSyzXby9zxa+FZMaOv1DNlZVgCPgh2TN+cT6xgW0UCpKi6JbvPPz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8sotO78+G3Pwoi91BHfsOJC0D8Yv+KlAy26H5LxLfqw82C7YeHBv2eFaDtgV/JEdOIssWoiz0h3MdvlTNlm2tdoo0eMVA5w36cSis5lwGSNG9Bty3vKx2y9LXDN4yShMg95BKv/fg2hCat+LlwarnTVF1GNJWqeyMizwyMAvqOiLbTPKJ9W2LgK83DrCRQpA8u8w9UJOP3HkGjU63zP97c0Rb3s2+fu0JTISy6OLeOrM6CLCeGf8tTTg7ovLSzfSRAJLro1UXSoK8WAlkl3BzC1vBw/PY8dg6B4ZT6GROvIuKzNy9GsEa3K+XW59R19ZpMJUcsw9k6OB08FG0cm6C4oYScEM5uOCGjchTajhdUQ4PRZaIVFhgMZ1tY4OHeLxwURpD6HQmneG6j/kIxLZOM48AhKXkdbow=="


text = js_compile.call("b", t)
print(text)
posted @ 2024-07-19 15:08  流年中渲染了微笑  阅读(8)  评论(0编辑  收藏  举报