Skip to content

Node.js

Hello World!

//var 定义变量,require 导入模块
var http = require('http')
http.createServer(function(request, response)
{
    //发送 http 头部
    //http 状态值: 200:OK
    //内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end('Hello World!\n');
}).listen(8888);

console.log("Server running at http://127.0.0.1:8888");

Node.js 的缺点

大小写变换

toUpperCase() 将小写字母的字符转换成大写,如果是其他字符,原字符不变
ı 会转换成 I
ſ 会转换成 S
toLowerCase() 将大写字母的字符转换成小写
İ 会转换成 i
会转换成 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
数组比较
空数组比较永远为 false,数组之间只比较第一个值,第一个值与之前比较方法相同
关键字比较
console.log(null==undefined) //true
console.log(null===undefined) //false
console.log(NaN==NaN) //false
console.log(NaN===NaN) //false

md5 绕过

判断条件是 a && b && a.length===b.length && a!==b && md5(a+flag) === md5(b+flag)
a={x:1};b={x:2}; 即可绕过 md5

编码绕过

console.log("a"==="\x61"); //true
console.log("a"==="\u0061"); //true
console.log(Buffer.from("dGVzdA==","base64").toString());
//test
//undefined

危险函数

命令执行

exec()

require('child_process').exec('open /System/Applications/Calculator.app')
//MacOS 环境
变形语句 (RCE bypass)
require('child_process')['exe'%2b'cSync']('open /System/Applications/Calculator.app') //%2b 是加号的 url 编码
require('child_process')['exe'.concat('cSync')]('open /System/Applications/Calculator.app')
同理可以把 execSync 转成 16 进制或 Unicode 编码也可以执行,还有模板拼接的方式,或者可以换一些不常用的函数
eval()
console.log(eval("document.cookie")) //执行 document.cookie
console.log("document.cookie") //输出 "document.cookie"

读写文件

writeFileSync()
require("fs").writeFileSync("input.txt","sss");
writeFile()
require("fs").writeFile("input.txt","test",(err)=>{});
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');