AIDE(高级入qin检测环境)是文件完整性检查程序和入qin检测程序。 node
当一个入qin者进入了你的系统而且种植了,一般会想办法来隐蔽这个(除了自身的一些隐蔽特性外,他会尽可能给你检查系统的过程设置障碍),一般入qin者会修改一些文件,好比管理员一般用ps aux来查看系统进程,那么入qin者极可能用本身通过修改的ps程序来替换掉你系统上的ps程序,以使用ps命令查不到正在运行的程序。若是入qin者发现管理员正在运行crontab做业,也有可能替换掉crontab程序等等。因此由此能够看出对于系统文件或是关键文件的检查是很必要的。目前就系统完整性检查的工具用的比较多的有两款:Tripwire和AIDE,前者是一款商业软件,后者是一款免费的但功能也很强大的工具。 linux
[root@CentOS7 ~]# yum -y install aide
/etc/aide.conf正则表达式
/etc/aide.conf 默认配置文件路径 /usr/sbin/aide 默认二进制可执行文件路径 /var/lib/aide 默认数据库文件路径 /var/log/aide 默认日志文件路径
`which aide` --init 执行完这步操做后会在默认数据库路径/var/lib/aide下产生一个名为“aide.db.new.gz”的数据库文件,/etc/aide.conf中定义的规则都写入到了该数据库文件中。
mv /var/lib/aide/aide.db{.new,}.gz 由于aide默认是从aide.db.gz数据库文件中读取/etc/aide.conf文件中定义的规则来检测文件完整性的,因此须要重命名初始化的库文件。
`which aide` --check
`which aide` --update 检测完须要更新文件数据库,不然下次检测仍是从旧的文件数据库中读取规则来检测文件的完整性。同时须要重命名数据库文件
# #p: permissions #i: inode: #n: number of links #u: user #g: group #s: size #b: block count #m: mtime #a: atime #c: ctime #S: check for growing size #acl: Access Control Lists #selinux SELinux security context #xattrs: Extended file attributes #md5: md5 checksum #sha1: sha1 checksum #sha256: sha256 checksum #sha512: sha512 checksum #rmd160: rmd160 checksum #tiger: tiger checksum #haval: haval checksum (MHASH only) #gost: gost checksum (MHASH only) #crc32: crc32 checksum (MHASH only) #whirlpool: whirlpool checksum (MHASH only)
规则定义格式:规则名 = 具体规则 【例】:TEST = a+m+c 规则使用格式:文件/目录 规则名 【例】:/dir1 TEST 注:若是在文件或目录前面加了“!”,则表示忽略检测
在/etc/aide.conf文件中定义以下规则,这里的/dir1目录刚开始是空的。 算法
TEST = a+c+m /dir1 TES
测试1: 数据库
在该目录下建立一个新的文件file1,并写入"hello aide" [root@CentOS7 ~]# aide --check AIDE, version 0.15.1 ### All files match AIDE database. Looks okay! [root@CentOS7 ~]# echo "hello aide" > /dir1/file1 [root@CentOS7 ~]# aide --check AIDE 0.15.1 found differences between database and filesystem!! Start timestamp: 2019-11-10 19:12:57 Summary: Total number of files: 3 Added files: 1 Removed files: 0 Changed files: 1 --------------------------------------------------- Added files: --------------------------------------------------- added: /dir1/file1 --------------------------------------------------- Changed files: --------------------------------------------------- changed: /dir1 --------------------------------------------------- Detailed information about changes: --------------------------------------------------- Directory: /dir1 Mtime : 2019-11-10 19:12:00 , 2019-11-10 19:12:55 Ctime : 2019-11-10 19:12:00 , 2019-11-10 19:12:55 以上输出表示在/dir1目录下添加了file1文件,而且修改了/dir1目录的Ctime和Mtime属性
测试2: 安全
将/dir1/file1文件的内容由"hello aide"修改成"hello world" [root@CentOS7 ~]# sed -i '/hello/c hello world' /dir1/file1 ; cat /dir1/file1 hello world [root@CentOS7 ~]# aide --check AIDE 0.15.1 found differences between database and filesystem!! Start timestamp: 2019-11-10 19:14:34 Summary: Total number of files: 3 Added files: 1 Removed files: 0 Changed files: 1 --------------------------------------------------- Added files: --------------------------------------------------- added: /dir1/file1 --------------------------------------------------- Changed files: --------------------------------------------------- changed: /dir1 --------------------------------------------------- Detailed information about changes: --------------------------------------------------- Directory: /dir1 Atime : 2019-11-10 19:12:02 , 2019-11-10 19:12:57 Mtime : 2019-11-10 19:12:00 , 2019-11-10 19:14:31 Ctime : 2019-11-10 19:12:00 , 2019-11-10 19:14:31 这时候/dir1目录的Atime,Mtime,Ctime都被修改了。