From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page AIDE and the translation is 67% complete.

AIDE (Advanced Intrusion Detection Environment) はホストベースの侵入検知システムです。AIDE はファイルや他リソースをスキャンし、データベース内にこれらファイルの情報について保存します。保存する情報はハッシュ値、ファイルサイズ、所有者、編集日時、作成日時等のような主だったファイルの属性値です。データベースを最初に作ったら、AIDE はそれからシステムを再スキャンして、前回の保存した値と今回のスキャン結果を比較します。もし値が前回と異なった場合は変更があったと報告します。AIDE の背景にある考え方は、スナップショット同士を比較して、改ざんファイルを見つけることです。


USE フラグ

USE フラグを次のように設定すると app-forensics/aide のインストールは簡単です。

USE flags for app-forensics/aide AIDE (Advanced Intrusion Detection Environment) is a file integrity checker

acl Add support for Access Control Lists
audit Enable support for Linux audit subsystem using sys-process/audit
curl Use curl for http,https and ftp backends
e2fs Enable support for checking file attributes on ext2/ext3/ext4 filesystems
mhash Add support for the mhash library
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
xattr Add support for extended attributes (filesystem-stored metadata)

特定のパッケージ固有の USE フラグは /etc/portage/package.use というファイルか、 /etc/portage/package.use と呼ばれるディレクトリの中にあるテキストファイルで設定する必要があります。例えば /etc/portage/package/use ファイル の場合:

ファイル /etc/portage/package.useAIDE の zlib サポートを有効化する
app-forensics/aide zlib



root #emerge --ask app-forensics/aide



app-forensics/aide の設定ファイルは第一印象ほどとっつきにくくはありません。デフォルトのファイルは /etc/aide/aide.conf に保存されていますが、システム管理者は必要に応じて、簡単に設定ファイルを複数作ることが出来ます。幾つかの変数に加え、設定ファイルにはスキャンするファイル情報 (ただのハッシュ値とか、iノード情報等々) とスキャンするファイルの短い表記が含まれています。


ファイル aide.conf変数

The first line in the example above (database) defines where the location of database that contains the known values. The second line (database_out) defines where to store new databases when another is generated. It is generally recommended against having these variables point to the same database (having the same paths for each variable). If one database is to overwrite another, the best method is to manually copy over the generated database from one location to the other. For example, to overwrite the first database with the second, this command could be used:

root #cp /var/lib/aide/ /var/lib/aide/aide.db

ひとまず、データベース変数はそのままにしておいてください; これらについてはこの記事内で後でより詳細に扱います。

Next, consider the variables which are short-hand notations for what information to record in the database.

ファイル aide.conf短縮記法を使用した AIDE の構成
Binlib = p+i+n+u+g+s+b+m+c+md5+sha1
Logs = p+i+n+u+g+S
md5 および sha1 は、(それぞれ) MD5 および SHA-1 チェックサムが取られることを意味するのは明らかでしょう。

文字はについてはデフォルトの aide.conf ファイルで説明されていますが、利便性のために以下の表でよく使用されるオプションの概要を提供します:

短縮記法 説明
p 権限
i inode 番号
n (ハード) リンクの数
u ユーザ情報
g グループ情報
s サイズ
S サイズ (サイズが突然小さくなったときのみ報告します - 大きくなることは許可されています)
b ブロック数
m 変更日時

Next is an overview of which directories to scan, and what to scan for. In three line example to follow, AIDE is instructed to scan the /bin and /sbin directories via the measures identified in the Binlib short-hand notation variable. The /var/log file will display the scan measures defined in the Logs variable defined above.

ファイル aide.confスキャン対象オプション
/bin Binlib
/sbin Binlib
/var/log Logs

AIDE supports regular expressions and users are allowed to "remove" matches. For instance, to scan /var/log but not /var/log/portage then make an exclusion set by using the ! (exclamation point) before the excluded path(s):

ファイル aide.conf他のスキャン対象
/var/log Logs


The configuration file is based on regular expressions, macros and rules for files and directories. Users experienced with the tripwire solution will have no difficulties dealing with AIDE's configuration file. The following macros are available:

Macro Description Syntax
ifdef If defined @@ifdef "name"
ifndef If not defined @@ifndef "name"
define Define a variable @@define "name" "value"
undef Undefine a variable @@undef "name"
ifhost if "hostname" @@ifhost "hostname"
ifnhost if not "hostname" @@ifnhost "hostname"
endif Endif must be used after any of the above macros except define and undef @@endif

These macros become very handy when dealing with multiple Gentoo boxes, while using the same configuration on all. Not all machines run the same services or even have the same users.

Next we have a set of flags which identify the permissions, file properties, checksums, cryptographic hashes, ... to validate on files and directories.

Flag Description
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
md5 md5 checksum
sha1 sha1 checksum
rmd160 rmd160 checksum
tiger tiger checksum
R p+i+n+u+g+s+m+c+md5
L p+i+n+u+g
E Empty group
> Growing logfile p+u+g+i+n+S

AIDE が mhash サポート付きでコンパイルされている場合、以下のフラグも使用することができます:

フラグ 説明
haval haval チェックサム
gost gost チェックサム
crc32 crc32 チェックサム


For a basic AIDE setup, a database must be initialized. This is performed using the --init option. To make sure AIDE uses the configuration settings defined in the sections before, be sure to pass the --config option pointed to the correct configuration file:

root #aide --init --config=/etc/aide/aide.conf
AIDE, version 0.14.2
### AIDE database at /var/lib/aide/ initialized.

Once initialized, any pre-existing database files can be copied over:

root #cd /var/lib/aide; cp aide.db

With a new database available, the entries can be scanned again (now or at a later date) using the --check option. This will create another database containing any modifications that have made to the file system since the first database has been created. Be sure to use the --config option pointed to the same configuration file that the first database was created with:

root #aide --check --config=/etc/aide/aide.conf
AIDE, version 0.14.2
### All files match AIDE database. Looks okay!

If file modification(s) occurred, a notification will be sent out, if no initial database exists at all a warning will be presented such as:

root #aide --init --config=/etc/aide/aide.conf
Couldn't open file /var/lib/aide/ for writing

This is not a real error and is simply aide stating it cannot find a database so it must create one, this may take several minutes.

root #aide --check --config=/etc/aide/aide.conf
AIDE found differences between database and filesystem!!
Start timestamp: 2013-04-11 15:31:02
  Total number of files:        318
  Added files:                  0
  Removed files:                0
  Changed files:                2
Changed files:
changed: /etc/pam.d
changed: /etc/pam.d/run_init
Detailed information about changes:
Directory: /etc/pam.d
  Mtime    : 2013-04-09 22:11:18              , 2013-04-11 15:31:01
  Ctime    : 2013-04-09 22:11:18              , 2013-04-11 15:31:01
File: /etc/pam.d/run_init
  Size     : 205                              , 208
  Mtime    : 2013-04-09 22:11:18              , 2013-04-11 15:31:00
  Ctime    : 2013-04-09 22:11:18              , 2013-04-11 15:31:01
  Inode    : 394203                           , 394053
  MD5      : Mm0KPzpPt63eqGClTJ/KaQ==         , eLUrP2BsIq25f3AZX+dlBA==
  SHA1     : NrQtsUeOsXS4RHUq+ejYBne5V6E=     , 5A6ef6VJCcMiqEjKQ7e9xkBNZB8=



The default AIDE configuration is useful, but it needs to be fine-tuned to suit the users' needs. It is important to know which files to scan and why.

For instance, to scan for all authentication-related files but not for other files, use a configuration like so:

ファイル aide.conf認証関連のスキャン対象
# SELinux のポリシーと設定
/etc/selinux ConfFiles
# 認証データベース
/etc/passwd ConfFiles
/etc/shadow ConfFiles
/etc/nsswitch.conf ConfFiles
# 認証の構成設定
/etc/pam.d ConfFiles
/etc/securetty ConfFiles
/etc/security ConfFiles
# PAM ライブラリ
/lib(64)?/security Binlib


A second important aspect is that the result database should be stored offline when not needed and should be used in read-only mode when the database is needed. This gives some protection against a malicious user that might have compromised the machine to modify the results database. For instance, provide the result database on a read-only NFS mount (for servers) or read-only medium (when physical access to the machine is possible) such as a CD/DVD or a read-only USB drive.

After storing the database on a read-only location, update the aide.conf file to have database point to this new location.


If applicable, try using offline scanning methods for the system. In case of virtual platforms, it might be possible to take a snapshot of the system, mount this snapshot (read-only) and then run the aide scan on the mounted file system.

root #losetup /dev/loop0 /srv/virt/gentoo.img
root #vgscan
root #vgchange -ay
root #mount -o ro /dev/volgrpX/volumeY /mnt/image
root #chroot /mnt/image
root #aide --check --config=/path/to/aide.conf
root #exit
root #umount /mnt/image
root #vgchange -an /dev/volgrpX
root #losetup -d /dev/loop0

The above approach uses chroot. This is only needed when the initial file system has been scanned from the live system and the administrator wants to perform an offline validation. If the initial scan was done offline, then the aide.conf file will point to the mount point already and the database will use these paths immediately, so then there is no need for chrooting.