/** * @param $folder * @param $files */ function scanfiles($folder, &$files) { global $filesHash; $handle = opendir($folder); if (!$handle) { printf("Could not open folder: %s\n", $folder); return; } while (false !== ($file = readdir($handle))) { // Skip self and parent if ($file[0] == '.' || $file[0] == '..') { continue; } $path = "{$folder}/{$file}"; if (is_dir($path)) { scanfiles($path, $files); } else { $analysis = analyse_file_path($path); $files[] = $analysis; $filesHash[$path] = $analysis; } } }
function xxxx($dir) { //获取本文件目录的文件夹地址 $filesnames = scanfiles($dir); //获取也就是扫描文件夹内的文件及文件夹名存入数组 $filesnames foreach ($filesnames as $name) { if ($name == '.' || $name == '..') { continue; } //编码转换 gbk_encoding($name); } }
?> <div class="item">危险代码扫描结果</div> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table"> <tr class="thead"> <td>位置</td> <td>包含可疑内容</td> <td>行为描述</td> <td>最后修改时间</td> </tr> <?php if ($_POST["attachments"]) { echo '<tr class="band"><td colspan="1">上传附件</td><td colspan="3">位置:' . 'attach/' . '</td></tr>'; $result = scanfiles(VI_ROOT . 'attach'); if ($result) { echo $result; } else { echo '<tr class="choice"><td colspan="4"><img src="' . VI_BASE . 'static/image/icon/tick.png" /> 未发现异常</td></tr>'; } } if ($_POST["webshell"]) { echo ' <tr class="band"><td colspan="1">系统缓存中扫描 Webshell</td><td colspan="3">位置:' . 'cache/' . '</td></tr>'; $result = scanwebshell(VI_ROOT . 'cache'); if ($result) { echo $result; } else { echo '<tr class="choice"><td colspan="4"><img src="' . VI_BASE . 'static/image/icon/tick.png" /> 未发现异常</td></tr>'; }
function createFileNodes($doc, $resType, $dir, $subDir, $filters = '*.*', $prefix = '', $bDfs = false) { $full_dir = $dir . $subDir; if (!is_dir($full_dir)) { return null; } //建立过滤词典 $filterDict = array(); if ($filters != '*.*') { foreach (explode(';', $filters) as $filter) { $filter = pathinfo(trim($filter))['extension']; if ($filter != '') { $filterDict[$filter] = 1; } } } $n_dir = strlen($dir); //遍历文件夹下所有文件(参数bDfs决定是否递归遍历子文件夹) $filesnames = scanfiles($full_dir, $bDfs); if (empty($filesnames)) { return null; } $node = getNodeByResType($doc, $resType); foreach ($filesnames as $fname) { //文件名信息对象 $pi = pathinfo($fname); //文件全名(文件名+扩展名) $basename = $pi['basename']; //扩展名 $ext = $pi['extension']; //文件名 $name = $pi['filename']; if ($basename == '.' || $basename == '..') { continue; } if ($resType == 'uidef' && $basename != 'init.xml') { continue; } if ($resType != 'uidef' && $basename == 'init.xml') { continue; } if ($filters != '*.*' && !array_key_exists($ext, $filterDict)) { continue; } //修饰前缀 //按照约定俗成的习惯(soui、duivision、vc等),xml的资源一般不加前缀,除了init.xml要用xml_init修饰以外 //其他的比如图片、图标、翻译等资源都是加前缀的,这样就能根据名字区分资源的类型,写代码能清晰一些 // if($resType == 'UIDEF' && $basename == 'init.xml') { //init.xml需要加前缀xml // $prefix = 'xml'; // } // else if ($ext == 'xml') { // 如果xml文件,默认不加前缀 $prefix = ''; } // else if($prefix == '') { //如果没有指定,则以文件的扩展名作为前缀 // $prefix = $ext; // } //创建file节点 $node->appendChild(createFileNode($doc, substr($fname, $n_dir), $prefix)); } return $node; }