zoukankan      html  css  js  c++  java
  • php简单的查找当前目录下的非法文件

    <?php
    	/**
    	*只遍历当前目录下的文档
    	*@return 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;
    ?>
    
  • 相关阅读:
    HDU-1115计算几何
    树形DP入门之HDU 1296
    拓扑排序-POJ1964
    其他一些数状数组的题
    HDU 2852(树状数组plus二分)
    POJ-2155二维树状数组
    HDOJ 1166 敌兵布阵 (线段树)
    codevs 1082 线段树练习3 (线段树)
    codevs 1081 线段树练习2 (线段树)
    codevs 1080 线段树练习(线段树)
  • 原文地址:https://www.cnblogs.com/phplhs/p/4167132.html
Copyright © 2011-2022 走看看