Misc JS Tricks & Relevant Info
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Javascript Fuzzing
Valid JS Comment Chars
//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]Valid JS New Lines Chars
Valid JS Spaces in function call
Valid chars to Generate Strings
Surrogate Pairs BF
This technique won't be very useful for XSS but it could be useful to bypass WAF protections. This python code receive as input 2bytes and it search a surrogate pairs that have the first byte as the the last bytes of the High surrogate pair and the the last byte as the last byte of the low surrogate pair.
More info:
javascript{}: Protocol Fuzzing
javascript{}: Protocol FuzzingURL Fuzzing
HTML Fuzzing
Analizing attributtes
The tool Hackability inspector from Portswigger helps to analyze the attributtes of a javascript object. Check: https://portswigger-labs.net/hackability/inspector/?input=x.contentWindow&html=%3Ciframe%20src=//subdomain1.portswigger-labs.net%20id=x%3E
.map js files
Trick to download .map js files: https://medium.com/@bitthebyte/javascript-for-bug-bounty-hunters-part-2-f82164917e7
You can use this tool to analyze these files https://github.com/paazmaya/shuji
"--" Assignment
The decrement operator -- is also an asignment. This operator takes a value and then decrements it by one. If that value is not a number, it will be set to NaN. This can be used to remove the content of variables from the environment.


Functions Tricks
.call and .apply
The .call method of a function is used to run the function.
The first argument it expects by default is the value of this and if nothing is provided, window will be that value (unless strict mode is used).
Arrow functions
Arrow functions allow you to generate functions in a single line more easily (if you understand them)
So, most of the previous functions are actually useless because we aren't saving them anywhere to save and call them. Example creating the plusone function:
Bind function
The bind function allow to create a copy of a function modifying the this object and the parameters given.
Function code leak
If you can access the object of a function you can get the code of that function
In cases where the function doesn't have any name, you can still print the function code from within:
Some random ways to extract the code of a function (even comments) from another function:
Sandbox Escape - Recovering window object
The Window object allows to reach globally defined functions like alert or eval.
Breakpoint on access to value
Automatic Browser Access to test payloads
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Last updated