本文實例總結了php網站被掛木馬後的修復方法。分享給大家供大家參考。具體方法如下:
在linux中我們可以使用命令來搜查木馬文件,到代碼安裝目錄執行下面命令
復制代碼 代碼如下:find ./ -iname "*.php" | xargs grep -H -n "eval(base64_decode"
搜出來接近100條結果,這個結果列表很重要,木馬都在裡面,要一個一個文件打開驗證是否是木馬,如果是,馬上刪除掉
最後找到10個木馬文件,存放在各種目錄,都是php webshell,功能很齊全,用base64編碼
如果你在windows中查找目錄直接使用windows文件搜索就可以了,可以搜索eval或最近修改文件,然後如果是dedecms我們要查看最新dedecms漏洞呀然後修補。
下面給個php木馬查找工具,直接放到你站點根目錄
復制代碼 代碼如下:<?php
/**************PHP Web木馬掃描器************************/
/* [+] 作者: alibaba */
/* [+] MSN: [email protected] */
/* [+] 首發: t00ls.net , 轉載請注明t00ls */
/* [+] 版本: v1.0 */
/* [+] 功能: web版php木馬掃描工具*/
/* [+] 注意: 掃描出來的文件並不一定就是後門, */
/* 請自行判斷、審核、對比原文件。*/
/* 如果你不確定掃出來的文件是否為後門,*/
/* 歡迎你把該文件發給我進行分析。*/
/*******************************************************/
ob_start();
set_time_limit(0);
$username = "t00ls"; //設置用戶名
$password = "t00ls"; //設置密碼
$md5 = md5(md5($username).md5($password));
$version = "PHP Web木馬掃描器v1.0";
PHP Web 木馬掃描器
$realpath = realpath('./');
$selfpath = $_SERVER['PHP_SELF'];
$selfpath = substr($selfpath, 0, strrpos($selfpath,'/'));
define('REALPATH', str_replace('//','/',str_replace('\','/',substr($realpath, 0, strlen($realpath) - strlen($selfpath)))));
define('MYFILE', basename(__FILE__));
define('MYPATH', str_replace('\', '/', dirname(__FILE__)).'/');
define('MYFULLPATH', str_replace('\', '/', (__FILE__)));
define('HOST', "http://".$_SERVER['HTTP_HOST']);
?>
<html>
<head>
<title><?php echo $version?></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style>
body{margin:0px;}
body,td{font: 12px Arial,Tahoma;line-height: 16px;}
a {color: #00f;text-decoration:underline;}
a:hover{color: #f00;text-decoration:none;}
.alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;}
.alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;}
.focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;}
.head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;}
.head td span{font-weight:normal;}
</style>
</head>
<body>
<?php
if(!(isset($_COOKIE['t00ls']) && $_COOKIE['t00ls'] == $md5) && !(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5)))
{
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>';
}
elseif(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5))
{
setcookie("t00ls", $md5, time()+60*60*24*365,"/");
echo "登陸成功!";
header( 'refresh: 1; url='.MYFILE.'?action=scan' );
exit();
}
else
{
setcookie("t00ls", $md5, time()+60*60*24*365,"/");
$setting = getSetting();
$action = isset($_GET['action'])?$_GET['action']:"";
if($action=="logout")
{
setcookie ("t00ls", "", time() - 3600);
Header("Location: ".MYFILE);
exit();
}
if($action=="download" && isset($_GET['file']) && trim($_GET['file'])!="")
{
$file = $_GET['file'];
ob_clean();
if (@file_exists($file)) {
header("Content-type: application/octet-stream");
header("Content-Disposition: filename="".basename($file).""");
echo file_get_contents($file);
}
exit();
}
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr class="head">
<td><?php echo $_SERVER['SERVER_ADDR']?><span ><?php echo "<a href='http://www.t00ls.net/'>$version</a>"?></span></td>
</tr>
<tr class="alt1">
<td><span ><?=date("Y-m-d H:i:s",mktime())?></span>
<a href="?action=scan">掃描</a> |
<a href="?action=setting">設定</a> |
<a href="?action=logout">登出</a>
</td>
</tr>
</tbody></table>
<br>
<?php
if($action=="setting")
{
if(isset($_POST['btnsetting']))
{
$Ssetting = array();
$Ssetting['user']=isset($_POST['checkuser'])?$_POST['checkuser']:"php | php? | phtml";
$Ssetting['all']=isset($_POST['checkall'])&&$_POST['checkall']=="on"?1:0;
$Ssetting['hta']=isset($_POST['checkhta'])&&$_POST['checkhta']=="on"?1:0;
setcookie("t00ls_s", base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/");
echo "設置完成!";
header( 'refresh: 1; url='.MYFILE.'?action=setting' );
exit();
}
?>
<form name="frmSetting" method="post" action="?action=setting">
<FIELDSET >
<LEGEND>掃描設定</LEGEND>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="60">文件後綴:</td>
<td width="300"><input type="text" name="checkuser" id="checkuser" value="<?php echo $setting['user']?>"></td>
</tr>
<tr>
<td><label for="checkall">所有文件</label></td>
<td><input type="checkbox" name="checkall" id="checkall" <?php if($setting['all']==1) echo "checked"?>></td>
</tr>
<tr>
<td><label for="checkhta">設置文件</label></td>
<td><input type="checkbox" name="checkhta" id="checkhta" <?php if($setting['hta']==1) echo "checked"?>></td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="btnsetting" id="btnsetting" value="提交">
</td>
</tr>
</table>
</fieldset>
</form>
<?php
}
else
{
$dir = isset($_POST['path'])?$_POST['path']:MYPATH;
$dir = substr($dir,-1)!="/"?$dir."/":$dir;
?>
<form name="frmScan" method="post" action="">
<table width="100%%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="35" >掃描路徑:</td>
<td width="690">
<input type="text" name="path" id="path" value="<?php echo $dir?>">
<input type="submit" name="btnScan" id="btnScan" value="開始掃描"></td>
</tr>
</table(www.jb51.net)>
</form>
<?php
if(isset($_POST['btnScan']))
{
$start=mktime();
$is_user = array();
$is_ext = "";
$list = "";
if(trim($setting['user'])!="")
{
$is_user = explode("|",$setting['user']);
if(count($is_user)>0)
{
foreach($is_user as $key=>$value)
$is_user[$key]=trim(str_replace("?","(.)",$value));
$is_ext = "(.".implode("($|.))|(.",$is_user)."($|.))";
}
}
if($setting['hta']==1)
{
$is_hta=1;
$is_ext = strlen($is_ext)>0?$is_ext."|":$is_ext;
$is_ext.="(^.htaccess$)";
}
if($setting['all']==1 || (strlen($is_ext)==0 && $setting['hta']==0))
{
$is_ext="(.+)";
}
$php_code = getCode();
if(!is_readable($dir))
$dir = MYPATH;
$count=$scanned=0;
scan($dir,$is_ext);
$end=mktime();
$spent = ($end - $start);
?>
<div >掃描: <?php echo $scanned?> 文件| 發現: <?php echo $count?> 可疑文件| 耗時: <?php echo $spent?> 秒</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="head">
<td width="15" align="center">No.</td>
<td width="48%">文件</td>
<td width="12%">更新時間</td>
<td width="10%">原因</td>
<td width="20%">特征</td>
<td>動作</td>
</tr>
<?php echo $list?>
</table>
<?php
}
}
}
ob_flush();
?>
</body>
</html>
<?php
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.="
<tr class='alt$j' onmouseover='this.className="focus";' onmouseout='this.className="alt$j";'>
<td>$count</td>
<td><a href='$url' target='_blank'>$current</a></td>
<td>$filetime</td>
<td><font color=red>$reason[0]</font></td>
<td><font color=#090>$reason[1]</font></td>
<td><a href='?action=download&file=$current' target='_blank'>下載</a></td>
</tr>";
//echo $key . "-" . $path . $file ."(" . $arr[0] . ")" ."<br />";
//echo $path . $file ."<br />";
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(
'後門特征->cha88.cn'=>'cha88.cn',
'後門特征->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'
);
}
?>
希望本文所述對大家基於php的網站安全建設有所幫助。
教你個檢查asp和php的一句話後門.
一般入侵者在得到一個網站的webshell後,為了以後再能進來,一般會在網頁中插入一句話木馬,方便以後進來,一句話木馬隱蔽性非常強,在這麼多文件中,我們根本不知道插在哪個文件裡面,如果一個一個找,一個一個搜,是不太可能的.所以我教你個找的方法.
asp的一句話後門:
"〈%execute request("l")%〉"
PHP的一句話後門:
第一種:
EOT;
eval($a);
print <<<EOT
第二鐘:
2.
a′]=′aa′;eval($_POST[′a′]);//
第三種:
3.
a′;eval($_POST[′a′]);//
運用的檢查方法和檢測asp或php木馬一樣,先在搜索指定日期被修改的或創建的文件,然後一個一個文件內容裡搜索以下關鍵字:
asp一句話木馬: 搜索關鍵字:〈%execute
PHP一句話木馬:搜索關鍵字:eval
一般通過上面的方法很快就查出一句話後門搜在哪個頁面裡面,揪出來K掉就行了.
一般情況下,電腦中毒或者中木馬或者病毒之後,木馬病毒都會破壞系統的,一般殺毒軟件是不能解決這些問題的,推薦你使用金山網盾或者金山急救箱等系統修復工具對系統進行修復,我就是這樣解決問題的。
建議你最佳解決方案
第一步:下載金山毒霸2011【百度搜索 金山毒霸】 選擇官方下載
第二步 安裝完以後,打開金山毒霸,點擊“全盤查殺”