情景模拟题
请依照下面的方式来创建你系统的重要文件校验值,并每日进行比对。
- 将 /etc/{passwd,shadow,group} 以及系统上面所有的 SUID/SGID 文件建立文件列表,该列表文件名为 important.file
ls /etc/{passwd,shadow,group} > important.file
find /usr/sbin /usr/bin -perm /6000 >> important.file
- 通过这个文件名列表,以名为 md5.checkfile.sh 的文件名去建立校验值,并将该校验值文件 finger1.file 设置成不可修改的属性
vim md5.checkfile.sh
#! /bin/bash
for filename in $ (cat important.file)
do
md5sum $filename >> finger1.file
done
sh md5.checkfile.sh
chattr +i finger1.file
- 通过相同的机制去建立后续的分析数据为 finger_new.file,并将两者进行比对,若有问题则发生 email 给 root :
vim md5.checkfile.sh
#! /bin/bash
if ["$1" == "new"]; then
for filename in $ (cat important.file)
do
md5sum $filename >> finger1.file
done
echo "New file finger1.file is created."
exit 0
fi
if [! -f finger1.file]; then
echo "file: finger1.file NOT exist."
exit 1
fi
[-f finger_new.file] && rm finger_new.file
for filename in $ (cat important.file)
do
md5sum $filename >> finger1.file
done
testing = $(diff finger1.file finger_new.file)
if ["$testing" != ""]; then
diff finger1.file finger_new.file | mail -s 'finger trouble..' root
fi
vim /etc/crontab
30 2 * * * cd/root; sh md5.checkfile.sh