2012-01-28 85 views
5

我在.js文件中遇到了这段代码。这是什么代码?解码这个奇怪的Javascript

我已经将该文件下载到我的localhost webserver.Keeping在.js文件中的代码重定向到google.com,当我评论此代码的页面运行完美!

我可以理解,这是为了强制执行页面只能从服务器链接执行!!!

我该如何解码这个js?

[]['\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72']['\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72'](self['\x75\x6e\x65\x73\x63\x61\x70\x65']('%69%66%28%7e%6c%6f%63%61%74%69%6f%6e%2e%70%72%6f%74%6f%63%6f%6c%2e%69%6e%64%65%78%4f%66%28%27%68%74%74%70%3a%27%29%26%26%7e%6c%6f%63%61%74%69%6f%6e%2e%68%6f%73%74%2e%69%6e%64%65%78%4f%66%28%27%74%65%6d%70%6c%61%74%65%2d%68%65%6c%70%2e%63%6f%6d%27%29%29%7b%7d%65%6c%73%65%28%6c%6f%63%61%74%69%6f%6e%2e%68%72%65%66%3d%27%68%74%74%70%3a%2f%2f%77%77%77%2e%67%6f%6f%67%6c%65%2e%63%6f%6d%27%29'))() 

回答

16

Python恰巧使用相同的编码方式,所以我只是把它扔到Python shell中。

>>> '\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72' 
'constructor' 
>>> '\x75\x6e\x65\x73\x63\x61\x70\x65' 
'unescape' 
>>> import urllib 
>>> urllib.unquote('%69%66%28%7e%6c%6f%63%61%74%69%6f%6e%2e%70%72%6f%74%6f%63%6f%6c%2e%69%6e%64%65%78%4f%66%28%27%68%74%74%70%3a%27%29%26%26%7e%6c%6f%63%61%74%69%6f%6e%2e%68%6f%73%74%2e%69%6e%64%65%78%4f%66%28%27%74%65%6d%70%6c%61%74%65%2d%68%65%6c%70%2e%63%6f%6d%27%29%29%7b%7d%65%6c%73%65%28%6c%6f%63%61%74%69%6f%6e%2e%68%72%65%66%3d%27%68%74%74%70%3a%2f%2f%77%77%77%2e%67%6f%6f%67%6c%65%2e%63%6f%6d%27%29') 
"if(~location.protocol.indexOf('http:')&&~location.host.indexOf('template-help.com')){}else(location.href='http://www.google.com')" 

所以这个代码归结为(添加空格为清楚起见):

[]['constructor']['constructor'](
    "if (~location.protocol.indexOf('http:') && 
     ~location.host.indexOf('template-help.com')) 
    {} 
    else 
    (location.href='http://www.google.com')")() 

那么,这实际上? Node.js的救援:

> [].constructor 
[Function: Array] 
> [].constructor.constructor 
[Function: Function] 
> 

所以[]只是一个空数组,[].constructor给我们的数组构造(这是一个Function对象),最后,[].constructor.constructor给我们Function对象的构造。该构造函数接受包含一些代码的字符串,并将其转换为可调用的函数,然后调用它(注意最后的())。因此,这最终只是执行此代码:

if (~location.protocol.indexOf('http:') && 
    ~location.host.indexOf('template-help.com')) 
    {} 
else 
    (location.href='http://www.google.com') 

是啊,如果我写这样的代码,我会混淆呢! ;)

+1

+1很好的解释:) – fozylet 2012-01-28 14:30:04

+0

简洁明了的解释...谢谢!接受! – Sandy505 2012-01-29 08:31:52

+0

@Thomas我如何编码正常的JavaScript代码到这种编码格式? – Sandy505 2012-01-29 08:33:33

3

它是双编码的,首先是%nn个URL样式字符,然后是\ xnn字符串字符。它解码为

[]['constructor']['constructor'](
    self['unescape'](' 
    if(~location.protocol.indexOf('http:')&&~location.host.indexOf('template-help.com')){} 
    else(location.href='http://www.google.com') 
    '))() 

注意引号不再巢解码后正常,而['unescape']已经完成。

5

尝试......

<html> 
<head> 
<script type="text/javascript"> 
var a="[]['\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72']['\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72'](self['\x75\x6e\x65\x73\x63\x61\x70\x65'](" + unescape('%69%66%28%7e%6c%6f%63%61%74%69%6f%6e%2e%70%72%6f%74%6f%63%6f%6c%2e%69%6e%64%65%78%4f%66%28%27%68%74%74%70%3a%27%29%26%26%7e%6c%6f%63%61%74%69%6f%6e%2e%68%6f%73%74%2e%69%6e%64%65%78%4f%66%28%27%74%65%6d%70%6c%61%74%65%2d%68%65%6c%70%2e%63%6f%6d%27%29%29%7b%7d%65%6c%73%65%28%6c%6f%63%61%74%69%6f%6e%2e%68%72%65%66%3d%27%68%74%74%70%3a%2f%2f%77%77%77%2e%67%6f%6f%67%6c%65%2e%63%6f%6d%27%29') + "))()"; 
</script> 
</head> 
<body> 
<input type=button value=click onclick="javascript:alert(a);"> 
</body> 
</html> 

答案,前面已经指出的那样,是...

[]['constructor']['constructor'](self['unescape'](if(~location.protocol.indexOf('http:')&&~location.host.indexOf('template-help.com')){}else(location.href='http://www.google.com')))() 
0

,我发现这个代码,同时下载从版型怪客模板之一。 COM。 我尝试了每一步,但我没有让我的本地/自己的服务器上的网站availbale。然后我认为它可能是一些JS,如果不是闪存。

尝试删除每一个js一个又一个,然后发现他们粘贴这些代码在他们的文件的最后不让你下载页面。 :)

了解我搜索谷歌的代码,发现这个线程。 Gr8文章。

快乐吧!我现在是个黑客。:)

它们粘贴的代码是:

[] [ '\ X63 \ x6f \ x6e \ X73 \ X74 \ X72 \ X75 \ X63 \ X74 \ x6f \ X72']'\ X63 \ x6f \ x6e \ X73 \ X74 \ X72 \ X75 \ X63 \ X74 \ x6f \ X72' ()

和jQuery的^ version.js

0

我想这下一次建议使用URL DECODE 你可以轻松解码那个字符串。

if(~location.protocol.indexOf('http:')&&~location.host.indexOf('template-help.com')){}else(location.href='http://www.google.com') 

这是一种隐藏代码的方法,并检查脚本是否在特定域上运行。如果不在某处重定向它。在这种情况下,google.com

0

您所说的js文件是一段js代码,http://templates.entheosweb.com/用于确保其网页脚本和主题不会从他们的网站被盗取。无论你在哪里获取该文件,都意味着它所包含的主题或文件被从该网站上盗取。

0

它发生一次复制/粘贴或template-help.com

只需删除该条完美运行保存为模板文件。如果我们解码代码,它看起来像这样 -

[]['constructor']['constructor'](
    "if (~location.protocol.indexOf('http:') && 
     ~location.host.indexOf('template-help.com')) 
    {} 
    else 
    (location.href='http://www.google.com')")() 

因此删除它n享受。