网站木马文件查找之-列出2023年网站根目录下以及子目录所有php文件
本代码适合查找网站挂马(木马)文件使用
<?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";
}
?>
如果php版本低于5.5 请使用下面的代码
<?php
function listPhpFiles($directory)
{
$fileList = array();
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php' && date('Y', $file->getMTime()) === '2023') {
$fileList[] = array(
'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";
}
?>