■同様の機能として、Tripwireがあります。
chkrootkit、tripwire、clamavチェック
http://d.hatena.ne.jp/labunix/20120830
■AIDEとは。
$ apt-cache show aide | grep ^Desc -A 16
Description-ja: 進化した侵入検知環境 - スタティック版ライブラリ
AIDE は侵入検出システムで、ローカルシステム上のファイルに対する変更を
検出します。設定ファイルから見つけた正規表現規則からなるデータベースを
生成します。一旦データベースが生成されると、ファイルの完全度を検証する
のに使用できます。ファイルの完全度をチェックするために使用する、いくつ
かのメッセージ要約アルゴリズム (md5、sha1、rmd160、tiger、haval など) を
備えています。 さらにアルゴリズムを追加するのも、それほど難しくはありま
せん。通常のファイル属性も、その不整合有無をチェックできます。
.
本パッケージには "通常の" システム向けにスタティックリンクされた
バイナリが含まれます。
.
まず確実に、設定ファイルの /etc/aide/aide.conf をいじりたくなるか、
独自の設定ファイルの断片を /etc/aide/aide.conf.d に配置したくなるでしょう。
.
上流開発元 URL: http://sourceforge.net/projects/aide
Homepage: http://sourceforge.net/projects/aide
■AIDEの導入。
$ sudo apt-get install -y aide
■AIDEのレポートメールの送信先の確認。
※必要なら変更する。
$ grep "^MAILTO" /etc/default/aide
MAILTO=root
■ファイルの場所
$ dpkg -l | grep ^ii | grep aide | awk '{print $2}'
aide
aide-common
$ dpkg -L aide | grep -v ^/usr/share
/.
/usr
/usr/bin
/usr/bin/aide
$ dpkg -L aide-common | grep -v ^/usr/share
/.
/etc
/etc/cron.daily
/etc/aide
/etc/aide/aide.settings.d
/etc/aide/aide.conf.d
/etc/default
/var
/var/lib
/var/lib/aide
/var/log
/var/log/aide
/usr
/usr/sbin
/usr/sbin/update-aide.conf
/usr/sbin/aideinit
/usr/bin
/usr/bin/aide-attributes
/usr/bin/aide.wrapper
■初回実行
※「aide.wrapper --init」に時間とCPUを要するので
「sudo nice -n 19 /usr/sbin/aideinit -y」とした方がベター。
$ man aideinit | grep yes
-y, --yes
$ man nice | grep "\-n"
-n, --adjustment=N
$ sudo /bin/bash -x /usr/sbin/aideinit -y
+ '[' -f /etc/default/aide ']'
+ . /etc/default/aide
++ MAILSUBJ='Daily AIDE report for '
++ MAILTO=root
++ COMMAND=update
++ COPYNEWDB=no
++ TRUNCATEDETAILS=no
++ FILTERUPDATES=no
++ FILTERINSTALLATIONS=no
++ LINES=1000
++ NOISE=
++ AIDEARGS=
+ MAILTO=root
+ opt_f=0
+ opt_y=0
+ opt_c=0
+ opt_b=0
+ defaultconfig=/var/lib/aide/aide.conf.autogenerated
+ '[' -x /usr/bin/aide ']'
+ '[' -n -y ']'
+ case "$1" in
+ opt_y=1
+ shift
+ '[' -n '' ']'
+ '[' -z '' ']'
+ update-aide.conf
+ config=/var/lib/aide/aide.conf.autogenerated
+ '[' '!' -f /var/lib/aide/aide.conf.autogenerated ']'
+ '[' -z '' ']'
++ egrep '^[[:space:]]*database_out=file:' /var/lib/aide/aide.conf.autogenerated
++ cut -d: -f2
+ outfile=/var/lib/aide/aide.db.new
+ '[' -z /var/lib/aide/aide.db.new ']'
+ '[' -z '' ']'
++ egrep '^[[:space:]]*database=file:' /var/lib/aide/aide.conf.autogenerated
++ cut -d: -f2
+ dbfile=/var/lib/aide/aide.db
+ '[' -z /var/lib/aide/aide.db ']'
+ '[' -f /var/lib/aide/aide.db.new ']'
+ '[' 1 -eq 0 ']'
+ extraflags=
+ '[' 0 -eq 1 ']'
+ echo 'Running aide --init...'
Running aide --init...
+ aide.wrapper --init
error mmap'ing ~/centos4/proc/kcore: Input/output error
error mmap'ing ~/centos4/proc/bus/pci/00/1f.3: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1f.2: Invalid argument
error mmap'ing ~/centos4/proc/bus/pci/00/1f.0: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1e.0: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1d.7: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1d.3: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1d.2: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1d.1: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1d.0: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1c.3: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1c.2: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1c.1: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1c.0: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/1b.0: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/02.1: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/02.0: No such device
error mmap'ing ~/centos4/proc/bus/pci/00/00.0: No such device
error mmap'ing ~/centos4/proc/bus/pci/02/00.0: No such device
error mmap'ing ~/centos4/proc/bus/pci/03/00.0: No such device
...
AIDE, version 0.15.1
+ RET=0
+ '[' 0 '!=' 0 ']'
+ '[' -f /var/lib/aide/aide.db -a 0 -eq 0 ']'
+ cp -f /var/lib/aide/aide.db.new /var/lib/aide/aide.db
■というわけで、以下で成功することを確認。
$ mount | grep cifs | awk '{print $3}' | for list in `xargs`;do sudo umount "$list";done;sudo aideinit -y
$ sudo mount -a
■除外設定
$ ls -ld ~/cifs/*/proc | awk '{print "!"$8}' | sudo tee -a /etc/aide/aide.conf
[sudo] password for labunix:
!/home/labunix/cifs/centos4/proc
!/home/labunix/cifs/centos5/proc
!/home/labunix/cifs/centos6/proc
!/home/labunix/cifs/cslc-5/proc
!/home/labunix/cifs/cslc-6/proc
!/home/labunix/cifs/lenny/proc
!/home/labunix/cifs/sid/proc
!/home/labunix/cifs/squeeze/proc
!/home/labunix/cifs/wheezy/proc
■アップデート
$ aide -C | awk '{print $4}' | sed s%aide.db%%g | xargs mkdir -p
$ sudo aide -C | awk '{print $4}' | xargs touch
$ sudo ls /var/lib/aide/please-dont-call-aide-without-parameters/
aide.db
$ aide -C
File database must have one db_spec specification
AIDE, version 0.15.1
File database must have one db_spec specification
AIDE, version 0.15.1
$ sudo aide --update
$ sudo ls /var/lib/aide/please-dont-call-aide-without-parameters/
aide.db aide.db.new
■再調整
$ sudo cp /var/lib/aide/aide.db /var/lib/aide/please-dontall-aide-without-parameters/aide.db
$ sudo aide --update
$ sudo aide -C
$ sudo aide -D
■cronのテスト
$ sudo /etc/cron.daily/aide
$ sudo cat /var/log/aide/aide.log | sed s/`hostname -f`/"dummy-host.example.com"/g
This is an automated report generated by the Advanced Intrusion Detection
Environment on dummy-host.example.jp started at 2013-04-13 18:49:16.
******************************************************************************
* The cron job was terminated with signal INT *
******************************************************************************
******************************************************************************
* the cron job was interrupted before AIDE could return an exit code. *
******************************************************************************
AIDE produced no errors.
funny, AIDE did not leave a log.
End of AIDE daily cron job at 2013-04-13 18:53, run time 243 seconds
■沢山変更すると以下のようなメールが来る。
$ cat aide.mail
...
AIDE 0.15.1 found differences between database and filesystem!!
Start timestamp: 2013-04-13 18:57:38
Summary:
Total number of files: 363236
Added files: 103
Removed files: 66
Changed files: 231
...
The AIDE run created a new database /var/lib/aide/aide.db.new with the following characteristics:
Size : 64317729
Bcount : 125760
Mtime : 2013-04-13 21:10:24
Ctime : 2013-04-13 21:10:24
Inode : 146776
RMD160 : 8yOmuHWhhDIR2GNs1xTXAbNDFHs=
TIGER : s4e2VDOeid9NyK90Nl2VfKafTsDuA/4m
SHA256 : P1OFtbhFzTfJlDBynThH+0hT3z/Klkr7
SHA512 : iHFQ0xjyHyyzmY5NGZrpb63rIx+tDyhP
CRC32 : tfVaaw==
HAVAL : as1U72dSc5wkwtDLE/8kFPTnrflyyBse
GOST : SMCXZ2awQUOCctMvxxm6sG5wX+RaCsw0
End of AIDE daily cron job at 2013-04-13 21:11, run time 8014 seconds