简介
AIDE(高级入 qin 检测环境) 是文件完整性检查程序和入 qin 检测程序.
特性
主要用途是检查文件的完整性, 审计计算机上哪些文件被更改过.
AIDE 根据从 / etc/aide.conf 配置文件中找到的正则表达式规则创建数据库. 初始化该数据库后, 就可以用来验证文件的完整性. 还可以检查所有通常的文件属性是否存在不一致. 它可以读取旧版本或更新版本的数据库. AIDE 数据库能够保存文件的各种属性, 包括: 权限 (permission), 索引节点序号 (inode number), 所属用户 (user), 所属用户组 (group), 文件大小, 最后修改时间 (mtime), 创建时间 (ctime), 最后访问时间 (atime), 增加的大小以及连接数. AIDE 还能够使用下列算法: sha1,md5,rmd160,tiger, 以密文形式建立每个文件的校验码或散列号.
这个数据库不应该保存那些经常变动的文件信息, 例如: 日志文件, 邮件,/proc 文件系统, 用户其实目录以及临时目录.
背景
当一个入 qin 者进入了你的系统并且种植了, 通常会想办法来隐蔽这个 (除了自身的一些隐蔽特性外, 他会尽量给你检查系统的过程设置障碍), 通常入 qin 者会修改一些文件, 比如管理员通常用 ps aux 来查看系统进程, 那么入 qin 者很可能用自己经过修改的 ps 程序来替换掉你系统上的 ps 程序, 以使用 ps 命令查不到正在运行的程序. 如果入 qin 者发现管理员正在运行 crontab 作业, 也有可能替换掉 crontab 程序等等. 所以由此可以看出对于系统文件或是关键文件的检查是很必要的. 目前就系统完整性检查的工具用的比较多的有两款: Tripwire 和 AIDE, 前者是一款商业软件, 后者是一款免费的但功能也很强大的工具.
操作步骤
安装
[root@CentOS7 ~]# yum -y install aide
修改配置文件
/etc/aide.conf
/etc/aide.conf 默认配置文件路径
/usr/sbin/aide 默认二进制可执行文件路径
/var/lib/aide 默认数据库文件路径
/var/log/aide 默认日志文件路径
初始化默认的 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
检测完需要更新文件数据库, 否则下次检测还是从旧的文件数据库中读取规则来检测文件的完整性. 同时需要重命名数据库文件
AIDE 默认规则
- #
- #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)
AIDE 规则定义及使用
规则定义格式: 规则名 = 具体规则
[例] :TEST = a+m+c
规则使用格式: 文件 / 目录 规则名
[例] :/dir1 TEST
注: 如果在文件或目录前面加了 "!", 则表示忽略检测
AIDE 规则验证
在 / 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 都被修改了.
来源: http://blog.51cto.com/hexiaoshuai/2449268