站外
广告
域名申请虚拟主机 文字广告位招租 文字广告位招租 文字广告位招租 企业网络安全 站外
广告
文字广告位招租 文字广告位招租 文字广告位招租 文字广告位招租 期货软件

PHP Web 木马扫描器源码

发布时间:2012-01-18 20:51文章来源:网络文章作者:alibaba 点击次数:
摘要:scanner.php: ?php /**************PHPWeb木马扫描器************************/ /*[+]作者:alibaba*/ /*[+]QQ:1499281192*/ /*[+]MSN:weeming21@hotmail.com*/ /*[+]首发:t00ls.net,转载请注明t00ls*/ /*[+]版本:v1.0*/ /*[+]功能:web版php木马扫描工具*/ /...

scanner.php:

  1. <?php 
  2. /**************PHP Web木马扫描器************************/ 
  3. /* [+] 作者: alibaba */ 
  4. /* [+] QQ: 1499281192 */ 
  5. /* [+] MSN: weeming21@hotmail.com */ 
  6. /* [+] 首发: t00ls.net , 转载请注明t00ls */ 
  7. /* [+] 版本: v1.0 */ 
  8. /* [+] 功能: web版php木马扫描工具*/ 
  9. /* [+] 注意: 扫描出来的文件并不一定就是后门, */ 
  10. /* 请自行判断、审核、对比原文件。*/ 
  11. /* 如果你不确定扫出来的文件是否为后门,*/ 
  12. /* 欢迎你把该文件发给我进行分析。*/ 
  13. /*******************************************************/ 
  14. ob_start(); 
  15. set_time_limit(0); 
  16. $username = "t00ls"//设置用户名 
  17. $password = "t00ls"//设置密码 
  18. $md5 = md5(md5($username).md5($password)); 
  19. $version = "PHP Web木马扫描器v1.0"
  20. $realpath = realpath('./'); 
  21. $selfpath = $_SERVER['PHP_SELF']; 
  22. $selfpath = substr($selfpath, 0, strrpos($selfpath,'/')); 
  23. define('REALPATH'str_replace('//','/',str_replace('\\','/',substr($realpath, 0, strlen($realpath) - strlen($selfpath))))); 
  24. define('MYFILE'basename(__FILE__)); 
  25. define('MYPATH'str_replace('\\', '/', dirname(__FILE__)).'/'); 
  26. define('MYFULLPATH'str_replace('\\', '/', (__FILE__))); 
  27. define('HOST'"http://".$_SERVER['HTTP_HOST']); 
  28. ?> 
  29. <html> 
  30. <head> 
  31. <title><?php echo $version?></title> 
  32. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  33. <style> 
  34. body{margin:0px;} 
  35. body,td{font: 12px Arial,Tahoma;line-height: 16px;} 
  36. a {color: #00f;text-decoration:underline;} 
  37. a:hover{color: #f00;text-decoration:none;} 
  38. .alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;} 
  39. .alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;} 
  40. .focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;} 
  41. .head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;} 
  42. .head td span{font-weight:normal;} 
  43. </style> 
  44. </head> 
  45. <body> 
  46. <?php 
  47. if(!(isset($_COOKIE['t00ls']) && $_COOKIE['t00ls'] == $md5) && !(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5))) 
  48. echo '<form id="frmlogin" name="frmlogin" method="post" action="">用户名: <input type="text" name="username" id="username" /> 密码: <input type="password" name="password" id="password" /> <input type="submit" name="btnLogin" id="btnLogin" value="登陆" /></form>'
  49. elseif(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5)) 
  50. setcookie("t00ls"$md5, time()+60*60*24*365,"/"); 
  51. echo "登陆 www.2cto.com 成功!"
  52. header( 'refresh: 1; url='.MYFILE.'?action=scan' ); 
  53. exit(); 
  54. else 
  55. setcookie("t00ls"$md5, time()+60*60*24*365,"/"); 
  56. $setting = getSetting(); 
  57. $action = isset($_GET['action'])?$_GET['action']:""
  58.  
  59. if($action=="logout"
  60. setcookie ("t00ls""", time() - 3600); 
  61. Header("Location: ".MYFILE); 
  62. exit(); 
  63. if($action=="download" && isset($_GET['file']) && trim($_GET['file'])!=""
  64. $file = $_GET['file']; 
  65. ob_clean(); 
  66. if (@file_exists($file)) { 
  67. header("Content-type: application/octet-stream"); 
  68. header("Content-Disposition: filename=\"".basename($file)."\""); 
  69. echo file_get_contents($file); 
  70. exit(); 
  71. ?> 
  72. <table border="0" cellpadding="0" cellspacing="0" width="100%"
  73. <tbody><tr class="head"
  74. <td><?php echo $_SERVER['SERVER_ADDR']?><span style="float: right; font-weight:bold;"><?php echo "<a href='http://www.t00ls.net/'>$version</a>"?></span></td> 
  75. </tr> 
  76. <tr class="alt1"
  77. <td><span style="float: right;"><?=date("Y-m-d H:i:s",mktime())?></span> 
  78. <a href="?action=scan">扫描</a> | 
  79. <a href="?action=setting">设定</a> | 
  80. <a href="?action=logout">登出</a> 
  81. </td> 
  82. </tr> 
  83. </tbody></table> 
  84. <br> 
  85. <?php 
  86. if($action=="setting"
  87. if(isset($_POST['btnsetting'])) 
  88. $Ssetting = array(); 
  89. $Ssetting['user']=isset($_POST['checkuser'])?$_POST['checkuser']:"php | php? | phtml"
  90. $Ssetting['all']=isset($_POST['checkall'])&&$_POST['checkall']=="on"?1:0; 
  91. $Ssetting['hta']=isset($_POST['checkhta'])&&$_POST['checkhta']=="on"?1:0; 
  92. setcookie("t00ls_s"base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/"); 
  93. echo "设置完成!"
  94. header( 'refresh: 1; url='.MYFILE.'?action=setting' ); 
  95. exit(); 
  96. ?> 
  97. <form name="frmSetting" method="post" action="?action=setting"
  98. <FIELDSET style="width:400px"
  99. <LEGEND>扫描设定</LEGEND> 
  100. <table width="100%" border="0" cellspacing="0" cellpadding="0"
  101. <tr> 
  102. <td width="60">文件后缀:</td> 
  103. <td width="300"><input type="text" name="checkuser" id="checkuser" style="width:300px;" value="<?php echo $setting['user']?>"></td> 
  104. </tr> 
  105. <tr> 
  106. <td><label for="checkall">所有文件</label></td> 
  107. <td><input type="checkbox" name="checkall" id="checkall" <?php if($setting['all']==1) echo "checked"?>></td> 
  108. </tr> 
  109. <tr> 
  110. <td><label for="checkhta">设置文件</label></td> 
  111. <td><input type="checkbox" name="checkhta" id="checkhta" <?php if($setting['hta']==1) echo "checked"?>></td> 
  112. </tr> 
  113. <tr> 
  114. <td>&nbsp;</td> 
  115. <td> 
  116. <input type="submit" name="btnsetting" id="btnsetting" value="提交"
  117. </td> 
  118. </tr> 
  119. </table> 
  120. </fieldset> 
  121. </form> 
  122. <?php 
  123. else 
  124. $dir = isset($_POST['path'])?$_POST['path']:MYPATH; 
  125. $dir = substr($dir,-1)!="/"?$dir."/":$dir
  126. ?> 
  127. <form name="frmScan" method="post" action=""
  128. <table width="100%%" border="0" cellspacing="0" cellpadding="0"
  129. <tr> 
  130. <td width="35" style="vertical-align:middle; padding-left:5px;">扫描路径:</td> 
  131. <td width="690"
  132. <input type="text" name="path" id="path" style="width:600px" value="<?php echo $dir?>"
  133. &nbsp;&nbsp;<input type="submit" name="btnScan" id="btnScan" value="开始扫描"></td> 
  134. </tr> 
  135. </table> 
  136. </form> 
  137. <?php 
  138. if(isset($_POST['btnScan'])) 
  139. $start=mktime(); 
  140. $is_user = array(); 
  141. $is_ext = ""
  142. $list = ""
  143.  
  144. if(trim($setting['user'])!=""
  145. $is_user = explode("|",$setting['user']); 
  146. if(count($is_user)>0) 
  147. foreach($is_user as $key=>$value
  148. $is_user[$key]=trim(str_replace("?","(.)",$value)); 
  149. $is_ext = "(\.".implode("($|\.))|(\.",$is_user)."($|\.))"
  150. if($setting['hta']==1) 
  151. $is_hta=1; 
  152. $is_ext = strlen($is_ext)>0?$is_ext."|":$is_ext
  153. $is_ext.="(^\.htaccess$)"
  154. if($setting['all']==1 || (strlen($is_ext)==0 && $setting['hta']==0)) 
  155. $is_ext="(.+)"
  156.  
  157. $php_code = getCode(); 
  158. if(!is_readable($dir)) 
  159. $dir = MYPATH; 
  160. $count=$scanned=0; 
  161. scan($dir,$is_ext); 
  162. $end=mktime(); 
  163. $spent = ($end - $start); 
  164. ?> 
  165. <div style="padding:10px; background-color:#ccc">扫描: <?php echo $scanned?> 文件| 发现: <?php echo $count?> 可疑文件| 耗时: <?php echo $spent?> 秒</div> 
  166. <table width="100%" border="0" cellspacing="0" cellpadding="0"
  167. <tr class="head"
  168. <td width="15" align="center">No.</td> 
  169. <td width="48%">文件</td> 
  170. <td width="12%">更新时间</td> 
  171. <td width="10%">原因</td> 
  172. <td width="20%">特征</td> 
  173. <td>动作</td> 
  174. </tr> 
  175. <?php echo $list?> 
  176. </table> 
  177. <?php 
  178. ob_flush(); 
  179. ?> 
  180. </body> 
  181. </html> 
  182. <?php 
  183. function scan($path = '.',$is_ext){ 
  184. global $php_code,$count,$scanned,$list
  185. $ignore = array('.''..' ); 
  186. $replace=array(" ","\n","\r","\t"); 
  187. $dh = @opendir( $path ); 
  188. while(false!==($file=readdir($dh))){ 
  189. if( !in_array( $file$ignore ) ){ 
  190. ifis_dir"$path$file" ) ){ 
  191. scan("$path$file/",$is_ext); 
  192. else { 
  193. $current = $path.$file
  194. if(MYFULLPATH==$currentcontinue
  195. if(!preg_match("/$is_ext/i",$file)) continue
  196. if(is_readable($current)) 
  197. $scanned++; 
  198. $content=file_get_contents($current); 
  199. $contentstr_replace($replace,"",$content); 
  200. foreach($php_code as $key => $value
  201. if(preg_match("/$value/i",$content)) 
  202. $count++; 
  203. $j = $count % 2 + 1; 
  204. $filetime = date('Y-m-d H:i:s',filemtime($current)); 
  205. $reason = explode("->",$key); 
  206. $url = str_replace(REALPATH,HOST,$current); 
  207. preg_match("/$value/i",$content,$arr); 
  208. $list.=" 
  209. <tr class='alt$j' onmouseover='this.className=\"focus\";' onmouseout='this.className=\"alt$j\";'
  210. <td>$count</td> 
  211. <td><a href='$url' target='_blank'>$current</a></td> 
  212. <td>$filetime</td> 
  213. <td><font color=red>$reason[0]</font></td> 
  214. <td><font color=#090>$reason[1]</font></td> 
  215. <td><a href='?action=download&file=$current' target='_blank'>下载</a></td> 
  216. </tr>"; 
  217. //echo $key . "-" . $path . $file ."(" . $arr[0] . ")" ."<br />"; 
  218. //echo $path . $file ."<br />"; 
  219. break
  220. closedir$dh ); 
  221. function getSetting() 
  222. $Ssetting = array(); 
  223. if(isset($_COOKIE['t00ls_s'])) 
  224. $Ssetting = unserialize(base64_decode($_COOKIE['t00ls_s'])); 
  225. $Ssetting['user']=isset($Ssetting['user'])?$Ssetting['user']:"php | php? | phtml | shtml"
  226. $Ssetting['all']=isset($Ssetting['all'])?intval($Ssetting['all']):0; 
  227. $Ssetting['hta']=isset($Ssetting['hta'])?intval($Ssetting['hta']):1; 
  228. else 
  229. $Ssetting['user']="php | php? | phtml | shtml"
  230. $Ssetting['all']=0; 
  231. $Ssetting['hta']=1; 
  232. setcookie("t00ls_s"base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/"); 
  233. return $Ssetting
  234. function getCode() 
  235. return array
  236. '后门特征->cha88.cn'=>'cha88\.cn'
  237. '后门特征->c99shell'=>'c99shell'
  238. '后门特征->phpspy'=>'phpspy'
  239. '后门特征->Scanners'=>'Scanners'
  240. '后门特征->cmd.php'=>'cmd\.php'
  241. '后门特征->str_rot13'=>'str_rot13'
  242. '后门特征->webshell'=>'webshell'
  243. '后门特征->EgY_SpIdEr'=>'EgY_SpIdEr'
  244. '后门特征->tools88.com'=>'tools88\.com'
  245. '后门特征->SECFORCE'=>'SECFORCE'
  246. '后门特征->eval("?>'=>'eval\((\'|")\?>'
  247. '可疑代码特征->system('=>'system\('
  248. '可疑代码特征->passthru('=>'passthru\('
  249. '可疑代码特征->shell_exec('=>'shell_exec\('
  250. '可疑代码特征->exec('=>'exec\('
  251. '可疑代码特征->popen('=>'popen\('
  252. '可疑代码特征->proc_open'=>'proc_open'
  253. '可疑代码特征->eval($'=>'eval\((\'|"|\s*)\\$'
  254. '可疑代码特征->assert($'=>'assert\((\'|"|\s*)\\$'
  255. '危险MYSQL代码->returns string soname'=>'returnsstringsoname'
  256. '危险MYSQL代码->into outfile'=>'intooutfile'
  257. '危险MYSQL代码->load_file'=>'select(\s+)(.*)load_file'
  258. '加密后门特征->eval(gzinflate('=>'eval\(gzinflate\('
  259. '加密后门特征->eval(base64_decode('=>'eval\(base64_decode\('
  260. '加密后门特征->eval(gzuncompress('=>'eval\(gzuncompress\('
  261. '加密后门特征->eval(gzdecode('=>'eval\(gzdecode\('
  262. '加密后门特征->eval(str_rot13('=>'eval\(str_rot13\('
  263. '加密后门特征->gzuncompress(base64_decode('=>'gzuncompress\(base64_decode\('
  264. '加密后门特征->base64_decode(gzuncompress('=>'base64_decode\(gzuncompress\('
  265. '一句话后门特征->eval($_'=>'eval\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)'
  266. '一句话后门特征->assert($_'=>'assert\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)'
  267. '一句话后门特征->require($_'=>'require\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)'
  268. '一句话后门特征->require_once($_'=>'require_once\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)'
  269. '一句话后门特征->include($_'=>'include\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)'
  270. '一句话后门特征->include_once($_'=>'include_once\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)'
  271. '一句话后门特征->call_user_func("assert"'=>'call_user_func\(("|\')assert("|\')'
  272. '一句话后门特征->call_user_func($_'=>'call_user_func\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)'
  273. '一句话后门特征->$_POST/GET/REQUEST/COOKIE[?]($_POST/GET/REQUEST/COOKIE[?]'=>'\$_(POST|GET|REQUEST|COOKIE)\[([^\]]+)\]\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)\['
  274. '一句话后门特征->echo(file_get_contents($_POST/GET/REQUEST/COOKIE'=>'echo\(file_get_contents\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)'
  275. '上传后门特征->file_put_contents($_POST/GET/REQUEST/COOKIE,$_POST/GET/REQUEST/COOKIE'=>'file_put_contents\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)\[([^\]]+)\],(\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)'
  276. '上传后门特征->fputs(fopen("?","w"),$_POST/GET/REQUEST/COOKIE['=>'fputs\(fopen\((.+),(\'|")w(\'|")\),(\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)\['
  277. '.htaccess插马特征->SetHandler application/x-httpd-php'=>'SetHandlerapplication\/x-httpd-php'
  278. '.htaccess插马特征->php_value auto_prepend_file'=>'php_valueauto_prepend_file'
  279. '.htaccess插马特征->php_value auto_append_file'=>'php_valueauto_append_file' 
  280. ); 
  281. ?> 


一个在php环境下扫描php木马的工具,目前可扫出以下特征码
特征码:
后门特征->cha88.cn
后门特征->c99shell
后门特征->phpspy
后门特征->Scanners
后门特征->cmd.php
后门特征->str_rot13
后门特征->webshell
后门特征->EgY_SpIdEr
后门特征->tools88.com
后门特征->SECFORCE
后门特征->eval("?>
可疑代码特征->system(
可疑代码特征->passthru(
可疑代码特征->shell_exec(
可疑代码特征->exec(
可疑代码特征->popen(
可疑代码特征->proc_open
可疑代码特征->eval($
可疑代码特征->assert($
危险MYSQL代码->returns string soname
危险MYSQL代码->into outfile
危险MYSQL代码->load_file
加密后门特征->eval(gzinflate(
加密后门特征->eval(base64_decode(
加密后门特征->eval(gzuncompress(
加密后门特征->gzuncompress(base64_decode(
加密后门特征->base64_decode(gzuncompress(
一句话后门特征->eval($_
一句话后门特征->assert($_
一句话后门特征->require($_
一句话后门特征->require_once($_
一句话后门特征->include($_
一句话后门特征->include_once($_
一句话后门特征->call_user_func("assert"
一句话后门特征->call_user_func($_
一句话后门特征->$_POST/GET/REQUEST/COOKIE[?]($_POST/GET/REQUEST/COOKIE[?]
一句话后门特征->echo(file_get_contents($_POST/GET/REQUEST/COOKIE
上传后门特征->file_put_contents($_POST/GET/REQUEST/COOKIE,$_POST/GET/REQUEST/COOKIE
上传后门特征->fputs(fopen("?","w"),$_POST/GET/REQUEST/COOKIE[
.htaccess插马特征->SetHandler application/x-httpd-php
.htaccess插马特征->php_value auto_prepend_file
.htaccess插马特征->php_value auto_append_file
懒惰设计,直接套用phpspy样式


注意: 扫描出来的文件并不一定就是后门, 请自行判断、审核、对比原文件。

标签分类:

上一篇:PHP开发安全规则之过滤用户输入
下一篇:php判断xss攻击