PHP 网页木马扫描器

/**
 * removeHorse.php by 2012.5.5
 */
set_time_limit(0);
arScan('./', '*.{php,htm,html}', array(
  array(
    '/eval\(.+\)/iUs',
    '/system\(.+\)/iUs'
  ),
  array('', '')
));

//扫描嵌入代码
function arScan($path, $mark, $expr, $i = 0) {
  $files = arGlob($path, $mark);
  foreach($files as $key => $file) {
    if(!$fc = file_get_contents($file)) { continue; }
    $fr = preg_replace($expr[0], $expr[1], $fc, -1, $rs);
    if($rs > 0) {
      #file_put_contents($file, $fc);
      $i++;
    }
    echo "[$rs] {$file} \n";
  }
  echo "共处理文件{$i}个";
}

//获取文件列表
function arGlob($path = './', $mark = '*', $full = false) {
  $files = array();
  if($result = glob($path.$mark, GLOB_MARK|GLOB_BRACE)) {
    $result = str_replace('\\', '/', $result);
    foreach($result as $file) {
      substr($file, -1, 1) == '/' || $files[] = $file;
    }
  }
  if($result = glob($path.'*', GLOB_MARK|GLOB_ONLYDIR)) {
    $result = str_replace('\\', '/', $result);
    foreach($result as $path) {
      $full && $files[] = $path;
      $files = array_merge($files, arGlob($path, $mark, $full));
    }
  }
  return $files;
}
文章作者: 若海; 原文链接: https://www.rehiy.com/post/33/; 转载需声明来自技术写真 - 若海

添加新评论