0x00目的
为了更好的保证网站不被黑客非法篡改,我们需要对WEB目录实现目录防篡改的功能。
0x01使用工具和使用环境
1. 安装
192.168.1.131 内部发布服务器 发布WEB目录的服务器
192.168.1.132 外部服务器 对外服务的WEB服务器
2. 架构如下:
0x02配置指南
1. 在对外服务器上安装和 配置inotify-tools(支持阿里云服务器)
Centos: RPM包下载地址http://pkgs.repoforge.org/inotify-tools/
rpm -ivh inotify-tools-3.13-1.el6.rf.x86_64.rpm |
Unbuntu
apt-get install inotify-tools |
2.发布服务器上设置Rsyncd
rsyncd.conf
uid = nobodygid = nobody
max connections = 200 timeout = 600 use chroot = no read only = yes pid file = /var/run/rsyncd.pid host_allow = 192.168.1.0/24 [tongbu] path = /var/www/html comment = web |
3.对外服务器编写监控脚本
#!/bin/bashrsyncCommand=”rsync -vzrtopg –progress –delete 192.168.1.131::tongbu/ /var/www/html”
inotifyLog=/var/log/inotify.log inotifywait -mrq –timefmt ‘%d/%m/%y %H:%M’ –format ‘%T %w%f%e’ -e CLOSE_WRITE,create,delete,move,attrib /var/www/html \ |while read files do $rsyncCommand echo “Tongbu was rsynced!”>$inotifyLog done |
然后执行
sh inotify.sh &echo “sh /opt/inotify.sh &”>>/etc/rc.local |
4. 对外服务器执行crontab,每5分钟执行一次
*/5 * * * * rsync -vzrtopg –progress –delete 192.168.1.131::tongbu/ /var/www/html/ |
0x03 验证
1. 对外服务器上传webshell,触发inotify,自动同步发布服务器的内容,删除WEBSHELL。
2. 发布服务器发布内容,通过crontab每5分钟同步一次,会有一定延迟,如有需要可设小此值。
3. rsyncd一定要设置read-only选项,否则黑客可以上传本地文件到发布服务器。
文章转自阿里云安全