介绍
AIDE(高级入侵检测环境)是一个入侵检测工具,主要用途是检查文本的副本。AIDE能够构造一个指定文档的数据库,使用aide.conf作为配置文档。AIDE数据库能够保存文档的各部分种属性,包括:权限(permission),索引序号(索引号),所属用户(user),所属用户组(group),文档大小,最后修改时间(mtime),创建时间(ctime),最后访问时间(atime的),增加的大小连同连接数.AIDE使用下列算法:SHA256,SHA512,rmd160,HAVAL,GOST,CRC32,虎,以密文形式建立每个文档的校验码或散列号
AIDE是用以代替收费商业版软件tripwire的一款新产品。
文件系统入侵检测的原理:
1,当系统处于健康状态时,把系统所有的文件做各种指纹的检验,得出一个检验基准数据库。
2,不是所有的文件都需要保存指纹,临时文件(/ var / log | / tmp | / var / tmp | / proc | / sys | / dev / shm ...)
3,需要检验文件是否被更改,只需要把基准数据对应指纹值做对比,就可以发现某些文件被更改过。
4,每天把检验的结果以邮件或其他方式发送管理员。
安装
# 安装
yum install -y aide
# 初始化数据库
aide --init
# 首次生成的文件是aide.db.new.gz 需要更改为 aide.db.gz
#名字默认是 /etc/aide.conf 的database 和 database_out
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
常用命令
#检查配置文件
aide -D
# 检查文件是否被篡改
aide --check 或 aide -C
# --update 命令会生成一个aide.db.new.gz文件,需要删除 .new字符串替换原本的aide.db.gz文件
aide --update
# 把报告发到邮箱
# aide -c --check |mail -s "test aide" root@localhost
日常使用
常规检查
1.使用 aide --check 命令,检查被修改的文件是否正常.
2.如果没有异常,则使用 aide --update 生成 aide.db.new.gz文件
并且替换基准数据
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
定期执行?
更改配置文件.生成新的基准数据
1.使用 aide --init命令生成 aide.db.new.gz文件.
2.替换 基准数据库
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
匹配规则配置【例】
# 匹配规则是正则表达式.
# 忽略nginx
!/usr/local/nginx/logs/.*
# 忽略 tomcat 日志
!/usr/local/tomcats/.*/logs/.*
# 忽略一些临时文件
!/usr/local/tomcats/.*/temp/.*
#/usr/local/tomcats/.*/webapps/.*
!/usr/local/tomcats/.*/work/.*
原始配置文件说明
#定义数据库文件夹
@@define DBDIR /var/lib/aide
#定义日志文件夹
@@define LOGDIR /var/log/aide
# The location of the database to be read.
# 基准数据库文件
database=file:@@{DBDIR}/aide.db.gz
# The location of the database to be written.
#database_out=sql:host:port:database:login_name:passwd:table
#database_out=file:aide.db.new
# 更新数据库文件
database_out=file:@@{DBDIR}/aide.db.new.gz
# Whether to gzip the output to database.
# 开启gzip 压缩
gzip_dbout=yes
# Default.
verbose=5
#日志地址
report_url=file:@@{LOGDIR}/aide.log
report_url=stdout
FIPSR = p+i+n+u+g+s+m+c+acl+selinux+xattrs+sha256
#R: p+i+n+u+g+s+m+c+acl+selinux+xattrs+md5
#L: p+i+n+u+g+acl+selinux+xattrs
#E: Empty group
#>: Growing logfile p+u+g+i+n+S+acl+selinux+xattrs
# You can create custom rules like this.
# With MHASH...
# ALLXTRAHASHES = sha1+rmd160+sha256+sha512+whirlpool+tiger+haval+gost+crc32
ALLXTRAHASHES = sha1+rmd160+sha256+sha512+tiger
# Everything but access time (Ie. all changes)
EVERYTHING = R+ALLXTRAHASHES
# Sane, with one good hash.
# NORMAL = sha256
NORMAL = sha256
# For directories, don't bother doing hashes.
DIR = p+i+n+u+g+acl+selinux+xattrs
# Access control only.
PERMS = p+u+g+acl+selinux+xattrs
# Access + inode changes + file type.
STATIC = p+u+g+acl+selinux+xattrs+i+n+b+c+ftype
# Logfiles only check access w/o xattrs.
LOG = p+u+g+n+acl+selinux+ftype
# Content + file type.
CONTENT = sha256+ftype
# Extended content + file type + access.
CONTENT_EX = sha256+ftype+p+u+g+n+acl+selinux+xattrs
DATAONLY = p+n+u+g+s+acl+selinux+xattrs+sha256
# Next decide what directories/files you want in the database. Aide
# uses a first match system. Put file specific instructions before generic
# matches. e.g. Put file matches before directories.
/boot/ CONTENT_EX
/bin/ CONTENT_EX
/sbin/ CONTENT_EX
/lib/ CONTENT_EX
/lib64/ CONTENT_EX
/opt/ CONTENT
# Admin's dot files constantly change, just check perms.
/root/\..* PERMS
# Otherwise get all of /root.
/root/ CONTENT_EX
# These are too volatile.
!/usr/src/
!/usr/tmp/
# Otherwise get all of /usr.
/usr/ CONTENT_EX
# Check only permissions, user, group, seliunx for /etc, but
# cover some important files closely.
!/etc/mtab$
# Ignore backup files
!/etc/.*~
# 其他的不在复制
参考