Skip to content

Instantly share code, notes, and snippets.

@codeimpossible
Created December 30, 2011 01:47
Show Gist options
  • Save codeimpossible/1537211 to your computer and use it in GitHub Desktop.
Save codeimpossible/1537211 to your computer and use it in GitHub Desktop.
get reference to window with obfuscated javascript
$=((([])[(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]]));$()["eval"]("alert(1)")
@codeimpossible
Copy link
Author

this takes advantage of a bug in javascripts implementation of Array.prototype.sort. When you assign the sort function to a global variable and call it with no arguments it will return this, which when called normally on an array would return the current array, but when it's called on the globally scoped variable it returns the window object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment