【发布时间】:2014-03-06 19:08:26
【问题描述】:
我将如何继续编写一个程序来查找我的所有第一行或第二行包含 N 个以上字符的 php 文件?我想显示文件名和行内容
我可以用这个逐个文件:
<html><head><title>Find String</title></head><body>
<?php
find_files('.');
function find_files($seed) {
if(! is_dir($seed)) return false;
$files = array();
$dirs = array($seed);
while(NULL !== ($dir = array_pop($dirs)))
{
if($dh = opendir($dir))
{
while( false !== ($file = readdir($dh)))
{
if($file == '.' || $file == '..') continue;
$path = $dir . '/' . $file;
if(is_dir($path)) { $dirs[] = $path; }
else { if(preg_match('/^.*\.(php[\d]?)$/i', $path)) { check_files($path); }}
}
closedir($dh);
}
}
}
function check_files($this_file){
if(!($content = file_get_contents($this_file)))
{ echo("<p>Could not check $this_file You should check the contents manually!</p>\n"); }
else
{
// What to do here??
}
unset($content);
}
?>
</body></html>
【问题讨论】:
-
这是现实世界的要求吗? :-)
-
@Dagon 你是什么意思?我已经在我的 php 文件中注入了代码,通常内容是在第一行或第二行中注入的......
-
@HommerSmith 你不知道还有什么被注入或改变,也不知道在哪里。唯一明智的做法是删除所有内容并从干净的备份中恢复。之后,修补您的软件以堵住攻击的漏洞。
-
如果这不是解决问题的方法,请从备份中恢复。你不能确定你会使用这种方法获得所有注入的代码。
-
我知道我需要从备份中恢复。我责怪服务器上说“没有备份”的人。谢谢你们的建议。