安装
1. 安装git
sudo apt-get update
sudo apt-get install git
2. clone aide源码
git clone https://github.com/aide/aide.git
这将在当前目录下创建一个名为aide的目录,并把代码下载到这个目录中
3. 安装依赖库
sudo apt-get install gcc
sudo apt-get install autoconf automake flex bison make pkg-config
sudo apt-get install autoconf-archive
sudo apt-get install libpcre2-dev
sudo apt-get install libnettle-dev libgcrypt-dev
sudo apt-get install libcheck-dev
这块如果有依赖库没有安装,会报杂七杂八的错,但不会告诉你是哪个依赖库少了。以上依赖库是我尝试我自己需要安装的,但是可能不全面,需要安装报错过程中自己排查。
4. 生成配置文件
cd aide
./autogen.sh
期间报错
configure.ac:19:error:possibly undefined macro:AC_MSG_ERROR
if this token and othres are legitimate,please use m4_pattern_allow
see the autoconf documentation
应该是无法识别AC_MSG_ERROR宏导致的,安装autoconf-archive依赖库就行。
我到这里的时候,没有反应是依赖库缺失,选择了在autoconf脚本(也就是configure.ac)中添加
m4_pattern_allow([AC_MSG_ERROR])
来显式允许使用这个宏,这样也能暂时解决问题,但是后续会因为缺失autoconf-archive依赖库不断报其他错误。
修改autoconf脚本后,需要运行以下命令重新生成configure脚本。
autoreconf -i
再次运行./autogen.sh后报错:
syntax error near unexpected token 'compoptionstring="${compoptionstring} use pthread:mandatory"
到这里我反应过来应该是缺少了某个库导致一致无法识别宏,这里如果再次用m4_pattern_allow也能解决问题,但后续可能还会有其他宏,直接安装autoconf-archive可以直接解决宏无法识别的问题。
5. 安装
./configure
make
make install
这里configure的过程中还会不断提示你缺少哪些库,需要仔细看安装日志,然后补上。
使用
在make install之后,会在/usr/local/bin中生成aide的可执行文件。
1. 配置配置文件
vim /usr/local/etc/aide.conf
配置文件格式可以在aide的官网查看,有许多种配置方法,包括哪些修改可检测、何时检测、检测范围、通知模式等。下面我们给一个简单的示例:
# AIDE configuration file
gzip_dbout=yes
# Define rules
@@define DBDIR /usr/local/var/lib/aide
# Regular rules
All= p+i+n+u+g+s+m+c+acl+xattrs+sha256
# Directories to monitor
/boot All
/bin All
/sbin All
/lib All
/lib64 All
/usr All
# Important files
/etc All
/root All
/var/log All
# Exclude some directories
!/proc
!/sys
!/dev
!/run
!/tmp
!/var/tmp
2. 初始化数据库
cd /usr/local/bin
aide --init
这会生成当前的系统状态基线,通常会在/usr/local/etc下生成aide.db
3. 运行监测
aide --check
这时,如果conf中配置监测的文件没有变化,会显示无文件变化,如下
如果有变化,也会显示出哪几个文件改变了,有什么改变。
4. 基线替换
确认所有数据合法后,更新AIDE数据库
aide --update
mv aide.db.new aide.db
5. 定时任务
也可以使用cron定期运行AIDE检查
sudo crontab -e
0 2 * * * /usr/bin/aide --check