首先模拟出一个目录下面有三个配置文件,内容都同样!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