几天前,我发现我被一个恶意脚本入侵,该脚本已在所有index.php文件,config.php和wp -config.php中传播。
我试图获取代码并对其进行修改,以查找包含该脚本的文件夹中的文件并自动将其删除。
不幸的是我没有成功。
代码开始如下:
<?php $J24fj = 'bH1Vrb2sswS7fUn8HyCx.... AND MUCH MORE ?>
这段代码总是在变化,但是里面有一个常量:该文本: ZXZhbChiYXNlNjRfZGVjb2RlKCJaW
我找到了这段代码,如何更改它以搜索常量并删除整行 <?php ******* ?>
<?php
$find='ZXZhbChiYXNlNjRfZGVjb2RlKCJaW';
echo findString('./',$find);
function findString($path,$find){
$return='';
ob_start();
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir($path.'/'.$file)){
$sub=findString($path.'/'.$file,$find);
if(isset($sub)){
echo $sub.PHP_EOL;
}
}else{
$ext=substr(strtolower($file),-3);
if($ext=='php'){
$filesource=file_get_contents($path.'/'.$file);
//The cleaning bit
echo "The string '".htmlentities($find)."' was found in the file '$path/$file and has been removed from the source file.<br />";
$clean_source = preg_replace('#'.$find.'#','',$filesource);
// $clean_source = str_replace($find,'',$filesource);
file_put_contents($path.'/'.$file,$clean_source);
}else{
continue;
}
}
}
}
closedir($handle);
}
$return = ob_get_contents();
ob_end_clean();
return $return;
}
?>
提前致谢
安东尼奥
像这样
preg_replace('/(\ <\?php。+?)(ZXZhbChiYXNlNjRfZGVjb2RlKCJaWZXZhbChiYXNlNjRfZGVjb2RlKCJaW)(。+?\?>)/''',$ filesource);
只要打开和关闭php标签是自包含的,就应该做到这一点,即不包含您希望保留的任何自己的代码。
请注意,preg_replace可以在不将文件内容复制到变量然后将新字符串复制到$ cleansource变量的情况下工作。
另外,在输出表示代码已被替换的字符串之前,应小心进行更改!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句