本代码适合查找网站挂马(木马)文件使用
<?php
function listPhpFiles($directory)
{
$fileList = [];
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php' && date('Y', $file->getMTime()) === '2023') {
$fileList[] = [
'path' => $file->getPathname(),
'modified' => $file->getMTime()
];
}
}
usort($fileList, function ($a, $b) {
return $b['modified'] - $a['modified'];
});
return $fileList;
}
// 列出网站根目录下以及所有子栏目中2023年修改的PHP文件
$rootDirectory = $_SERVER['DOCUMENT_ROOT'];
$phpFiles = listPhpFiles($rootDirectory);
// 输出文件列表
foreach ($phpFiles as $file) {
echo $file['path'] . ' - ' . date('Y-m-d H:i:s', $file['modified']) . "\n";
}
?>
标签:文件,网站,modified,file,2023,根目录 From: https://www.cnblogs.com/yuesha/p/17544377.html