Home >Backend Development >PHP Tutorial >Summary of repair methods for Trojans hanging on PHP websites_PHP Tutorial
Repairing a PHP website with Trojans is secondary. The most important thing is how to prevent Trojans from injecting into your website after repairing it. Next, I will summarize the repair of PHP websites with Trojans and preventing the website in the future. Give me the method of hanging Trojan again.
In Linux, we can use commands to search for Trojan files. Go to the code installation directory and execute the following command
The code is as follows | Copy code | ||||
|
Nearly 100 results were found. This list of results is very important. Trojans are all in it. You need to open the files one by one to verify whether they are Trojans. If so, delete them immediately
Finally, 10 Trojan files were found, stored in various directories, all of which are php webshells with complete functions and encoded in base64
If you are looking for a directory in Windows, just use Windows file search. You can search for eval or recently modified files. Then if it is dedecms, we need to check the latest dedecms vulnerability and then patch it.
Here is a PHP Trojan search tool, which can be placed directly in the root directory of your site
The code is as follows | Copy code | ||||||||
/**************PHP Web Trojan Scanner***********************/ /* [+] Author: alibaba */ /* [+] QQ: 1499281192 * www.bKjia.c0m/ /* [+] MSN: weeming21@hotmail.com */ /* [+] First published: t00ls.net, please indicate t00ls when reprinting */ /* [+] Version: v1.0 */ /* [+] Function: web version php Trojan scanning tool*/ /* [+] Note: The scanned files are not necessarily backdoors, */ /* Please judge, review and compare the original documents by yourself. */ /* If you are not sure whether the scanned file is a backdoor, */ /* You are welcome to send this file to me for analysis. */ /*******************************************************/ ob_start(); set_time_limit(0); $username = "t00ls"; //Set username $password = "t00ls"; //Set password $md5 = md5(md5($username).md5($password)); $version = "PHP Web Trojan Scanner v1.0";
PHP Web Trojan Scanner $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']); ?> 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;}
if(!(isset($_COOKIE['t00ls']) && $_COOKIE['t00ls'] == $md5) && !(isset($_POST['username']) && isset($_POST[' password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5))) { echo ' ';} elseif(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password'] ))==$md5)) { setcookie("t00ls", $md5, time()+60*60*24*365,"/"); echo "Login successful!"; 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(); } ?>
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(); } ?>
} else { $dir = isset($_POST['path'])?$_POST['path']:MYPATH; $dir = substr($dir,-1)!="/"?$dir."/":$dir; ?>
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); ?> 扫描: 文件| 发现: 可疑文件| 耗时: 秒
} } } 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.=" | |||||||||
$count | $current | $filetime | $reason[0] | $reason[1] | 下载 |