Skip to content

Instantly share code, notes, and snippets.

@msgodf
Created June 1, 2011 09:56
Show Gist options
  • Save msgodf/1002060 to your computer and use it in GitHub Desktop.
Save msgodf/1002060 to your computer and use it in GitHub Desktop.
Code to run arbitrary JavaScript code as a string, using only the characters []$=()-+~""!_
[][$___=(($=(({}+"")))[$__=-~-~-~-~-~[]]+$[-~[]]+(""[+[]]+"")[-~[]]+(![]+"")[-~-~-~[]]+(($_=(!""+"")))[+[]]+$_[-~[]]+$_[-~-~[]]+$[$__]+$_[+[]]+$[-~[]]+$_[-~[]])][$___](($$=($_____=(!""+"")[-~[]]+(!""+"")[-~-~-~[]]+(!""+"")[+[]]+(!""+"")[-~-~[]]+(!""+"")[-~[]]+(""[+[]]+"")[-~[]]
)+"[][$___][$___]('"+$_____+"\"\\"+(""[+[]]+"")[+[]]
+(+[])+(+[]))+($$$=""+(-~-~-~-~[])+(-~[]))+($$$$="\"')()"))()+[][$___][$___]($$+($$$=-~$$$)+$$$$)()+[][$___][$___]($$+($$$=-~$$$)+$$$$)()+[][$___][$___]($$+($$$=-~$$$)+$$$$)()
// The code just constructs the string 'constructor' from the primitives '[object Object]',
// 'true', 'false', and 'undefined' and then uses it to access the Function constructor of
// the built-in Array type
[]['constructor']['constructor']("//Insert arbitrary code here")();
[][$___=(($=(({}+"")))[$__=-~-~-~-~-~[]]+$[-~[]]+(""[+[]]+"")[-~[]]+(![]+"")[-~-~-~[]]+(($_=(!""+"")))[+[]]+$_[-~[]]+$_[-~-~[]]+$[$__]+$_[+[]]+$[-~[]]+$_[-~[]])][$___]("// Insert arbitrary code here")()
[][$___=(($=(({}+"")))[$__=-~-~-~-~-~[]]+$[-~[]]+(""[+[]]+"")[-~[]]+(![]+"")[-~-~-~[]]+(($_=(!""+"")))[+[]]+$_[-~[]]+$_[-~-~[]]+$[$__]+$_[+[]]+$[-~[]]+$_[-~[]])][$___]($_____+(___$=[][$___][$___]("_$_$",($_____=(!""+"")[-~[]]+(!""+"")[-~-~-~[]]+(!""+"")[+[]]+(!""+"")[-~-~[]]+(!""+"")[-~[]]+(""[+[]]+"")[-~[]]
)+'[][$___][$___]($_____+"\'\\\\'+(''[+[]]+'')[+[]]+'"+_$_$+"\';")();'))(""+(+[])+(+[])+(-~-~[])+(+[]))+___$(""+(+[])+(+[])+(-~-~-~[])+(-~-~-~-~[])))()
(___$=[][$___][$___]("_$_$",($_____=(!""+"")[-~[]]+(!""+"")[-~-~-~[]]+(!""+"")[+[]]+(!""+"")[-~-~[]]+(!""+"")[-~[]]+(""[+[]]+"")[-~[]]
)+'[][$___][$___]($_____+"\'\\\\'+(''[+[]]+'')[+[]]+'"+_$_$+"\';")();'))(""+(+[])+(+[])+(-~-~[])+(+[]))
@msgodf
Copy link
Author

msgodf commented Jun 1, 2011

I decided to see if I could write something to execute more arbitrary code than in the original article on Hacker News at http://adamcecc.blogspot.com/2011/01/javascript.html

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