Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * 1. Сканируем всю корневую директорию +
- * 2. Ищем файлы без расширений и неизвестных форматов +
- * 3. Проверяем папки на содержимое в поисках вирусов
- * 4. Проверяем размеры файлов
- */
- class wpStructure{
- public static $data=array(
- "wp-admin"=>array(
- "type"=>"folder",
- "normalExt"=>array("htaccess","php"),
- "child"=>array(
- "css"=>array(
- "type"=>"folder",
- "normalExt"=>array("css"),
- "child"=>array(
- "colors"=>array(
- "type"=>"folder",
- "normalExt"=>array("scss"),
- "child"=>array()
- ),
- ),
- ),
- )
- ),
- );
- }
- class check{
- private static $data=array();
- private static $parentDir=".";
- private static $normalExt=array(
- "htaccess","md","db",
- "css","scss",
- "ico","png","jpg","jpeg","gif",
- "svg","psd","swf",
- "mp4","avi","mp3","ogg","wav",
- "js","php","txt","htm","html","rtf","pdf",
- "csv","xml","json","sql",
- "ini","dat","002","icc","crt","ds_store",
- "ttf","eot","woff","otf",
- "mo","po","pot","xap",
- "gz",
- );
- private static $badNames=array(
- "global",
- );
- private static $badWords=array(
- "eval","base64_decode","base64_encode","gzinflate","str_rot13","exec","mail"
- );
- private static $normalFiles=array("Makefile");
- private static $typeErrors=array(
- 1=>"Возможный вирус",
- 2=>"Неизвестный формат",
- );
- public static $errors=array();
- private static function parseSite($path,$isRoot=false){
- $pathFiles=scandir($path);
- foreach($pathFiles as $key=>$value){
- if(!in_array($value,array(".","..",".idea","@ban","parser.php"))){
- $file=explode(".",$value);
- if(count($file)==1 && !is_dir($path.$value) && !in_array($value,self::$normalFiles)){
- $fileData=pathinfo($path.$value);
- if(!isset($fileData["extension"])){
- $filename=$fileData["dirname"]."/".$fileData["filename"];
- $fileInfo=self::fileInfo($filename);
- self::setErrors($fileInfo,1);
- }
- }
- if(!isset($file[1]) && !$isRoot){
- $value=$path.$value;
- }else{
- if(count($file)>1){
- $ext=strtolower($file[count($file)-1]);
- if(!in_array($ext,self::$normalExt)){
- $fileInfo=self::fileInfo($value);
- self::setErrors($fileInfo,2);
- }
- }
- }
- if(is_dir($value)){
- $fullPath=$isRoot?"./{$value}/":"{$value}/";
- self::$data[$fullPath]=array();
- self::parseSite($fullPath);
- }else{
- $path=$isRoot?"./":$path;
- $fullPath=$path.$value;
- self::$data[$path][]=$fullPath;
- }
- }
- unset($key,$value);
- }
- }
- private static function fillArray($data){
- $outArray=array();
- foreach($data as $key=>$value){
- $keys=explode("/",$key);
- $keys=array_slice($keys,0,count($keys)-1);
- $outArray=self::setElements($outArray,$keys,$value);
- unset($key,$value);
- }
- return $outArray;
- }
- private static function setElements(&$array,$key,$value,$layer=1){
- $current=$key[$layer-1];
- if(!isset($array[$current])){
- $array[$current]=array();
- }
- if($layer==count($key)){
- $array[$current]=$value;
- }else{
- $array[$current]=self::setElements($array[$current],$key,$value,$layer+1);
- }
- return $array;
- }
- private static function setErrors($fileInfo,$type=null){
- if(!empty($type)){
- $fileInfo["type"]=self::$typeErrors[$type];
- }
- self::$errors[]=$fileInfo;
- }
- public static function setTable($isClosed=false){
- echo $isClosed?"</table>":"<table>";
- }
- public static function fileInfo($file){
- $fileInfo=array();
- $fileInfo["file"]=$file;
- $fileInfo["date"]=date ("d.m.Y H:i:s",filemtime($file));
- $fileInfo["chmod"]=substr(sprintf("%o",fileperms($file)),-4);
- return $fileInfo;
- }
- public static function getReport($type=1){
- self::parseSite(check::$parentDir,true);
- $objData=null;
- if($type==1){
- $objData=json_decode(json_encode(check::$data),false);
- }elseif($type==2){
- $objData=json_decode(json_encode(self::fillArray(check::$data)),false);
- }
- return check::$data;
- }
- }
- function preDump($data){
- echo "<meta charset=\"UTF-8\">";
- echo "<pre>";
- var_dump($data);
- echo "</pre>";
- }
- $outData=check::getReport();
- //if(!empty(check::$errors)){
- // preDump(check::$errors);
- //}
- //var_dump(check::getReport());
- foreach($outData as $key=>$files){
- foreach($files as $file){
- $data=explode(".",$file);
- if($data[count($data)-1]=="php"){
- $text=file($file);
- $firstStrings=array();
- if(isset($text[1]) && !in_array(trim($text[1]),array("/**","/*"))){
- for($i=0;$i<=5;){
- if(isset($text[$i])){
- $firstStrings[$i]=$text[$i];
- }
- $i++;
- }
- }
- if(!empty($firstStrings)){
- $firstStrings=join("<br />",$firstStrings);
- echo "<strong>{$file}</strong><br />";
- preDump($firstStrings);
- }
- }
- unset($file);
- }
- unset($key,$files);
- }
Add Comment
Please, Sign In to add comment