首先模擬出一個目錄下面有三個配置文件,內容都同樣!mysql
[root@rhelX64 test]# ll 總用量 12 -rw-r--r-- 1 root root 95 12月 4 12:26 apache.conf -rw-r--r-- 1 root root 95 12月 4 12:26 mysql.conf -rw-r--r-- 1 root root 95 12月 4 12:25 nginx.conf
[root@rhelX64 test]# cat nginx.conf this is one line. this is two line. this is three line. this is four line. this is five line.
用MD5作標記,寫入conf.log文件nginx
[root@rhelX64 test]# cat /mnt/conf.log 105256b35aa4a08e18378b66be607c7f apache.conf 105256b35aa4a08e18378b66be607c7f mysql.conf 105256b35aa4a08e18378b66be607c7f nginx.conf
沒有改動文件,咱們來看看測試結果!sql
[root@rhelX64 test]# md5sum -c /mnt/conf.log apache.conf: 肯定 mysql.conf: 肯定 nginx.conf: 肯定
改動nginx文件,看看經過「指紋」文件,是否能夠報警?apache
[root@rhelX64 test]# echo "this is six line." >> nginx.conf [root@rhelX64 test]# md5sum -c /mnt/conf.log apache.conf: 肯定 mysql.conf: 肯定 nginx.conf: 失敗 md5sum: 警告:1/3 生成的校驗和不匹配
能夠看到,nginx失敗,表示已經被篡改文件,下面經過一個腳原本監控配置文件。bash
#!/bin/bash #created by sanpang #email:zyjqianfuyu@163.com #home:lovers.blog.51cto.com #qq:791880666 #function This script is used to monitor if the file is a malicious changes # Source function library. . /etc/rc.d/init.d/functions if [ -e "/mnt/conf.log" ]; then md5sum -c /mnt/conf.log else md5sum /test/*.conf > /mnt/conf.log md5sum -c /mnt/conf.log fi