当前位置:首页 > PHP教程 > php高级应用 > 列表

php网站被挂木马修复方法总结

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-22 11:09:47 浏览: 评论:0 

php网站被挂木马修复是次要的最要的是怎么修复之后不再让木马再注入到你的网站才是重要的,下面我来总结一下php网站被挂木马修复与之后防止网站再次给挂木马的方法.

在linux中我们可以使用命令来搜查木马文件,到代码安装目录执行下面命令:

find ./ -iname "*.php" | xargs grep -H -n "eval(base64_decode"

搜出来接近100条结果,这个结果列表很重要,木马都在里面,要一个一个文件打开验证是否是木马,如果是,马上删除掉,最后找到10个木马文件,存放在各种目录,都是php webshell,功能很齐全,用base64编码.

如果你在windows中查找目录直接使用windows文件搜索就可以了,可以搜索eval或最近修改文件,然后如果是dedecms我们要查看最新dedecms漏洞呀然后修补.

下面给个php木马查找工具,直接放到你站点根目录,代码如下:

  1. <?php 
  2.  
  3. /**************PHP Web木马扫描器************************/ 
  4.  
  5. /* [+] 作者: alibaba */ 
  6.  
  7. /* [+] QQ: 1499281192 * www.phpfensi.com/ 
  8.  
  9. /* [+] MSN: weeming21@hotmail.com */ 
  10.  
  11. /* [+] 首发: t00ls.net , 转载请注明t00ls */ 
  12.  
  13. /* [+] 版本: v1.0 */ 
  14.  
  15. /* [+] 功能: web版php木马扫描工具*/ 
  16.  
  17. /* [+] 注意: 扫描出来的文件并不一定就是后门, */ 
  18.  
  19. /* 请自行判断、审核、对比原文件。*/ 
  20.  
  21. /* 如果你不确定扫出来的文件是否为后门,*/ 
  22.  
  23. /* 欢迎你把该文件发给我进行分析。*/ 
  24.  
  25. /*******************************************************/ 
  26.  
  27. ob_start(); 
  28.  
  29. set_time_limit(0); 
  30.  
  31. $username = "t00ls"; //设置用户名 
  32.  
  33. $password = "t00ls"; //设置密码 
  34.  
  35. $md5 = md5(md5($username).md5($password)); 
  36.  
  37. $version = "PHP Web木马扫描器v1.0"; 
  38.  
  39. PHP Web 木马扫描器 
  40.  
  41. $realpath = realpath('./'); 
  42.  
  43. $selfpath = $_SERVER['PHP_SELF']; 
  44.  
  45. $selfpath = substr($selfpath, 0, strrpos($selfpath,'/')); 
  46.  
  47. define('REALPATH', str_replace('//','/',str_replace('\','/',substr($realpath, 0, strlen($realpath) - strlen($selfpath))))); 
  48.  
  49. define('MYFILE', basename(__FILE__)); 
  50.  
  51. define('MYPATH', str_replace('\', '/', dirname(__FILE__)).'/'); 
  52.  
  53. define('MYFULLPATH', str_replace('\', '/', (__FILE__))); 
  54.  
  55. define('HOST', "http://".$_SERVER['HTTP_HOST']); 
  56.  
  57. ?> 
  58.  
  59. <html> 
  60.  
  61. <head> 
  62.  
  63. <title><?php echo $version?></title> 
  64.  
  65. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  66.  
  67. <style> 
  68.  
  69. body{margin:0px;} 
  70.  
  71. body,td{font: 12px Arial,Tahoma;line-height: 16px;} 
  72.  
  73. a {color: #00f;text-decoration:underline;} 
  74.  
  75. a:hover{color: #f00;text-decoration:none;} 
  76.  
  77. .alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;} 
  78.  
  79. .alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;} 
  80.  
  81. .focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;} 
  82.  
  83. .head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;} 
  84.  
  85. .head td span{font-weight:normal;} 
  86.  
  87. </style> 
  88.  
  89. </head> 
  90.  
  91. <body> 
  92.  
  93. <?php 
  94.  
  95. if(!(isset($_COOKIE['t00ls']) && $_COOKIE['t00ls'] == $md5) && !(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5))) 
  96.  
  97. { 
  98.  
  99. 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>'; 
  100.  
  101. } 
  102.  
  103. elseif(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5)) 
  104.  
  105. { 
  106.  
  107. setcookie("t00ls", $md5, time()+60*60*24*365,"/"); 
  108.  
  109. echo "登陆成功!"; 
  110.  
  111. header( 'refresh: 1; url='.MYFILE.'?action=scan' ); 
  112.  
  113. exit(); 
  114.  
  115. } 
  116.  
  117. else 
  118.  
  119. { 
  120.  
  121. setcookie("t00ls", $md5, time()+60*60*24*365,"/"); 
  122.  
  123. $setting = getSetting(); 
  124.  
  125. $action = isset($_GET['action'])?$_GET['action']:""; 
  126.  
  127.   
  128.  
  129. if($action=="logout") 
  130.  
  131. { 
  132.  
  133. setcookie ("t00ls", "", time() - 3600); 
  134.  
  135. Header("Location: ".MYFILE); 
  136.  
  137. exit(); 
  138.  
  139. } 
  140.  
  141. if($action=="download" && isset($_GET['file']) && trim($_GET['file'])!="") 
  142.  
  143. { 
  144.  
  145. $file = $_GET['file']; 
  146.  
  147. ob_clean(); 
  148.  
  149. if (@file_exists($file)) { 
  150.  
  151. header("Content-type: application/octet-stream"); 
  152.  
  153. header("Content-Disposition: filename="".basename($file)."""); 
  154.  
  155. echo file_get_contents($file); 
  156.  
  157. } 
  158.  
  159. exit(); 
  160.  
  161. } 
  162.  
  163. ?> 
  164.  
  165. <table border="0" cellpadding="0" cellspacing="0" width="100%"> 
  166.  
  167. <tbody><tr class="head"> 
  168.  
  169. <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> 
  170.  
  171. </tr> 
  172.  
  173. <tr class="alt1"> 
  174.  
  175. <td><span style="float: right;"><?=date("Y-m-d H:i:s",mktime())?></span> 
  176.  
  177. <a href="?action=scan">扫描</a> | 
  178.  
  179. <a href="?action=setting">设定</a> | 
  180.  
  181. <a href="?action=logout">登出</a> 
  182.  
  183. </td> 
  184.  
  185. </tr> 
  186.  
  187. </tbody></table> 
  188.  
  189. <br> 
  190.  
  191. <?php 
  192.  
  193. if($action=="setting") 
  194.  
  195. { 
  196.  
  197. if(isset($_POST['btnsetting'])) 
  198.  
  199. { 
  200.  
  201. $Ssetting = array(); 
  202.  
  203. $Ssetting['user']=isset($_POST['checkuser'])?$_POST['checkuser']:"php | php? | phtml"; 
  204.  
  205. $Ssetting['all']=isset($_POST['checkall'])&&$_POST['checkall']=="on"?1:0; 
  206.  
  207. $Ssetting['hta']=isset($_POST['checkhta'])&&$_POST['checkhta']=="on"?1:0; 
  208.  
  209. setcookie("t00ls_s", base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/"); 
  210.  
  211. echo "设置完成!"; 
  212.  
  213. header( 'refresh: 1; url='.MYFILE.'?action=setting' ); 
  214.  
  215. exit(); 
  216.  
  217. } 
  218.  
  219. ?> 
  220.  
  221. <form name="frmSetting" method="post" action="?action=setting"> 
  222.  
  223. <FIELDSET style="width:400px"> 
  224.  
  225. <LEGEND>扫描设定</LEGEND> 
  226.  
  227. <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
  228.  
  229. <tr> 
  230.  
  231. <td width="60">文件后缀:</td> 
  232.  
  233. <td width="300"><input type="text" name="checkuser" id="checkuser" style="width:300px;" value="<?php echo $setting['user']?>"></td> 
  234.  
  235. </tr> 
  236.  
  237. <tr> 
  238.  
  239. <td><label for="checkall">所有文件</label></td> 
  240.  
  241. <td><input type="checkbox" name="checkall" id="checkall" <?php if($setting['all']==1) echo "checked"?>></td> 
  242.  
  243. </tr> 
  244.  
  245. <tr> 
  246.  
  247. <td><label for="checkhta">设置文件</label></td> 
  248.  
  249. <td><input type="checkbox" name="checkhta" id="checkhta" <?php if($setting['hta']==1) echo "checked"?>></td> 
  250.  
  251. </tr> 
  252.  
  253. <tr> 
  254.  
  255. <td>&nbsp;</td> 
  256.  
  257. <td> 
  258.  
  259. <input type="submit" name="btnsetting" id="btnsetting" value="提交"> 
  260.  
  261. </td> 
  262.  
  263. </tr> 
  264.  
  265. </table> 
  266.  
  267. </fieldset> 
  268.  
  269. </form> 
  270.  
  271. <?php 
  272.  
  273. } 
  274.  
  275. else 
  276.  
  277. { 
  278.  
  279. $dir = isset($_POST['path'])?$_POST['path']:MYPATH; 
  280.  
  281. $dir = substr($dir,-1)!="/"?$dir."/":$dir; 
  282.  
  283. ?> 
  284.  
  285. <form name="frmScan" method="post" action=""> 
  286.  
  287. <table width="100%%" border="0" cellspacing="0" cellpadding="0"> 
  288.  
  289. <tr> 
  290.  
  291. <td width="35" style="vertical-align:middle; padding-left:5px;">扫描路径:</td> 
  292.  
  293. <td width="690"> 
  294.  
  295. <input type="text" name="path" id="path" style="width:600px" value="<?php echo $dir?>"> 
  296.  
  297. &nbsp;&nbsp;<input type="submit" name="btnScan" id="btnScan" value="开始扫描"></td> 
  298.  
  299. </tr> 
  300.  
  301. </table> 
  302.  
  303. </form> 
  304.  
  305. <?php 
  306.  
  307. if(isset($_POST['btnScan'])) 
  308.  
  309. { 
  310.  
  311. $start=mktime(); 
  312.  
  313. $is_user = array(); 
  314.  
  315. $is_ext = ""; 
  316.  
  317. $list = ""; 
  318.  
  319.   
  320.  
  321. if(trim($setting['user'])!="") 
  322.  
  323. { 
  324.  
  325. $is_user = explode("|",$setting['user']); 
  326.  
  327. if(count($is_user)>0) 
  328.  
  329. { 
  330.  
  331. foreach($is_user as $key=>$value) 
  332.  
  333. $is_user[$key]=trim(str_replace("?","(.)",$value)); 
  334.  
  335. $is_ext = "(.".implode("($|.))|(.",$is_user)."($|.))"; 
  336.  
  337. } 
  338.  
  339. } 
  340.  
  341. if($setting['hta']==1) 
  342.  
  343. { 
  344.  
  345. $is_hta=1; 
  346.  
  347. $is_ext = strlen($is_ext)>0?$is_ext."|":$is_ext; 
  348.  
  349. $is_ext.="(^.htaccess$)"; 
  350.  
  351. } 
  352.  
  353. if($setting['all']==1 || (strlen($is_ext)==0 && $setting['hta']==0)) 
  354.  
  355. { 
  356.  
  357. $is_ext="(.+)"; 
  358.  
  359. } 
  360.  
  361.   
  362.  
  363. $php_code = getCode(); 
  364.  
  365. if(!is_readable($dir)) 
  366.  
  367. $dir = MYPATH; 
  368.  
  369. $count=$scanned=0; 
  370.  
  371. scan($dir,$is_ext); 
  372.  
  373. $end=mktime(); 
  374.  
  375. $spent = ($end - $start); 
  376.  
  377. ?> 
  378.  
  379. <div style="padding:10px; background-color:#ccc">扫描: <?php echo $scanned?> 文件| 发现: <?php echo $count?> 可疑文件| 耗时: <?php echo $spent?> 秒</div> 
  380.  
  381. <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
  382.  
  383. <tr class="head"> 
  384.  
  385. <td width="15" align="center">No.</td> 
  386.  
  387. <td width="48%">文件</td> 
  388.  
  389. <td width="12%">更新时间</td> 
  390.  
  391. <td width="10%">原因</td> 
  392.  
  393. <td width="20%">特征</td> 
  394.  
  395. <td>动作</td> 
  396.  
  397. </tr> 
  398.  
  399. <?php echo $list?> 
  400.  
  401. </table> 
  402.  
  403. <?php 
  404.  
  405. } 
  406.  
  407. } 
  408.  
  409. } 
  410.  
  411. ob_flush(); 
  412.  
  413. ?> 
  414.  
  415. </body> 
  416.  
  417. </html> 
  418.  
  419. <?php 
  420.  
  421. function scan($path = '.',$is_ext){ 
  422.  
  423. global $php_code,$count,$scanned,$list; 
  424.  
  425. $ignore = array('.', '..' ); 
  426.  
  427. $replace=array(" ","n","r","t"); 
  428.  
  429. $dh = @opendir( $path ); 
  430.  
  431.   
  432.  
  433.   
  434.  
  435. while(false!==($file=readdir($dh))){ 
  436.  
  437. if( !in_array( $file, $ignore ) ){ 
  438.  
  439. if( is_dir( "$path$file" ) ){ 
  440.  
  441. scan("$path$file/",$is_ext); 
  442.  
  443. } else { 
  444.  
  445. $current = $path.$file; 
  446.  
  447. if(MYFULLPATH==$current) continue; 
  448.  
  449. if(!preg_match("/$is_ext/i",$file)) continue; 
  450.  
  451. if(is_readable($current)) 
  452.  
  453. { 
  454.  
  455. $scanned++; 
  456.  
  457. $content=file_get_contents($current); 
  458.  
  459. $content= str_replace($replace,"",$content); 
  460.  
  461. foreach($php_code as $key => $value) 
  462.  
  463. { 
  464.  
  465. if(preg_match("/$value/i",$content)) 
  466.  
  467. { 
  468.  
  469. $count++; 
  470.  
  471. $j = $count % 2 + 1; 
  472.  
  473. $filetime = date('Y-m-d H:i:s',filemtime($current)); 
  474.  
  475. $reason = explode("->",$key); 
  476.  
  477. $url = str_replace(REALPATH,HOST,$current); 
  478.  
  479. preg_match("/$value/i",$content,$arr); 
  480.  
  481. $list.=" 
  482.  
  483. <tr class='alt$j' onmouseover='this.className="focus";' onmouseout='this.className="alt$j";'> 
  484.  
  485. <td>$count</td> 
  486.  
  487. <td><a href='$url' target='_blank'>$current</a></td> 
  488.  
  489. <td>$filetime</td> 
  490.  
  491. <td><font color=red>$reason[0]</font></td> 
  492.  
  493. <td><font color=#090>$reason[1]</font></td> 
  494.  
  495. <td><a href='?action=download&file=$current' target='_blank'>下载</a></td> 
  496.  
  497. </tr>"; 
  498.  
  499. //echo $key . "-" . $path . $file ."(" . $arr[0] . ")" ."<br />"; 
  500.  
  501. //echo $path . $file ."<br />"; 
  502.  
  503. break; 
  504.  
  505. } 
  506.  
  507. } 
  508.  
  509. } 
  510.  
  511. } 
  512.  
  513. } 
  514.  
  515. } 
  516.  
  517. closedir( $dh ); 
  518.  
  519. } 
  520.  
  521. function getSetting() 
  522.  
  523. { 
  524.  
  525. $Ssetting = array(); 
  526.  
  527. if(isset($_COOKIE['t00ls_s'])) 
  528.  
  529. { 
  530.  
  531. $Ssetting = unserialize(base64_decode($_COOKIE['t00ls_s'])); 
  532.  
  533. $Ssetting['user']=isset($Ssetting['user'])?$Ssetting['user']:"php | php? | phtml | shtml"; 
  534.  
  535. $Ssetting['all']=isset($Ssetting['all'])?intval($Ssetting['all']):0; 
  536.  
  537. $Ssetting['hta']=isset($Ssetting['hta'])?intval($Ssetting['hta']):1; 
  538.  
  539. } 
  540.  
  541. else 
  542.  
  543. { 
  544.  
  545. $Ssetting['user']="php | php? | phtml | shtml"; 
  546.  
  547. $Ssetting['all']=0; 
  548.  
  549. $Ssetting['hta']=1; 
  550.  
  551. setcookie("t00ls_s", base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/"); 
  552.  
  553. } 
  554.  
  555. return $Ssetting; 
  556.  
  557. } 
  558.  
  559. function getCode() 
  560.  
  561. { 
  562.  
  563. return array( 
  564.  
  565. '后门特征->phpfensi.com'=>'phpfensi.com', 
  566.  
  567. '后门特征->c99shell'=>'c99shell', 
  568.  
  569. '后门特征->phpspy'=>'phpspy', 
  570.  
  571. '后门特征->Scanners'=>'Scanners', 
  572.  
  573. '后门特征->cmd.php'=>'cmd.php', 
  574.  
  575. '后门特征->str_rot13'=>'str_rot13', 
  576.  
  577. '后门特征->webshell'=>'webshell', 
  578.  
  579. '后门特征->EgY_SpIdEr'=>'EgY_SpIdEr', 
  580.  
  581. '后门特征->tools88.com'=>'tools88.com', 
  582.  
  583. '后门特征->SECFORCE'=>'SECFORCE', 
  584.  
  585. '后门特征->eval("?>'=>'eval(('|")?>', 
  586.  
  587. '可疑代码特征->system('=>'system(', 
  588.  
  589. '可疑代码特征->passthru('=>'passthru(', 
  590.  
  591. '可疑代码特征->shell_exec('=>'shell_exec(', 
  592.  
  593. '可疑代码特征->exec('=>'exec(', 
  594.  
  595. '可疑代码特征->popen('=>'popen(', 
  596.  
  597. '可疑代码特征->proc_open'=>'proc_open', 
  598.  
  599. '可疑代码特征->eval($'=>'eval(('|"|s*)\$', 
  600.  
  601. '可疑代码特征->assert($'=>'assert(('|"|s*)\$', 
  602.  
  603. '危险MYSQL代码->returns string soname'=>'returnsstringsoname', 
  604.  
  605. '危险MYSQL代码->into outfile'=>'intooutfile', 
  606.  
  607. '危险MYSQL代码->load_file'=>'select(s+)(.*)load_file', 
  608.  
  609. '加密后门特征->eval(gzinflate('=>'eval(gzinflate(', 
  610.  
  611. '加密后门特征->eval(base64_decode('=>'eval(base64_decode(', 
  612.  
  613. '加密后门特征->eval(gzuncompress('=>'eval(gzuncompress(', 
  614.  
  615. '加密后门特征->eval(gzdecode('=>'eval(gzdecode(', 
  616.  
  617. '加密后门特征->eval(str_rot13('=>'eval(str_rot13(', 
  618.  
  619. '加密后门特征->gzuncompress(base64_decode('=>'gzuncompress(base64_decode(', 
  620.  
  621. '加密后门特征->base64_decode(gzuncompress('=>'base64_decode(gzuncompress(', 
  622.  
  623. '一句话后门特征->eval($_'=>'eval(('|"|s*)\$_(POST|GET|REQUEST|COOKIE)', 
  624.  
  625. '一句话后门特征->assert($_'=>'assert(('|"|s*)\$_(POST|GET|REQUEST|COOKIE)', 
  626.  
  627. '一句话后门特征->require($_'=>'require(('|"|s*)\$_(POST|GET|REQUEST|COOKIE)', 
  628.  
  629. '一句话后门特征->require_once($_'=>'require_once(('|"|s*)\$_(POST|GET|REQUEST|COOKIE)', 
  630.  
  631. '一句话后门特征->include($_'=>'include(('|"|s*)\$_(POST|GET|REQUEST|COOKIE)', 
  632.  
  633. '一句话后门特征->include_once($_'=>'include_once(('|"|s*)\$_(POST|GET|REQUEST|COOKIE)', 
  634.  
  635. '一句话后门特征->call_user_func("assert"'=>'call_user_func(("|')assert("|')', 
  636.  
  637. '一句话后门特征->call_user_func($_'=>'call_user_func(('|"|s*)\$_(POST|GET|REQUEST|COOKIE)', 
  638.  
  639. '一句话后门特征->$_POST/GET/REQUEST/COOKIE[?]($_POST/GET/REQUEST/COOKIE[?]'=>'$_(POST|GET|REQUEST|COOKIE)[([^]]+)](('|"|s*)\$_(POST|GET|REQUEST|COOKIE)[', 
  640.  
  641. '一句话后门特征->echo(file_get_contents($_POST/GET/REQUEST/COOKIE'=>'echo(file_get_contents(('|"|s*)\$_(POST|GET|REQUEST|COOKIE)', 
  642.  
  643. '上传后门特征->file_put_contents($_POST/GET/REQUEST/COOKIE,$_POST/GET/REQUEST/COOKIE'=>'file_put_contents(('|"|s*)\$_(POST|GET|REQUEST|COOKIE)[([^]]+)],('|"|s*)\$_(POST|GET|REQUEST|COOKIE)', 
  644.  
  645. '上传后门特征->fputs(fopen("?","w"),$_POST/GET/REQUEST/COOKIE['=>'fputs(fopen((.+),('|")w('|")),('|"|s*)\$_(POST|GET|REQUEST|COOKIE)[', 
  646.  
  647. '.htaccess插马特征->SetHandler application/x-httpd-php'=>'SetHandlerapplication/x-httpd-php', 
  648.  
  649. '.htaccess插马特征->php_value auto_prepend_file'=>'php_valueauto_prepend_file', 
  650.  
  651. '.htaccess插马特征->php_value auto_append_file'=>'php_valueauto_append_file' 
  652. //开源代码phpfensi.com 
  653. );
  654. }
  655. ?> 

Tags: php网站挂马 php网站被挂木马

分享到: