2012-01-28 87 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享受。