php 非法 获取网站 目录,php简单的查找当前目录下的非法文件

/**

*只遍历当前目录下的文档

[email protected] bool

*/

$new = microtime();

function read_all_file($path)

{

if(empty($path))

{

return false;

}

$path = rtrim($path,‘/‘);

static $file_arr = array();

if(! is_readable($path))

{

echo $path.‘无权限读取文件或文件夹不存在‘;

return false;

}

//$oldtime = strtotime(‘2014-12-12‘);

$new_path = ‘‘;$x = ‘‘;$ext = ‘‘;$content = ‘‘;

if($handler = opendir($path))

{

while (($sub = readdir($handler)) !== FALSE)

{

if ($sub != "." && $sub != ".." && $sub != "Thumb.db" && $sub != "Thumbs.db")

{ $new_path = $path."/".$sub;

if(is_file($path."/".$sub))

{

$x = explode(‘.‘, $new_path);

$ext = strtolower(end($x));

if($ext == ‘php‘ || $ext == ‘asp‘)

{

$content = file_get_contents($new_path);

$time = filemtime($new_path);

//记录非法文件位置

if(preg_match(‘/eval|cmd|system|exec|fopen|file_put_contents/i‘,$content)){

file_put_contents(‘gua.txt‘,$new_path.PHP_EOL, FILE_APPEND);

}

/*if($time>$oldtime){

file_put_contents(‘gua-date.txt‘,$new_path.PHP_EOL, FILE_APPEND);

}*/

unset($content);

}

else

{

continue;

}

}

/*else //如果是文件夹输出文件名称继续

{

//read_all_file($path."/".$sub);

}*/

}

}

}

closedir($handler);

}

read_all_file(dirname(__FILE__).‘/phpcms‘);

echo microtime() - $new;

?>

原文:http://www.cnblogs.com/phplhs/p/4167132.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值