初学js逆向,遇到个问题,这是js解密部分的代码
const i
=
require(
'crypto'
)
/
/
解密
function T(e) {
return
i.createHash(
"md5"
).update(e).digest()
}
function decrypt_data(e){
let t
=
'xxxx'
let a
=
'xxxx'
if
(!e)
return
null
const o
=
T(t)
, n
=
T(a)
, r
=
i.createDecipheriv(
"aes-128-cbc"
, o, n);
let s
=
r.update(e,
"base64"
,
"utf-8"
);
s
+
=
r.final(
"utf-8"
)
/
/
return
s
+
=
r.final(
"utf-8"
),
/
/
s
console.log(s);
}
decrypt_data(process.argv[
2
]);
我通过python去调用decrypt_data函数进行解密,代码如下
import
execjs
with
open
(
'yd.js'
,mode
=
'r'
,encoding
=
'utf8'
) as f:
jscode
=
f.read()
myjs
=
execjs.
compile
(jscode)
myjs.call(
"decrypt_data"
,encrypted_data)
死活都报错
Exception
in
thread Thread
-
1
:
IndexError:
list
index out of
range
询问gpt得知
JS 中的
Buffer
和加密处理(比如 Node.js 的 crypto 模块)不能被直接在 Python 的 execjs 中正确模拟运行。
execjs 是通过 JS 引擎(比如 Node.js、JScript、QuickJS 等)运行 JS 代码的桥梁,但它:
无法完整模拟 Node.js 原生模块(如 crypto)
所以你那段依赖 require(
'crypto'
) 的 Node.js 加密解密逻辑在 execjs 中根本跑不通
最终 给出了用
import
subprocess
result
=
subprocess.check_output([
'node'
,
'yd.js'
, encrypted_data], encoding
=
'utf-8'
)
print
(result)
在这里,终于得到了正确的输出