Linuxの監査機能のAuditdのメモです。コマンドはCentOSまたはAmazon Linuxで実行しています。
- アーキテクチャ
- インストール方法
- 各種ログの挙動設定ファイル
- Auditルール設定
- とりあえず動きを確認したい場合
- 直近のログイン履歴を見る
- サマリレポート(aureport)
- クエリ検索(ausearch)
- (補足)Amazon Linux
- 参考URL
アーキテクチャ
アーキテクチャは以下のRedHat公式から引用の図の通り。システムコールをフックしてAudit Daemonが監査ログに情報を蓄積します。
蓄積した監査ログは、そのまま見ることもできますが、aureportなどの各種レポートツールも付属しています。
インストール方法
普通にパッケージからインストール可能です。
yum install audit
apt-get install auditd
各種ログの挙動設定ファイル
各種ログファイル設定やローテーション方法などを設定するファイル。
/etc/audit/auditd.conf
Auditルール設定
Auditログの取得ルールを記述するファイル。
/etc/audit/audit.rules
ルールの記述方法は、manコマンドで確認したり、
$ man audit.rules
または、このあたり。
設定サンプル
手っ取り早くいきたければ、この設定サンプルあたりから取捨選択で一旦は事足りそう。
一時的にルール変更を行う(auditctl)
auditctlコマンドで一時的な設定が可能
# auditctl -w /etc/ssh/sshd_config -p warx -k sshd_config
現在のルール設定確認(auditctl)
ルール設定確認もauditctlで可能
# auditctl -l -w /etc/ssh/sshd_config -p rwxa -k sshd_config
とりあえず動きを確認したい場合
以下のコマンドを実行して一時ルールを適用。rootユーザ(uid=0)の全部のコマンドを記録。
# auditctl -a always,exit -F arch=b64 -S execve -F euid=0 # auditctl -a always,exit -F arch=b32 -S execve -F euid=0
tail -f
でログファイルを確認
# tail -f /var/log/audit/audit.log
rootユーザで適当にコマンドを打ってみると、Auditログが書き込まれる。
直近のログイン履歴を見る
時系列の履歴とか(aulast)
# aulast ec2-user pts/0 124x33x203x210.a Tue Aug 23 07:00 - 07:02 (00:02) ec2-user pts/0 124x33x203x210.a Tue Aug 23 07:02 - 07:02 (00:00) otomo pts/0 124x33x203x210.a Tue Aug 23 07:02 - 07:02 (00:00) ec2-user pts/0 124x33x203x210.a Tue Aug 23 07:02 - 07:58 (00:55) otomo pts/3 124x33x203x210.a Tue Aug 23 09:06 - 09:06 (00:00) ec2-user pts/1 124x33x203x210.a Tue Aug 23 07:03 still logged in ec2-user pts/0 124x33x203x210.a Tue Aug 23 09:05 still logged in ec2-user pts/2 124x33x203x210.a Tue Aug 23 09:05 still logged in
ユーザ毎の履歴(aulastlog)
# aulastlog Username Port From Latest root **Never logged in** bin **Never logged in** daemon **Never logged in** adm **Never logged in** lp **Never logged in** sync **Never logged in** shutdown **Never logged in** halt **Never logged in** mail **Never logged in** uucp **Never logged in** operator **Never logged in** games **Never logged in** gopher **Never logged in** ftp **Never logged in** nobody **Never logged in** rpc **Never logged in** ntp **Never logged in** saslauth **Never logged in** mailnull **Never logged in** smmsp **Never logged in** rpcuser **Never logged in** nfsnobody **Never logged in** sshd **Never logged in** dbus **Never logged in** ec2-user /dev/pts/2 124x33x203x210.ap124.ftth. 2016年08月23日 09:05:42 otomo /dev/pts/3 124x33x203x210.ap124.ftth. 2016年08月23日 09:06:35
サマリレポート(aureport)
# aureport Summary Report ====================== Range of time in logs: 2016年08月23日 05:56:42.094 - 2016年08月23日 10:38:42.994 Selected time for report: 2016年08月23日 05:56:42 - 2016年08月23日 10:38:42.994 Number of changes in configuration: 26 Number of changes to accounts, groups, or roles: 8 Number of logins: 18 Number of failed logins: 16 Number of authentications: 56 Number of failed authentications: 36 Number of users: 4 Number of terminals: 14 Number of host names: 15 Number of executables: 14 Number of commands: 11 Number of files: 14 Number of AVC's: 0 Number of MAC events: 0 Number of failed syscalls: 0 Number of anomaly events: 0 Number of responses to anomaly events: 0 Number of crypto events: 434 Number of integrity events: 0 Number of virt events: 0 Number of keys: 2 Number of process IDs: 135 Number of events: 900
クエリ検索(ausearch)
ausearchは複数条件使ってAuditログの検索ができます。
# ausearch -m ADD_USER -ui 0 ---- time->Tue Aug 23 05:56:47 2016 type=ADD_USER msg=audit(1471931807.081:6): pid=2295 uid=0 auid=4294967295 ses=4294967295 msg='op=adding user id=500 exe="/usr/sbin/useradd" hostname=? addr=? terminal=? res=success' ----
クエリに必要な情報
ログの中の Type
に当たる値を探す。(ausearch -m
オプション)
System Callの数値を探す。(ausearch -sc
オプション)
32bit
# ausyscall i386 --dump
64bit
# ausyscall x86_64 --dump
(補足)Amazon Linux
例えばCentOSの場合は初期設定では以下のルールがあるだけ。
# cat /etc/audit/audit.rules -D -b 320
しかし、Amazon Linuxは最初に以下の値が入っていてSystem CallのAuditログ取得できないので注意。
-a never,task