情景模擬題
請依照下面的方式來創建你係統的重要文件校驗值,並每日進行比對。
- 將 /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