CentOS 8
Sponsored Link

Auditd : 監査ルールを追加する2019/09/28

 
デフォルトで設定されているシステムへのログインやユーザーアカウント操作、Sudo アクションなどの監査設定以外のアクション、例えば、ある特定のファイルへのアクセスを監査したい場合等は、個別にルールを追加する必要があります。
[1] 例として、[/etc/hosts] の書き込みアクセスと属性変更を記録する監査ルールを設定します。
# 現在のルールを表示 (デフォルトは以下のように個別ルールは未設定)

[root@dlp ~]#
auditctl -l

No rules
# -p [r|w|x|a] で監視対象アクションを指定

# r=読み取り, w=書き込み, x=実行, a=属性変更

# -k [任意の文字列] で検索用キーを設定

[root@dlp ~]#
auditctl -w /etc/hosts -p wa -k hosts_change

[root@dlp ~]#
auditctl -l

-w /etc/hosts -p wa -k hosts_change
[2] 監査ルール設定後、監査対象のファイルに監査対象アクションを実行すると、以下のようなログが記録されます。
[root@dlp ~]#
ausearch -k hosts_change | aureport -f -i


File Report
===============================================
# date time file syscall success exe auid event
===============================================
1. 09/26/2019 21:02:54 /etc/hosts ? yes ? root 156
2. 09/26/2019 21:02:54 /etc/hosts~ rename yes /usr/bin/vi root 157
3. 09/26/2019 21:02:54 /etc/hosts openat yes /usr/bin/vi root 159
4. 09/26/2019 21:02:54 /etc/hosts ? yes ? root 158
5. 09/26/2019 21:02:54 /etc/hosts setxattr yes /usr/bin/vi root 160
6. 09/26/2019 21:02:54 (null) fchmod yes /usr/bin/vi root 161
7. 09/26/2019 21:02:54 /etc/hosts setxattr yes /usr/bin/vi root 162
[3] [auditctl] で設定した監査ルールはシステム再起動すると初期化されるため、永続化するには [/etc/audit/rules.d] 配下にルールを定義しておく必要があります。定義ファイルは、拡張子が [.rules] であればファイル名は任意の名称で OK です。
# 現在の設定を additional.rules に書き出す

[root@dlp ~]#
auditctl -l >> /etc/audit/rules.d/additional.rules

[4] 監査対象にディレクトリを指定すると、対象ディレクトリ配下が再帰的に監査対象となります。
# [/home/testdir/] に読み取りアクセスの監査ルールを設定

[root@dlp ~]#
auditctl -w /home/testdir/ -p r -k testdir_audit

[root@dlp ~]#
auditctl -l

-w /etc/hosts -p wa -k hosts_change
-w /home/testdir -p r -k testdir_audit
# 読み取りアクセスが以下のように記録される

[root@dlp ~]#
ausearch -k testdir_audit | aureport -f -i


File Report
===============================================
# date time file syscall success exe auid event
===============================================
1. 09/26/2019 22:07:21 /home/testdir/cent/testfile.txt openat yes /usr/bin/cat root 70
2. 09/26/2019 22:07:42 /home/testdir/cent/testfile.txt openat yes /usr/bin/vi root 77
3. 09/26/2019 22:07:42 /home/testdir/cent/testfile.txt openat yes /usr/bin/vi root 78
[5] 例として、UID が 1000 以上のログインユーザーが消去したファイルを監査する設定です。
なお、以下で S オプションで指定しているシステムコールの一覧は [dnf install man-pages] をすると [man syscalls] で確認できます。
[root@dlp ~]#
auditctl -a always,exit -F arch=b64 -S unlink,unlinkat -F 'auid>=1000' -F 'auid!=-1' -F key=delete_audit

[root@dlp ~]#
auditctl -l

-w /etc/hosts -p wa -k hosts_change
-a always,exit -F arch=b64 -S unlink,unlinkat -F auid>=1000 -F auid!=-1 -F key=delete_audit
# 以下のようなログが記録される

[root@dlp ~]#
ausearch -k delete_audit | aureport -f -i


File Report
===============================================
# date time file syscall success exe auid event
===============================================
1. 09/26/2019 22:22:33 /run/user/1000/systemd/ unlink no /usr/lib/systemd/systemd cent 122
2. 09/26/2019 22:22:33 /run/user/1000/systemd/ unlink no /usr/lib/systemd/systemd cent 123
3. 09/26/2019 22:22:39 test2.txt unlinkat yes /usr/bin/rm cent 128
4. 09/26/2019 22:22:41 test.txt unlinkat yes /usr/bin/rm cent 129
関連コンテンツ