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. echo '用户名:  密码:  '
  77.  
  78.  
  79. elseif(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5)) 
  80.  
  81.  
  82. setcookie("t00ls"$md5, time()+60*60*24*365,"/"); 
  83.  
  84. echo "登陆成功!"
  85.  
  86. header( 'refresh: 1; url='.MYFILE.'?action=scan' ); 
  87.  
  88. exit(); 
  89.  
  90.  
  91. else 
  92.  
  93.  
  94. setcookie("t00ls"$md5, time()+60*60*24*365,"/"); 
  95.  
  96. $setting = getSetting(); 
  97.  
  98. $action = isset($_GET['action'])?$_GET['action']:""
  99.  
  100.   
  101.  
  102. if($action=="logout"
  103.  
  104.  
  105. setcookie ("t00ls""", time() - 3600); 
  106.  
  107. Header("Location: ".MYFILE); 
  108.  
  109. exit(); 
  110.  
  111.  
  112. if($action=="download" && isset($_GET['file']) && trim($_GET['file'])!=""
  113.  
  114.  
  115. $file = $_GET['file']; 
  116.  
  117. ob_clean(); 
  118.  
  119. if (@file_exists($file)) { 
  120.  
  121. header("Content-type: application/octet-stream"); 
  122.  
  123. header("Content-Disposition: filename="".basename($file)."""); 
  124.  
  125. echo file_get_contents($file); 
  126.  
  127.  
  128. exit(); 
  129.  
  130.  
  131. ?> 
  132.  
  133. "0" cellpadding="0" cellspacing="0" width="100%"
  134.  
  135. class="head"
  136.  
  137. echo $_SERVER['SERVER_ADDR']?>"float: right; font-weight:bold;">echo "$version"?> 
  138.  
  139.  
  140.  
  141. class="alt1"
  142.  
  143. "float: right;">date("Y-m-d H:i:s",mktime())?> 
  144.  
  145. "?action=scan">扫描 | 
  146.  
  147. "?action=setting">设定 | 
  148.  
  149. "?action=logout">登出 
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  

  157.  
  158.  
  159.  
  160. if($action=="setting"
  161.  
  162.  
  163. if(isset($_POST['btnsetting'])) 
  164.  
  165.  
  166. $Ssetting = array(); 
  167.  
  168. $Ssetting['user']=isset($_POST['checkuser'])?$_POST['checkuser']:"php | php? | phtml"
  169.  
  170. $Ssetting['all']=isset($_POST['checkall'])&&$_POST['checkall']=="on"?1:0; 
  171.  
  172. $Ssetting['hta']=isset($_POST['checkhta'])&&$_POST['checkhta']=="on"?1:0; 
  173.  
  174. setcookie("t00ls_s"base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/"); 
  175.  
  176. echo "设置完成!"
  177.  
  178. header( 'refresh: 1; url='.MYFILE.'?action=setting' ); 
  179.  
  180. exit(); 
  181.  
  182.  
  183. ?> 
  184.  
  185. "frmSetting" method="post" action="?action=setting"
  186.  
  187. "width:400px"
  188.  
  189. 扫描设定 
  190.  
  191. "100%" border="0" cellspacing="0" cellpadding="0"
  192.  
  193.  
  194.  
  195. "60">文件后缀: 
  196.  
  197. "300">"text" name="checkuser" id="checkuser" style="width:300px;" value=""
  198.  
  199.  
  200.  
  201.  
  202.  
  203. for="checkall">所有文件 
  204.  
  205. "checkbox" name="checkall" id="checkall" if($setting['all']==1) echo "checked"?>> 
  206.  
  207.  
  208.  
  209.  
  210.  
  211. for="checkhta">设置文件 
  212.  
  213. "checkbox" name="checkhta" id="checkhta" if($setting['hta']==1) echo "checked"?>> 
  214.  
  215.  
  216.  
  217.  
  218.  
  219.   
  220.  
  221.  
  222.  
  223. "submit" name="btnsetting" id="btnsetting" value="提交"
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237. else 
  238.  
  239.  
  240. $dir = isset($_POST['path'])?$_POST['path']:MYPATH; 
  241.  
  242. $dir = substr($dir,-1)!="/"?$dir."/":$dir
  243.  
  244. ?> 
  245.  
  246. "frmScan" method="post" action=""
  247.  
  248. "100%%" border="0" cellspacing="0" cellpadding="0"
  249.  
  250.  
  251.  
  252. "35" style="vertical-align:middle; padding-left:5px;">扫描路径: 
  253.  
  254. "690"
  255.  
  256. "text" name="path" id="path" style="width:600px" value=""
  257.  
  258.   "submit" name="btnScan" id="btnScan" value="开始扫描"
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267. if(isset($_POST['btnScan'])) 
  268.  
  269.  
  270. $start=mktime(); 
  271.  
  272. $is_user = array(); 
  273.  
  274. $is_ext = ""
  275.  
  276. $list = ""
  277.  
  278.   
  279.  
  280. if(trim($setting['user'])!=""
  281.  
  282.  
  283. $is_user = explode("|",$setting['user']); 
  284.  
  285. if(count($is_user)>0) 
  286.  
  287.  
  288. foreach($is_user as $key=>$value
  289.  
  290. $is_user[$key]=trim(str_replace("?","(.)",$value)); 
  291.  
  292. $is_ext = "(.".implode("($|.))|(.",$is_user)."($|.))"
  293.  
  294.  
  295.  
  296. if($setting['hta']==1) 
  297.  
  298.  
  299. $is_hta=1; 
  300.  
  301. $is_ext = strlen($is_ext)>0?$is_ext."|":$is_ext
  302.  
  303. $is_ext.="(^.htaccess$)"
  304.  
  305.  
  306. if($setting['all']==1 || (strlen($is_ext)==0 && $setting['hta']==0)) 
  307.  
  308.  
  309. $is_ext="(.+)"
  310.  
  311.  
  312.   
  313.  
  314. $php_code = getCode(); 
  315.  
  316. if(!is_readable($dir)) 
  317.  
  318. $dir = MYPATH; 
  319.  
  320. $count=$scanned=0; 
  321.  
  322. scan($dir,$is_ext); 
  323.  
  324. $end=mktime(); 
  325.  
  326. $spent = ($end - $start); 
  327.  
  328. ?> 
  329.  
  330. "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 ) ){ 
  •  
  • ifis_dir"$path$file" ) ){ 
  •  
  • scan("$path$file/",$is_ext); 
  •  
  • else { 
  •  
  • $current = $path.$file
  •  
  • if(MYFULLPATH==$currentcontinue
  •  
  • if(!preg_match("/$is_ext/i",$file)) continue
  •  
  • if(is_readable($current)) 
  •  
  •  
  • $scanned++; 
  •  
  • $content=file_get_contents($current); 
  •  
  • $contentstr_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技术的分享社区,专属您自己的技术摘抄本、收藏夹。
    • 在这里……