shell检测系统文件完整性
今天发现个可以检测系统文件完整性的shell脚本,自己试了下还可以吧,推授给大家.
系统:centos 5.x
脚本内容:
cat my_filecheck.sh
执行脚本:
./my_filecheck.sh
进行校验:
md5sum -c fp.20141205160628.chksum
如下:
md5sum -c fp.20141209202544.chksum
/bin/gawk: OK
/bin/igawk: OK
/bin/ln: OK
/bin/loadkeys: OK
/bin/gzip: OK
/bin/mkdir: OK
/bin/date: OK
/bin/cat: OK
/bin/mountpoint: OK
/bin/taskset: OK
/bin/umount: OK
/bin/mount: OK
/bin/doexec: OK
/bin/kill: OK
/bin/sync: OK
/bin/unicode_start: OK
/bin/usleep: OK
/bin/mknod: OK
/bin/setserial: OK
/bin/cp: OK
/bin/mktemp: OK
/bin/setfont: OK
/bin/unicode_stop: OK
.....
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/cast5.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/crypto_blkcipher.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/twofish.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/authenc.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/cbc.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/crypto_hash.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/seqiv.ko: OK
/lib/libproc-3.2.7.so: OK
/lib/libacl.so.1.1.0: OK
/lib/libauparse.so.0.0.0: OK
/lib/libdmraid.so.1.0.0.rc13-17: OK
/lib/libvolume_id.so.0.66.0: OK
/lib/libgobject-2.0.so.0.1200.3: OK
/lib/libnss_compat-2.5.so: OK
/lib/rtkaio/i686/nosegneg/librtkaio-2.5.so: OK
/lib/rtkaio/librtkaio-2.5.so: OK
/lib/libdmraid-events-isw.so.1.0.0.rc13: OK
/lib/libdevmapper-event-lvm2snapshot.so.2.02: OK
/lib/libblkid.so.1.0: OK
/lib/libdb-4.3.so: OK
/lib/libSegFault.so: OK
/lib/libiw.so.28: OK
/lib/libdmraid-events-isw.so.1.0.0.rc13-17: OK
可以看到很多OK.
如果只想看到错误的话,可以用下面这个命令:
md5sum -c fp.20141209202544.chksum |grep -v "OK"
我的系统没有报错的,所以没有办法给大家结果.
ps:http://diudiu.blog.51cto.com/6371183/1586734
系统:centos 5.x
脚本内容:
cat my_filecheck.sh
#!/bin/bash # # 变量首先声明才能使用 shopt -s -o nounset # 声明 # 建立日期 Date=$(date +'%Y%m%d%H%M%S') # 加入审核的目录 # Dirs="/bin /sbin /usr/bin /usr/sbin /lib /usr/local/sbin /usr/local/bin /usr/local/lib" # 临时文件 # TMP_file=$(mktemp /tmp/check.XXXXXX) # 文件checksum存储文件 FP="/root/fp.$Date.chksum" # 使用哪种checksum工具 Checker="/usr/bin/md5sum" Find="/usr/bin/find" # 函数区 # scan_file() { local f for f in $Dirs do $Find $f -type f >> $TMP_file done } # 读取文件建立每个文件的checksum值 cr_checksum_list() { local f if [ -f $TMP_file ]; then for f in $(cat $TMP_file); do $Checker $f >> $FP done fi } rmTMP() { [ -f $TMP_file ] && rm -rf $TMP_file } # 主程序区 # 扫描列表 scan_file # 建立文件的checksum值 cr_checksum_list # 清理临时文件 rmTMP
执行脚本:
./my_filecheck.sh
进行校验:
md5sum -c fp.20141205160628.chksum
如下:
md5sum -c fp.20141209202544.chksum
/bin/gawk: OK
/bin/igawk: OK
/bin/ln: OK
/bin/loadkeys: OK
/bin/gzip: OK
/bin/mkdir: OK
/bin/date: OK
/bin/cat: OK
/bin/mountpoint: OK
/bin/taskset: OK
/bin/umount: OK
/bin/mount: OK
/bin/doexec: OK
/bin/kill: OK
/bin/sync: OK
/bin/unicode_start: OK
/bin/usleep: OK
/bin/mknod: OK
/bin/setserial: OK
/bin/cp: OK
/bin/mktemp: OK
/bin/setfont: OK
/bin/unicode_stop: OK
.....
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/cast5.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/crypto_blkcipher.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/twofish.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/authenc.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/cbc.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/crypto_hash.ko: OK
/lib/modules/2.6.18-194.el5PAE/kernel/crypto/seqiv.ko: OK
/lib/libproc-3.2.7.so: OK
/lib/libacl.so.1.1.0: OK
/lib/libauparse.so.0.0.0: OK
/lib/libdmraid.so.1.0.0.rc13-17: OK
/lib/libvolume_id.so.0.66.0: OK
/lib/libgobject-2.0.so.0.1200.3: OK
/lib/libnss_compat-2.5.so: OK
/lib/rtkaio/i686/nosegneg/librtkaio-2.5.so: OK
/lib/rtkaio/librtkaio-2.5.so: OK
/lib/libdmraid-events-isw.so.1.0.0.rc13: OK
/lib/libdevmapper-event-lvm2snapshot.so.2.02: OK
/lib/libblkid.so.1.0: OK
/lib/libdb-4.3.so: OK
/lib/libSegFault.so: OK
/lib/libiw.so.28: OK
/lib/libdmraid-events-isw.so.1.0.0.rc13-17: OK
可以看到很多OK.
如果只想看到错误的话,可以用下面这个命令:
md5sum -c fp.20141209202544.chksum |grep -v "OK"
我的系统没有报错的,所以没有办法给大家结果.
ps:http://diudiu.blog.51cto.com/6371183/1586734
执行:my_filecheck.sh
md5sum -c fp.20150119165245.chksum |grep -v "OK" 没问题
mv /sbin/iptables /usr/games/
再次执行 my_filecheck.sh
md5sum -c fp.20150119165856.chksum |grep -v "OK" 依然没问题
很显然 /sbin 下的 iptables 文件丢失了 可是好像没发现丢失呢
我想知道 是我打开的方式不对么 呵呵
万谢 告知