Misc JS Tricks & Relevant Info
JavaScript 模糊测试
有效的 JS 注释字符
//This is a 1 line comment
/* This is a multiline comment*/
#!This is a 1 line comment, but "#!" must to be at the beggining of the line
-->This is a 1 line comment, but "-->" must to be at the beggining of the line
for (let j = 0; j < 128; j++) {
for (let k = 0; k < 128; k++) {
for (let l = 0; l < 128; l++) {
if (j == 34 || k ==34 || l ==34)
continue;
if (j == 0x0a || k ==0x0a || l ==0x0a)
continue;
if (j == 0x0d || k ==0x0d || l ==0x0d)
continue;
if (j == 0x3c || k ==0x3c || l ==0x3c)
continue;
if (
(j == 47 && k == 47)
||(k == 47 && l == 47)
)
continue;
try {
var cmd = String.fromCharCode(j) + String.fromCharCode(k) + String.fromCharCode(l) + 'a.orange.ctf"';
eval(cmd);
} catch(e) {
var err = e.toString().split('\n')[0].split(':')[0];
if (err === 'SyntaxError' || err === "ReferenceError")
continue
err = e.toString().split('\n')[0]
}
console.log(err,cmd);
}
}
}
//From: https://balsn.tw/ctf_writeup/20191012-hitconctfquals/#bounty-pl33z
// From: Heyes, Gareth. JavaScript for hackers: Learn to think like a hacker (p. 43). Kindle Edition.
log=[];
for(let i=0;i<=0xff;i++){
for(let j=0;j<=0xfff;j++){
try {
eval(`${String.fromCodePoint(i,j)}%$£234$`)
log.push([i,j])
}catch(e){}
}
}
console.log(log)//[35,33],[47,47]有效的JS换行字符
- New Line
- Carriage Return
\u2028- Line Separator\u2029- Paragraph Separator
函数调用中有效的JS空格
有效JS空格在函数调用中
生成字符串的有效字符
代理对 BF
这种技术对于 XSS 不太有用,但可能对绕过 WAF 保护有用。这段 Python 代码接收 2 个字节作为输入,并搜索具有第一个字节作为高代理对的最后字节和最后一个字节作为低代理对的最后字节的代理对。
更多信息:
javascript{}: 协议模糊化
javascript{}: 协议模糊化URL Fuzzing
URL模糊测试
HTML模糊测试
分析属性
工具Hackability inspector来自Portswigger可帮助分析javascript对象的属性。检查:https://portswigger-labs.net/hackability/inspector/?input=x.contentWindow&html=%3Ciframe%20src=//subdomain1.portswigger-labs.net%20id=x%3E
.map js文件
您可以使用此工具分析这些文件https://github.com/paazmaya/shuji
"--" 赋值
递减运算符--也是一种赋值。此运算符接受一个值,然后将其减一。如果该值不是数字,则将其设置为NaN。这可用于从环境中删除变量的内容。


函数技巧
.call 和 .apply
函数的**.call方法用于运行函数**。
默认情况下,它期望的第一个参数是**this的值**,如果未提供任何值,则**window将成为该值(除非使用strict mode**)。
箭头函数
箭头函数允许您更轻松地在一行中生成函数(如果您理解它们的话)
因此,大多数先前的函数实际上是无用的,因为我们没有将它们保存在任何地方以便调用。例如创建plusone函数:
绑定函数
绑定函数允许创建一个修改this对象和给定参数的函数的副本**。
函数代码泄漏
如果你可以访问函数的对象,你就可以获取该函数的代码。
在某些情况下,函数没有名称,你仍然可以从内部打印函数代码:
一些随机的方法来从另一个函数中提取函数的代码(甚至包括注释):
逃逸沙盒 - 恢复 window 对象
Window 对象允许访问全局定义的函数,如 alert 或 eval。
```javascript // Some ways to access window window.eval("alert(1)") frames globalThis parent self top //If inside a frame, this is top most window
// Access window from document document.defaultView.alert(1) // Access document from a node object node = document.createElement('div') node.ownerDocument.defaultView.alert(1)
// There is a path property on each error event whose last element is the window // In other browsers the method is
// In case of svg, the "event" object is called "evt"
// Abusing Error.prepareStackTrace to get Window back Error.prepareStackTrace=function(error, callSites){ 2 callSites.shift().getThis().alert(1337); 3 }; 4 new Error().stack
// From an HTML event // Events from HTML are executed in this context with(document) { with(element) { //executed event } } // Because of that with(document) it's possible to access properties of document like: <img src onerror=s=createElement('script');s.append('alert(1337)');appendChild(s)>
自动浏览器访问以测试有效载荷
最后更新于