gpt4 book ai didi

javascript - 解码这个奇怪的 Javascript

转载 作者:数据小太阳 更新时间:2023-10-29 05:40:49 27 4
gpt4 key购买 nike

我在 .js 文件中看到了这段代码。这是什么代码??

我已经将该文件下载到我的本地主机网络服务器上。将此代码保存在 .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'))()

最佳答案

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')

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

关于javascript - 解码这个奇怪的 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9045701/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com