php专区

 首页 > php专区 > PHP应用 > 常用功能 > php网站被挂木马修复方法总结 - php高级应用

php网站被挂木马修复方法总结 - php高级应用

分享到:
【字体:大 中 小】
导读:
          php网站被挂木马修复是次要的最要的是怎么修复之后不再让木马再注入到你的网站才是重要的,下面我来总结一下php网站被挂木马修复与之后防止网站再次给挂木马的方法.在linux中我们可...

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

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.  
  2. /**************PHP Web木马扫描器************************/ 
  3.  
  4. /* [+] 作者: alibaba */ 
  5.  
  6. /* [+] QQ: 1499281192 * www.phpfensi.com/ 
  7.  
  8. /* [+] MSN: weeming21@hotmail.com */ 
  9.  
  10. /* [+] 首发: t00ls.net , 转载请注明t00ls */ 
  11.  
  12. /* [+] 版本: v1.0 */ 
  13.  
  14. /* [+] 功能: web版php木马扫描工具*/ 
  15.  
  16. /* [+] 注意: 扫描出来的文件并不一定就是后门, */ 
  17.  
  18. /* 请自行判断、审核、对比原文件。*/ 
  19.  
  20. /* 如果你不确定扫出来的文件是否为后门,*/ 
  21.  
  22. /* 欢迎你把该文件发给我进行分析。*/ 
  23.  
  24. /*******************************************************/ 
  25.  
  26. ob_start(); 
  27.  
  28. set_time_limit(0); 
  29.  
  30. $username = "t00ls"; //设置用户名 
  31.  
  32. $password = "t00ls"; //设置密码 
  33.  
  34. $md5 = md5(md5($username).md5($password)); 
  35.  
  36. $version = "PHP Web木马扫描器v1.0"; 
  37.  
  38. PHP Web 木马扫描器 
  39.  
  40. $realpath = realpath('./'); 
  41.  
  42. $selfpath = $_SERVER['PHP_SELF']; 
  43.  
  44. $selfpath = substr($selfpath, 0, strrpos($selfpath,'/')); 
  45.  
  46. define('REALPATH', str_replace('//','/',str_replace('','/',substr($realpath, 0, strlen($realpath) - strlen($selfpath))))); 
  47.  
  48. define('MYFILE', basename(__FILE__)); 
  49.  
  50. define('MYPATH', str_replace('', '/', dirname(__FILE__)).'/'); 
  51.  
  52. define('MYFULLPATH', str_replace('', '/', (__FILE__))); 
  53.  
  54. define('HOST', "http://".$_SERVER['HTTP_HOST']); 
  55.  
  56. ?> 
  57.  
  58.  
  59.  
  60.  
  61.  
  62. <?php <span class="func">echo</span><span> </span><span class="vars">$version</span><span>?> 
  63.  
  64. "Content-Type" content="text/html; charset=gb2312" /> 
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. if(!(isset($_COOKIE['t00ls']) && $_COOKIE['t00ls'] == $md5) && !(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5))) 
  74.  
  75. { 
  76.  
  77. echo '用户名:  密码:  '; 
  78.  
  79. } 
  80.  
  81. elseif(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5)) 
  82.  
  83. { 
  84.  
  85. setcookie("t00ls", $md5, time()+60*60*24*365,"/"); 
  86.  
  87. echo "登陆成功!"; 
  88.  
  89. header( 'refresh: 1; url='.MYFILE.'?action=scan' ); 
  90.  
  91. exit(); 
  92.  
  93. } 
  94.  
  95. else 
  96.  
  97. { 
  98.  
  99. setcookie("t00ls", $md5, time()+60*60*24*365,"/"); 
  100.  
  101. $setting = getSetting(); 
  102.  
  103. $action = isset($_GET['action'])?$_GET['action']:""; 
  104.  
  105.   
  106.  
  107. if($action=="logout") 
  108.  
  109. { 
  110.  
  111. setcookie ("t00ls", "", time() - 3600); 
  112.  
  113. Header("Location: ".MYFILE); 
  114.  
  115. exit(); 
  116.  
  117. } 
  118.  
  119. if($action=="download" && isset($_GET['file']) && trim($_GET['file'])!="") 
  120.  
  121. { 
  122.  
  123. $file = $_GET['file']; 
  124.  
  125. ob_clean(); 
  126.  
  127. if (@file_exists($file)) { 
  128.  
  129. header("Content-type: application/octet-stream"); 
  130.  
  131. header("Content-Disposition: filename="".basename($file)."""); 
  132.  
  133. echo file_get_contents($file); 
  134.  
  135. } 
  136.  
  137. exit(); 
  138.  
  139. } 
  140.  
  141. ?> 
  142.  
  143. "0" cellpadding="0" cellspacing="0" width="100%"> 
  144.  
  145. class="head"> 
  146.  
  147. echo $_SERVER['SERVER_ADDR']?>"float: right; font-weight:bold;">echo "$version"?> 
  148.  
  149.  
  150.  
  151. class="alt1"> 
  152.  
  153. "float: right;">date("Y-m-d H:i:s",mktime())?> 
  154.  
  155. "?action=scan">扫描 | 
  156.  
  157. "?action=setting">设定 | 
  158.  
  159. "?action=logout">登出 
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  

  167.  
  168.  
  169.  
  170. if($action=="setting") 
  171.  
  172. { 
  173.  
  174. if(isset($_POST['btnsetting'])) 
  175.  
  176. { 
  177.  
  178. $Ssetting = array(); 
  179.  
  180. $Ssetting['user']=isset($_POST['checkuser'])?$_POST['checkuser']:"php | php? | phtml"; 
  181.  
  182. $Ssetting['all']=isset($_POST['checkall'])&&$_POST['checkall']=="on"?1:0; 
  183.  
  184. $Ssetting['hta']=isset($_POST['checkhta'])&&$_POST['checkhta']=="on"?1:0; 
  185.  
  186. setcookie("t00ls_s", base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/"); 
  187.  
  188. echo "设置完成!"; 
  189.  
  190. header( 'refresh: 1; url='.MYFILE.'?action=setting' ); 
  191.  
  192. exit(); 
  193.  
  194. } 
  195.  
  196. ?> 
  197.  
  198. "frmSetting" method="post" action="?action=setting"> 
  199.  
  200. "width:400px"> 
  201.  
  202. 扫描设定 
  203.  
  204. "100%" border="0" cellspacing="0" cellpadding="0"> 
  205.  
  206.  
  207.  
  208. "60">文件后缀: 
  209.  
  210. "300">"text" name="checkuser" id="checkuser" style="width:300px;" value=""> 
  211.  
  212.  
  213.  
  214.  
  215.  
  216. for="checkall">所有文件 
  217.  
  218. "checkbox" name="checkall" id="checkall" if($setting['all']==1) echo "checked"?>> 
  219.  
  220.  
  221.  
  222.  
  223.  
  224. for="checkhta">设置文件 
  225.  
  226. "checkbox" name="checkhta" id="checkhta" if($setting['hta']==1) echo "checked"?>> 
  227.  
  228.  
  229.  
  230.  
  231.  
  232.   
  233.  
  234.  
  235.  
  236. "submit" name="btnsetting" id="btnsetting" value="提交"> 
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249. } 
  250.  
  251. else 
  252.  
  253. { 
  254.  
  255. $dir = isset($_POST['path'])?$_POST['path']:MYPATH; 
  256.  
  257. $dir = substr($dir,-1)!="/"?$dir."/":$dir; 
  258.  
  259. ?> 
  260.  
  261. "frmScan" method="post" action=""> 
  262.  
  263. "100%%" border="0" cellspacing="0" cellpadding="0"> 
  264.  
  265.  
  266.  
  267. "35" style="vertical-align:middle; padding-left:5px;">扫描路径: 
  268.  
  269. "690"> 
  270.  
  271. "text" name="path" id="path" style="width:600px" value=""> 
  272.  
  273.   "submit" name="btnScan" id="btnScan" value="开始扫描"> 
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282. if(isset($_POST['btnScan'])) 
  283.  
  284. { 
  285.  
  286. $start=mktime(); 
  287.  
  288. $is_user = array(); 
  289.  
  290. $is_ext = ""; 
  291.  
  292. $list = ""; 
  293.  
  294.   
  295.  
  296. if(trim($setting['user'])!="") 
  297.  
  298. { 
  299.  
  300. $is_user = explode("|",$setting['user']); 
  301.  
  302. if(count($is_user)>0) 
  303.  
  304. { 
  305.  
  306. foreach($is_user as $key=>$value) 
  307.  
  308. $is_user[$key]=trim(str_replace("?","(.)",$value)); 
  309.  
  310. $is_ext = "(.".implode("($|.))|(.",$is_user)."($|.))"; 
  311.  
  312. } 
  313.  
  314. } 
  315.  
  316. if($setting['hta']==1) 
  317.  
  318. { 
  319.  
  320. $is_hta=1; 
  321.  
  322. $is_ext = strlen($is_ext)>0?$is_ext."|":$is_ext; 
  323.  
  324. $is_ext.="(^.htaccess$)"; 
  325.  
  326. } 
  327.  
  328. if($setting['all']==1 || (strlen($is_ext)==0 && $setting['hta']==0)) 
  329.  
  330. { 
  331.  
  332. $is_ext="(.+)"; 
  333.  
  334. } 
  335.  
  336.   
  337.  
  338. $php_code = getCode(); 
  339.  
  340. if(!is_readable($dir)) 
  341.  
  342. $dir = MYPATH; 
  343.  
  344. $count=$scanned=0; 
  345.  
  346. scan($dir,$is_ext); 
  347.  
  348. $end=mktime(); 
  349.  
  350. $spent = ($end - $start); 
  351.  
  352. ?> 
  353.  
  354. "padding:10px; background-color:#ccc">扫描: echo $scanned?> 文件| 发现: echo $count?> 可疑文件| 耗时: echo $spent?> 秒
 
  •  
  • "100%" border="0" cellspacing="0" cellpadding="0"> 
  •  
  • class="head"> 
  •  
  • "15" align="center">No. 
  •  
  • "48%">文件 
  •  
  • "12%">更新时间 
  •  
  • "10%">原因 
  •  
  • "20%">特征 
  •  
  • 动作 
  •  
  •  
  •  
  • echo $list?> 
  •  
  •  
  •  
  •  
  • } 
  •  
  • } 
  •  
  • } 
  •  
  • ob_flush(); 
  •  
  • ?> 
  •  
  •  
  •  
  •  
  •  
  •  
  • function scan($path = '.',$is_ext){ 
  •  
  • global $php_code,$count,$scanned,$list; 
  •  
  • $ignore = array('.', '..' ); 
  •  
  • $replace=array(" ","n","r","t"); 
  •  
  • $dh = @opendir( $path ); 
  •  
  •   
  •  
  •   
  •  
  • while(false!==($file=readdir($dh))){ 
  •  
  • if( !in_array( $file, $ignore ) ){ 
  •  
  • if( is_dir( "$path$file" ) ){ 
  •  
  • scan("$path$file/",$is_ext); 
  •  
  • } else { 
  •  
  • $current = $path.$file; 
  •  
  • if(MYFULLPATH==$current) continue; 
  •  
  • if(!preg_match("/$is_ext/i",$file)) continue; 
  •  
  • if(is_readable($current)) 
  •  
  • { 
  •  
  • $scanned++; 
  •  
  • $content=file_get_contents($current); 
  •  
  • $content= str_replace($replace,"",$content); 
  •  
  • foreach($php_code as $key => $value) 
  •  
  • { 
  •  
  • if(preg_match("/$value/i",$content)) 
  •  
  • { 
  •  
  • $count++; 
  •  
  • $j = $count % 2 + 1; 
  •  
  • $filetime = date('Y-m-d H:i:s',filemtime($current)); 
  •  
  • $reason = explode("->",$key); 
  •  
  • $url = str_replace(REALPATH,HOST,$current); 
  •  
  • preg_match("/$value/i",$content,$arr); 
  •  
  • $list.=" 
  •  
  • class='alt$j' onmouseover='this.className="focus";' onmouseout='this.className="alt$j";'> 
  •  
  • $count 
  •  
  • '$url' target='_blank'>$current 
  •  
  • $filetime 
  •  
  • $reason[0] 
  •  
  • $reason[1] 
  •  
  • '?action=download&file=$current' target='_blank'>下载 
  •  
  • "; 
  •  
  • //echo $key . "-" . $path . $file ."(" . $arr[0] . ")" .""; 
  •  
  • //echo $path . $file .""; 
  •  
  • break; 
  •  
  • } 
  •  
  • } 
  •  
  • } 
  •  
  • } 
  •  
  • } 
  •  
  • } 
  •  
  • closedir( $dh ); 
  •  
  • } 
  •  
  • function getSetting() 
  •  
  • { 
  •  
  • $Ssetting = array(); 
  •  
  • if(isset($_COOKIE['t00ls_s'])) 
  •  
  • { 
  •  
  • $Ssetting = unserialize(base64_decode($_COOKIE['t00ls_s'])); 
  •  
  • $Ssetting['user']=isset($Ssetting['user'])?$Ssetting['user']:"php | php? | phtml | shtml"; 
  •  
  • $Ssetting['all']=isset($Ssetting['all'])?intval($Ssetting['all']):0; 
  •  
  • $Ssetting['hta']=isset($Ssetting['hta'])?intval($Ssetting['hta']):1; 
  •  
  • } 
  •  
  • else 
  •  
  • { 
  •  
  • $Ssetting['user']="php | php? | phtml | shtml"; 
  •  
  • $Ssetting['all']=0; 
  •  
  • $Ssetting['hta']=1; 
  •  
  • setcookie("t00ls_s", base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/"); 
  •  
  • } 
  •  
  • return $Ssetting; 
  •  
  • } 
  •  
  • function getCode() 
  •  
  • { 
  •  
  • return array( 
  •  
  • '后门特征->phpfensi.com'=>'phpfensi.com', 
  •  
  • '后门特征->c99shell'=>'c99shell', 
  •  
  • '后门特征->phpspy'=>'phpspy', 
  •  
  • '后门特征->Scanners'=>'Scanners', 
  •  
  • '后门特征->cmd.php'=>'cmd.php', 
  •  
  • '后门特征->str_rot13'=>'str_rot13', 
  •  
  • '后门特征->webshell'=>'webshell', 
  •  
  • '后门特征->EgY_SpIdEr'=>'EgY_SpIdEr', 
  •  
  • '后门特征->tools88.com'=>'tools88.com', 
  •  
  • '后门特征->SECFORCE'=>'SECFORCE', 
  •  
  • '后门特征->eval("?>'=>'eval(('|")?>', 
  •  
  • '可疑代码特征->system('=>'system(', 
  •  
  • '可疑代码特征->passthru('=>'passthru(', 
  •  
  • '可疑代码特征->shell_exec('=>'shell_exec(', 
  •  
  • '可疑代码特征->exec('=>'exec(', 
  •  
  • '可疑代码特征->popen('=>'popen(', 
  •  
  • '可疑代码特征->proc_open'=>'proc_open', 
  •  
  • '可疑代码特征->eval($'=>'eval(('|"|s*)$', 
  •  
  • '可疑代码特征->assert($'=>'assert(('|"|s*)$', 
  •  
  • '危险MYSQL代码->returns string soname'=>'returnsstringsoname', 
  •  
  • '危险MYSQL代码->into outfile'=>'intooutfile', 
  •  
  • '危险MYSQL代码->load_file'=>'select(s+)(.*)load_file', 
  •  
  • '加密后门特征->eval(gzinflate('=>'eval(gzinflate(', 
  •  
  • '加密后门特征->eval(base64_decode('=>'eval(base64_decode(', 
  •  
  • '加密后门特征->eval(gzuncompress('=>'eval(gzuncompress(', 
  •  
  • '加密后门特征->eval(gzdecode('=>'eval(gzdecode(', 
  •  
  • '加密后门特征->eval(str_rot13('=>'eval(str_rot13(', 
  •  
  • '加密后门特征->gzuncompress(base64_decode('=>'gzuncompress(base64_decode(', 
  •  
  • '加密后门特征->base64_decode(gzuncompress('=>'base64_decode(gzuncompress(', 
  •  
  • '一句话后门特征->eval($_'=>'eval(('|"|s*)$_(POST|GET|REQUEST|COOKIE)', 
  •  
  • '一句话后门特征->assert($_'=>'assert(('|"|s*)$_(POST|GET|REQUEST|COOKIE)', 
  •  
  • '一句话后门特征->require($_'=>'require(('|"|s*)$_(POST|GET|REQUEST|COOKIE)', 
  •  
  • '一句话后门特征->require_once($_'=>'require_once(('|"|s*)$_(POST|GET|REQUEST|COOKIE)', 
  •  
  • '一句话后门特征->include($_'=>'include(('|"|s*)$_(POST|GET|REQUEST|COOKIE)', 
  •  
  • '一句话后门特征->include_once($_'=>'include_once(('|"|s*)$_(POST|GET|REQUEST|COOKIE)', 
  •  
  • '一句话后门特征->call_user_func("assert"'=>'call_user_func(("|')assert("|')', 
  •  
  • '一句话后门特征->call_user_func($_'=>'call_user_func(('|"|s*)$_(POST|GET|REQUEST|COOKIE)', 
  •  
  • '一句话后门特征->$_POST/GET/REQUEST/COOKIE[?]($_POST/GET/REQUEST/COOKIE[?]'=>'$_(POST|GET|REQUEST|COOKIE)[([^]]+)](('|"|s*)$_(POST|GET|REQUEST|COOKIE)[', 
  •  
  • '一句话后门特征->echo(file_get_contents($_POST/GET/REQUEST/COOKIE'=>'echo(file_get_contents(('|"|s*)$_(POST|GET|REQUEST|COOKIE)', 
  •  
  • '上传后门特征->file_put_contents($_POST/GET/REQUEST/COOKIE,$_POST/GET/REQUEST/COOKIE'=>'file_put_contents(('|"|s*)$_(POST|GET|REQUEST|COOKIE)[([^]]+)],('|"|s*)$_(POST|GET|REQUEST|COOKIE)', 
  •  
  • '上传后门特征->fputs(fopen("?","w"),$_POST/GET/REQUEST/COOKIE['=>'fputs(fopen((.+),('|")w('|")),('|"|s*)$_(POST|GET|REQUEST|COOKIE)[', 
  •  
  • '.htaccess插马特征->SetHandler application/x-httpd-php'=>'SetHandlerapplication/x-httpd-php', 
  •  
  • '.htaccess插马特征->php_value auto_prepend_file'=>'php_valueauto_prepend_file', 
  •  
  • '.htaccess插马特征->php_value auto_append_file'=>'php_valueauto_append_file' 
  • //开源代码phpfensi.com 
  • );
  • }
  • ?> 
  • 分享到:
    PHP防CC攻击实现代码总结 - php高级应用
    PHP防CC攻击实现代码总结 CC攻击就是对方利用程序或一些代理对您的网站进行不间断的访问,造成您的网站处理不了而处于当机状态,下面我们来总结一些防CC攻击的php实例代码,各位朋友可参考. 例1,代码如下: //代理IP直接退出   emptyempty($_SERVER[&#039;HTTP_VIA&#039;]) or exit(&...
    BS结构中使用PHP访问ORACLE LOB - php高...
    BS结构中使用PHP访问ORACLE LOB 摘要:本文介绍了如何利用PHP的数据库访问技术实现对ORACLE LOB数据对象的存储。 关键字:PHP;ORACLE; LOB;存储; 引言:PHP,即“PHP: Hypertext Preprocessor”,是一种广泛用于 Open Source(开放源代码)并可以嵌入 HTML 的多用途脚本语言。它的语法...
    •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
    • 在这里……