Rumah > pembangunan bahagian belakang > tutorial php > php木马webshell扫描器代码_PHP教程

php木马webshell扫描器代码_PHP教程

WBOY
Lepaskan: 2016-07-21 15:21:20
asal
1262 orang telah melayarinya

复制代码 代码如下:

/*
+--------------------------------------------------------------------------+
| Codz by indexphp Version:0.01 |
| (c) 2009 indexphp |
| http://www.indexphp.org |
+--------------------------------------------------------------------------+
*/
/*===================== 程序配置 =====================*/
$dir='cms'; //设置要扫描的目录
$jumpoff=false;//设置要跳过检查的文件
$jump='safe.php|g'; //设置要跳过检查的文件或者文件夹 $jumpoff=false 时此设置有效
$danger='eval|cmd|passthru';//设置要查找的危险的函数 以确定是否木马文件
$suffix='php|inc';//设置要扫描文件的后缀
$dir_num=0;
$file_num=0;
$danger_num=0;
/*===================== 配置结束 =====================*/
extract (GetHttpVars());
if ($m=="edit") Edit();
if ($m=="del") Delete();
if ($check=='check')
{ $safearr = explode("|",$jump);
$start_time=microtime(true);
safe_check($dir);
$end_time=microtime(true);
$total=$end_time-$start_time;
$file_num=$file_num-$dir_num;
$message= " 文件数:".$file_num;
$message.= " 文件夹数:".$dir_num;
$message.= " 可疑文件数:".$danger_num;
$message.= " 执行时间:".$total;
echo $message;
exit();
}
function GetHttpVars() {//全局变量
$superglobs = array(
'_POST',
'_GET',
'HTTP_POST_VARS',
'HTTP_GET_VARS');
$httpvars = array();
foreach ($superglobs as $glob) {
global $$glob;
if (isset($$glob) && is_array($$glob)) {
$httpvars = $$glob;
}
if (count($httpvars) > 0)
break;
}
return $httpvars;
}
function Safe_Check($dir)//遍历文件
{
global $danger ,$suffix ,$dir_num ,$file_num ,$danger_num;
$hand=@dir($dir) or die('文件夹不存在') ;
while ($file=$hand->read() )
{
$filename=$dir.'/'.$file;
if (!$jumpoff) {
if(Jump($filename))continue;
}
if(@is_dir($filename) && $file != '.' && $file!= '..'&& $file!='./..')
{ $dir_num++;
Safe_Check($filename);
}
if (preg_match_all ("/\.($suffix)/i",$filename,$out))
{
$str='';
$fp = @fopen($filename,'r')or die('没有权限');
while(!feof($fp))
{
$str .= fgets($fp,1024);
}
fclose($fp);
if( preg_match_all ("/($danger)[ \r\n\t]{0,}([\[\(])/i",$str,$out))
{
echo "可疑文件:{$filename}
查看代码
删除
";
$danger_num++;
}
}
$file_num++;
}
}
function Edit()//查看可疑文件
{
global $filename;
$filename = str_replace("..","",$filename);
$file = $filename;
$content = "";
if(is_file($file))
{
$fp = fopen($file,"r")or die('没有权限');
$content = fread($fp,filesize($file));
fclose($fp);
$content = htmlspecialchars($content);
}
echo "\r\n";
exit();
}
function Delete()//删除文件
{
global $filename;
(is_file($filename))?($mes=unlink($filename)?'删除成功':'删除失败 查看权限'):'';
echo $mes;
exit();
}
function Jump($file)//跳过文件
{
global $jump,$safearr;
if($jump != '')
{
foreach($safearr as $v)
{
if($v=='') continue;
if( eregi($v,$file) ) return true ;
}
}
return false;
}
?>




www.bkjia.comtruehttp://www.bkjia.com/PHPjc/324899.htmlTechArticle复制代码 代码如下: ?php /* +--------------------------------------------------------------------------+ | Codz by indexphp Version:0.01 | | (c) 2009 indexphp | | http://www...
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan