网站地图    收藏   

主页 > php专栏 > php应用 >

php webshell扫描后门木马实例程序 - php高级应用

来源:自学PHP网    时间:2014-11-27 22:16 作者: 阅读:

[导读] 本文章来给大家介绍一个php webshell扫描后门木马实例程序,这个可以扫描你网站上的木马程序,这个给大家找网站木马提供了很大的方便.php webshell扫描后门木马实例程序代码如下:?php/****...

php webshell扫描后门木马实例程序

本文章来给大家介绍一个php webshell扫描后门木马实例程序,这个可以扫描你网站上的木马程序,这个给大家找网站木马提供了很大的方便.

php webshell扫描后门木马实例程序代码如下:

  1. <?php 
  2. /********************** 
  3.   php扫描后门 
  4. **********************/ 
  5. error_reporting(E_ERROR); 
  6. ini_set('max_execution_time',20000); 
  7. ini_set('memory_limit','512M'); 
  8. header("content-Type: text/html; charset=gb2312"); 
  9. $matches = array
  10.   '/function\_exists\s*\(\s*[\'|\"](popen|exec|proc\_open|system|passthru)+[\'|\"]\s*\)/i', 
  11.   '/(exec|shell\_exec|system|passthru)+\s*\(\s*\$\_(\w+)\[(.*)\]\s*\)/i'
  12.   '/((udp|tcp)\:\/\/(.*)\;)+/i'
  13.   '/preg\_replace\s*\((.*)\/e(.*)\,\s*\$\_(.*)\,(.*)\)/i'
  14.   '/preg\_replace\s*\((.*)\(base64\_decode\(\$/i'
  15.   '/(eval|assert|include|require|include\_once|require\_once)+\s*\(\s*(base64\_decode|str\_rot13|gz(\w+)|file\_(\w+)\_contents|(.*)php\:\/\/input)+/i'
  16.   '/(eval|assert|include|require|include\_once|require\_once|array\_map|array\_walk)+\s*\(\s*\$\_(GET|POST|REQUEST|COOKIE|SERVER|SESSION)+\[(.*)\]\s*\)/i'
  17.   '/eval\s*\(\s*\(\s*\$\$(\w+)/i'
  18.   '/(include|require|include\_once|require\_once)+\s*\(\s*[\'|\"](\w+)\.(jpg|gif|ico|bmp|png|txt|zip|rar|htm|css|js)+[\'|\"]\s*\)/i', 
  19.   '/\$\_(\w+)(.*)(eval|assert|include|require|include\_once|require\_once)+\s*\(\s*\$(\w+)\s*\)/i'
  20.   '/\(\s*\$\_FILES\[(.*)\]\[(.*)\]\s*\,\s*\$\_(GET|POST|REQUEST|FILES)+\[(.*)\]\[(.*)\]\s*\)/i'
  21.   '/(fopen|fwrite|fputs|file\_put\_contents)+\s*\((.*)\$\_(GET|POST|REQUEST|COOKIE|SERVER)+\[(.*)\](.*)\)/i'
  22.   '/echo\s*curl\_exec\s*\(\s*\$(\w+)\s*\)/i'
  23.   '/new com\s*\(\s*[\'|\"]shell(.*)[\'|\"]\s*\)/i', 
  24.   '/\$(.*)\s*\((.*)\/e(.*)\,\s*\$\_(.*)\,(.*)\)/i'
  25.   '/\$\_\=(.*)\$\_/i'
  26.   '/\$\_(GET|POST|REQUEST|COOKIE|SERVER)+\[(.*)\]\(\s*\$(.*)\)/i'
  27.   '/\$(\w+)\s*\(\s*\$\_(GET|POST|REQUEST|COOKIE|SERVER)+\[(.*)\]\s*\)/i'
  28.   '/\$(\w+)\(\$\{(.*)\}/i' 
  29. ); 
  30. function antivirus($dir,$exs,$matches) { 
  31.   if(($handle = @opendir($dir)) == NULL) return false; 
  32.   while(false !== ($name = readdir($handle))) { 
  33.     if($name == '.' || $name == '..'continue
  34.     $path = $dir.$name
  35.     if(is_dir($path)) { 
  36.       if(is_readable($path)) antivirus($path.'/',$exs,$matches); 
  37.     } elseif(strpos($name,';') > -1 || strpos($name,'%00') > -1 || strpos($name,'/') > -1) { 
  38.       echo '<p>特征 <input type="text" style="width:218px;" value="解析漏洞"> '.$path.'</p>'flush(); ob_flush(); 
  39.     } else { 
  40.       if(!preg_match($exs,$name)) continue
  41.       if(filesize($path) > 10000000) continue
  42.       $fp = fopen($path,'r'); 
  43.       $code = fread($fp,filesize($path)); 
  44.       fclose($fp); 
  45.       if(emptyempty($code)) continue
  46.       foreach($matches as $matche) { 
  47.         $array = array(); 
  48.         preg_match($matche,$code,$array); 
  49.         if(!$arraycontinue
  50.         if(strpos($array[0],"\x24\x74\x68\x69\x73\x2d\x3e")) continue
  51.         $len = strlen($array[0]); 
  52.         if($len > 10 && $len < 1500) { 
  53.           echo '<p>特征 <input type="text" style="width:218px;" value="'.htmlspecialchars($array[0]).'"> '.$path.'</p>'
  54.           flush(); ob_flush(); break
  55.         } 
  56.       } 
  57.       unset($code,$array); 
  58.     } 
  59.   } 
  60.   closedir($handle); 
  61.   return true; 
  62. function strdir($str) { return str_replace(array('\\','//','//'),array('/','/','/'),chop($str)); } 
  63. echo '<form method="POST">'
  64. echo '<p>路径: <input type="text" name="dir" value="'.($_POST['dir'] ? strdir($_POST['dir'].'/') : strdir($_SERVER['DOCUMENT_ROOT'].'/')).'" style="width:398px;"></p>'
  65. echo '<p>后缀: <input type="text" name="exs" value="'.($_POST['exs'] ? $_POST['exs'] : '.php|.inc|.phtml').'" style="width:398px;"></p>'
  66. echo '<p>操作: <input type="submit" style="width:80px;" value="scan"></p>'
  67. echo '</form>'
  68. if(file_exists($_POST['dir']) && $_POST['exs']) { 
  69.   $dir = strdir($_POST['dir'].'/'); 
  70.   $exs = '/('.str_replace('.','\\.',$_POST['exs']).')/i'
  71.   echo antivirus($dir,$exs,$matches) ? '<p>扫描完毕</p>' : '<p>扫描中断</p>'
  72. }//开源代码phpfensi.com 
  73. ?> 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论