How does this kind of javascript obfuscation work?

妖精的绣舞 提交于 2019-12-04 14:11:40

Note that in JavaScript, someobject["xyz"] is about the same as someobject.xyz.

First statement:

_0x4e9d is an array with two strings:

  • "fromCharCode"
  • "write"

Second statement decodes to document.write(String.fromCharCode(0x3c,0x62,...,0x3e)).

Finally, the string being written is this piece of HTML:

<button onclick='javascript:if (document.getElementById("pass").value=="j00w1n"){alert("You WIN!");window.location += "?lvl_password="+document.getElementById("pass").value}else {alert("WRONG! Try again!")}'>Check Password

Each \xnn is a character code as hexadecimal.

So \x63 will give you an 'a'

To do it to your own code you need to have something that will translate each character to it's hex code point:

var aAsHex = '\\x'+'a'.charCodeAt(0).toString(16)

Then copy and paste the output to a file.

var _0x4e9d = ["\x66\x72\x6F\x6D\x43\x68\x61\x72\x43\x6F\x64\x65", "\x77\x72\x69\x74\x65"];

is ["fromCharCode", "write"]

document[_0x4e9d[0x1]](String[_0x4e9d[0x0]]

is document.write(String.fromCharCode

String.fromCharCode(0x3c, 0x62, ...)

Is

<button 
  onclick='javascript:if (document.getElementById("pass").value=="j00w1n"){alert("You WIN!");window.location += "?lvl_password="+document.getElementById("pass").value}else {alert("WRONG! Try again!")}'
>
  Check Password
</button>

The JavaScript in the onclick is

if (document.getElementById("pass").value=="j00w1n") {
  alert("You WIN!");
  window.location += "?lvl_password=" + document.getElementById("pass").value
} else {
  alert("WRONG! Try again!")
}

PHP, assuming $string contains data. So you can obfuscate by running reverse process.

echo preg_replace('~((0|\\\)x([0-9a-f]+))~ei', 'chr(hexdec("\\1"))', $string);

You will get this...

var _�=["fromCharCode","write"];document[_�[]](String[_�[]](<,b,u,t,t,o,n, ,o,n,c,l,i,c,k,=,',j,a,v,a,s,c,r,i,p,t,:,i,f, ,(,d,o,c,u,m,e,n,t,.,g,e,t,E,l,e,m,e,n,t,B,y,I,d,(,",p,a,s,s,",),.,v,a,l,u,e,=,=,",j,0,0,w,1,n,",),{,a,l,e,r,t,(,",Y,o,u, ,W,I,N,!,",),;,w,i,n,d,o,w,.,l,o,c,a,t,i,o,n, ,+,=, ,",?,l,v,l,_,p,a,s,s,w,o,r,d,=,",+,d,o,c,u,m,e,n,t,.,g,e,t,E,l,e,m,e,n,t,B,y,I,d,(,",p,a,s,s,",),.,v,a,l,u,e,},e,l,s,e, ,{,a,l,e,r,t,(,",W,R,O,N,G,!, ,T,r,y, ,a,g,a,i,n,!,",),},',>,C,h,e,c,k, ,P,a,s,s,w,o,r,d,<,/,b,u,t,t,o,n,>));

Actually I have now figured out the real way to obfuscate the javascript like that, without having to make each character separately.

http://javascriptobfuscator.com/default.aspx

This is the obfuscator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!