过去两天我们看到一个非常奇怪的情况。 在我们的网站 – 基于PHP / MySQL的 – 我们有以下情况 –
我们在public_html下有许多目录,全部由apache拥有。 这些目录具有所有的执行权限。
我们看到,这些目录的权限不断变化 – 执行不断被删除。 我们不知道为什么,这是什么? 显然,担心的是有人试图改变网站,使用Apache帐户(这是设置为nologin帐户)。
任何帮助,将不胜感激。
安装auditd (根据在这个答案中给出的信息)并用它来确定是什么改变了。 一旦你确定了什么是做出改变,那么你可以进入更多有趣的“如何”和“为什么”的问题。
您可以使用incron + inotify监视目录权限。
在public_html文件夹中设置监视以进行审计:
# auditctl -w /path/to/public_html -p warx
安装incron并创build一个configuration文件来监视public_html所有子目录:
find /path/to/public_html -type d -print0 | xargs -0 -I{} echo "{} IN_ATTRIB sendmail.sh" >> /etc/incron.d/webroot.conf
sendmail.sh包括一个简单的行如下:
#!/bin/bash echo "`date +%c`" | mail -s "someone has changed permission in public_html" [email protected]
每当有人更改权限,它会通过电子邮件发送给您。 通过ausearch -f /path/to/public_htmllogin到你的服务器并检查谁做了修改,你会看到类似这样的内容:
time->Mon Aug 8 01:12:41 2011 type=PATH msg=audit(1312740761.563:2279002): item=0 name="/var/www/html/awstats/" inode=1732554 dev=08:03 mode=040775 ouid=48 ogid=48 rdev=00:00 type=CWD msg=audit(1312740761.563:2279002): cwd="/var/www" type=SYSCALL msg=audit(1312740761.563:2279002): arch=c000003e syscall=90 success=yes exit=0 a0=14cb0d0 a1=1b4 a2=ffffffb6 a3=1b4 items=1 ppid=12660 pid=12901 auid=510 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=pts1 ses=360563 comm="chmod" exe="/bin/chmod" key=(null)
注意uid和gid 。