PHP / SSH正则表达式脚本/命令从许多文件中删除相同的恶意软件代
我有一种病毒感染了我客户服务器上的数千个文件.
幸运的是,我已经在这个人的服务器上处理了很多其他恶意软件,这个很容易做简单的正则表达式(他把所有的网站放在同一个帐户上:(但我正在和他一起解决这个问题). 基本上,与大多数恶意软件不同,我看到它在关闭之前注入了php?>好的代码(很难确定什么是好代码/坏代码),这个当前的恶意软件总是添加一个新的<?php ...恶意软件......?>. 所以基本上,说这里的代码很好: <?php require('./wp-blog-header.php'); ?> 而不是在require语句之后但在?>之前立即添加某种base64_decode eval. (当页面恰好在条件/复杂语句中结束时,这可能使删除变得困难),这将始终使用NEW<?php ...?>添加以下代码.像这样: <?php require('./wp-blog-header.php'); ?><?php ... malware ...?> 我不想在这里放任何恶意代码,但这就是恶意代码始终启动的方式: <?php @error_reporting(0); if (!isset($eva1fYlbakBcVSir)) {$eva1fYlbakBcVSir = "tons and tons of characters";$eva1tYlbakBcVSir = "x633514433x6f1534x70170x65";$SNIPSNIPSNIPSNIP;} ?> 我想搜索每个文件<?php @error_reporting(0); if(!isset,如果它是页面上的最后一个PHP语句,那么删除内的所有内容 解决方法
以下是使用纯php清理整个项目的方法.
<?php //Enter it as it is and escape any single quotes $find='<?php @error_reporting(0); if (!isset($eva1fYlbakBcVSir)) {$eva1fYlbakBcVSir ='';?>'; 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); $pos = strpos($filesource,$find); if ($pos === false) { continue; } else { //The cleaning bit echo "The string '".htmlentities($find)."' was found in the file '$path/$file and exists at position $pos and has been removed from the source file.<br />"; $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; } ?> 祝好运. 更新(使用正则表达式): <?php error_reporting(E_ALL); $find='<?php @error_reporting(0); if (!isset((.*?)?>'; echo findString('./',-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,$clean_source); }else{ continue; } } } } closedir($handle); } $return = ob_get_contents(); ob_end_clean(); return $return; } ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |