Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange JavaScript notation, all parenthesis and brackets [duplicate]

Tags:

javascript

So I participated in a Capture The Flag this week and one of the challenges really confused me.

Challenge file (.txt)

Preview:

[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+

This was the file given, it reminded me of this, after playing with it for a bit I entered it into the JavaScript console on my browser and an alert with the flag popped up.

If someone could explain why this works, and how I could create something like this. Also is it simple to translate this into normal looking JavaScript, I just imagine this could be a way for an attacker to execute sketchy code in my browser.

like image 321
jacstrong Avatar asked Feb 24 '26 09:02

jacstrong


1 Answers

i put some link that could be helpful

  • transaltejs (github code) translate string into this pattern

  • explanetion 1, jsfuck

  • explanation 2, JavaScript, the weird parts

the key to do this

  • false => ![]

  • true => !![]

  • undefined => [][[]]

  • NaN => +[![]]

  • 0 => +[]

  • 1 => +!+[]

  • 2 => !+[]+!+[]

  • 10 => [+!+[]]+[+[]]

  • Array => []

  • Number => +[]

  • String => []+[]

  • Boolean => ![]

  • Function => []["filter"]

  • eval => []["filter"]"constructor"()

  • window => []["filter"]"constructor"()

like image 140
Francesco Taioli Avatar answered Feb 26 '26 01:02

Francesco Taioli