Explaination of JavaScript "The Da Vinci Code"
Novice security researchers can reach an impasse analyzing the such-like JS-code (it generates an alert):
I would like to remove the veil of secrecy, and explain how it works. It uses several JS-rules:
(É=[Å=[],µ=!Å+Å][µ[È=-~-~++Å]+({}+Å) [Ç=!!Å+µ,ª=Ç[Å]+Ç[+!Å],Å]+ª])() [µ[Å]+µ[Å+Å]+Ç[È]+ª](Å)
I would like to remove the veil of secrecy, and explain how it works. It uses several JS-rules:
- implicit type conversion;
- arrays indexing;
- string and arithmetic operations (unary and binary);
- JSON-based object creation;
- referencing the global object (window) using some functions with invalid or empty parameters;
- accessing properties by bracket notation.
[] //explicit empty array declaration![] //implicit conversion to the Boolean valuefalse[]+![] //implicit conversion to the String valuefalse([]+![])[3] //get a char by index 3sa=[],++a //implicit conversion to the Integer value1([]+![])[a=[],++a] //use several implicit conversion, get a char by index 1a{} //explicit empty object creation via JSON-declaration({}+[]) //implicit conversion tho the String value[object Object]({}+[])[a=[],-~++a] //use several implicit conversion, get a char by index 2bx=[].sort,x() //get window object[object Window](x=[].sort,x())["location"] //access window.location propertyhttp://www.squarefree.com/shell/shell.html
Please notice that getting window object is not a trivial procedure, but there is a good description how it works: (x=[].sort)()===window
Now let's proceed to the analyzing the original sample:
Knowing the variables the mysterious code turns out in the trivial one://setting up variablesÅ=[],µ=!Å+ÅfalseµfalseÈ=-~-~++Å3Å1Ç=!!Å+µtruefalseª=Ç[Å]+Ç[+!Å]rt
µ[Å]+µ[Å+Å]+Ç[È]+ª //one of the expression in the codealert(É=["false"]["sort"])()["alert"](1) //deobfuscated code
As you can see there is no magic here. But it clearly shows that in daedal hands JavaScript can be a dangerous weapon. So be cautious and careful, and no magic can resist your skills!
Comments
Post a Comment