如何解决我如何确定正在使用fopen的脚本?
| 我的网站被脚本小子袭击得非常成功。自动地,在我的服务器上访问一个隐藏的脚本,该脚本导致修改了我所有的index.php文件,并在它们的顶部添加了iframe(以64为基数编码)。 我很难让我的托管服务提供商提供帮助,因为他们说他们在这件事上很无奈。 我怀疑如果可以确定哪些脚本正在使用php的fopen函数,那么我将能够发现主篡改脚本的位置并将其删除。 有什么建议吗?解决方法
使用ѭ0来查找所有PHP脚本,然后使用grep进行fopen。如果您没有外壳程序访问权限,请下载包含脚本的整个目录,然后在计算机上执行此操作。
find /base/dir/with/your/scripts -name \'*.php\' | xargs grep \'fopen\'
, 下一步
关闭一切
重新设置服务器
一点一点地分析代码,找出漏洞。
保持被黑客入侵的服务器运行是不负责任的。除了更改index.php文件外,还可能安装了真正的恶意工具-同时,您的服务器可能是犯罪分子的开放代理。
开张
除了fopen之外,还有十几种从PHP内部更改文件的方法。例子
file_put_contents
move_uploaded_file
exec(\'echo foo > /path/to/bar\')
与系统相同,passthru,shell_exec,proc_open
如果真的很开心,那您很幸运。
, 我仍在使用grep和ssh访问来发现和清除问题。可能是代替嵌入式脚本重写我的文件,而是由站点上某处的输入表单执行php代码。我还不确定。同时,我已经编写了一个脚本来打击对eval(base64_decode注入到我的index.php文件中的注入。这会检查并删除index.php文件中的eval(base64_decode(\'\');)并搜索我的文件结构到5个目录级别,这对我的网站来说足够了,我将其设置为每5分钟在cronjob上运行一次,这似乎完全不需要服务器。
<?php
$level=5;
function get_sorted($path)
{
//$ignore = array(\'.\',\"\'\",\"error_log\");
$dh = @opendir( $path );
while ($file = @readdir( $dh ))
{
if (!strstr($file,\'.\')&&!strstr($file,\"\'\")&&!strstr($file,\"error_log\")&&!strstr($file,\"README\")&&!strstr($file,\"cookietxt\")&&$file!=\'.\'&&$file!=\'..\')
{
$directories[] = $file;
}
else
{
if ($file!=\'.\'&&$file!=\'..\')
{
$files[] = $file;
}
}
}
$array = array($directories,$files);
return $array;
}
function clean_files($files,$path)
{
//echo 1;exit;
if ($files)
{
foreach($files as $key=>$val)
{
//echo $val;
if ($val == \'index.php\')
{
//echo 1; exit;
//fopen .htacess
$targetFile = \"$path/$val\";
echo \"Checking: $targetFile <br>\";
$handle1 = fopen($targetFile,\'r\');
$data = @fread($handle1,filesize($targetFile));
fclose($handle1);
$string = preg_match(\'/eval.base64_decode(.*?)\\;/\',$data,$matches );
$string = $matches[0];
if ($string)
{
echo \"MALWARE FOUND IN $targetFile ! ... rewriting!<br>\";
$data = str_replace($string,\'\',$data);
$handle1 = fopen($targetFile,\'w\');
fwrite($handle1,$data);
fclose($handle1);
//exit;
}
unset($string);
unset($data);
}
}
}
else
{
echo \"<br>No files discovered in $path<br>\";
}
}
//clean first level
$array = get_sorted(\'.\');
$directories = $array[0];
$files = $array[1];
clean_files($files,\'.\');
//get second level & clean
foreach ($directories as $key=>$val)
{
$p_1 = \"./$val\";
$a_1 = get_sorted($val);
$d_1 = $a_1[0];
$f_1 = $a_1[1];
//echo $val;
//print_r($d_1);
//echo \"<hr>\";
clean_files($f_1,\"{$p_1}\");
//check and clean level 2
if ($d_1)
{
foreach ($d_1 as $k_1=>$v_1)
{
//echo $v_1;exit;
$p_2 = $p_1.\'/\'.$v_1;
$a_2 = get_sorted($p_2);
$d_2 = $a_2[0];
$f_2 = $a_2[1];
clean_files($f_2,$p_2);
if ($d_2)
{
//check and clean level 3
foreach ($d_2 as $k_2=>$v_2)
{
$p_3 = $p_2.\'/\'.$v_2;
//echo $p_3;
$a_3 = get_sorted($p_3);
$d_3 = $a_3[0];
$f_3 = $a_3[1];
//echo\"<hr>$v_2\";
//print_r($f_3);exit;
clean_files($f_3,$p_3);
//unset($
}
//check and clean level 4
if ($d_3)
{
foreach ($d_3 as $k_3=>$v_3)
{
$p_4 = $p_3.\'/\'.$v_3;
$a_4 = get_sorted($p_4);
$d_4 = $a_4[0];
$f_4 = $a_4[1];
clean_files($f_4,$p_4);
}
//check and clean level 5
if ($d_4&&$level==5)
{
foreach ($d_4 as $k_4=>$v_4)
{
$p_5 = $p_4.\'/\'.$v_4;
$a_5 = get_sorted($p_5);
$d_5 = $a_5[0];
$f_5 = $a_5[1];
clean_files($f_5,$p_5);
}
}
}
}
}
}
}
?>
如果您遇到类似的问题并尝试运行此脚本,请小心。它将删除index.php文件中所有的eval(base64_encode脚本是否为恶意文件或不是恶意文件。您还可以编辑preg_match表达式以定位其他自然注入。您还可以使用此代码定位index.php以外的文件
, Grep可能是您的朋友之一。开始猜测,看看是否有异常情况出现。
我还将仔细检查所有日志,以查看是否可以确定攻击的来源。您至少可以在短期内通过IP阻止攻击。查看文件上的日期可能可以告诉您最后一次访问该文件的位置。
另外,请勿排除JavaScript注入。他们可以用它来做一些相当卑鄙的事情,在页面底部看起来像一堆乱码。
显然,更改密码以包含任何数据库。更新所有开源软件,因为这通常是这些人的入门方式。您甚至可以尝试将代码所有权更改为其他用户。任何在下次尝试帮助跟踪有问题的代码时都会弹出错误的信息。
而且,我会考虑寻找新的主机...。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。