CentOS Stream 10
Sponsored Link

Auditd : ausearch でログを検索する
2025/01/02
 

監査ルールは個別に設定することも可能ですが、デフォルトでも、システムへのログインやユーザーアカウント操作、Sudo アクションなどは監査され、[/var/log/audit/audit.log] へ記録されています。

[1] ログはテキスト形式で記録されているため、ログファイルを直接開いて参照可能です。
[root@dlp ~]#
tail -5 /var/log/audit/audit.log

type=BPF msg=audit(1735797189.739:112): prog-id=46 op=UNLOAD
type=SERVICE_STOP msg=audit(1735797192.271:113): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=systemd-hostnamed comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
type=BPF msg=audit(1735797192.283:114): prog-id=44 op=UNLOAD
type=BPF msg=audit(1735797192.283:115): prog-id=43 op=UNLOAD
type=BPF msg=audit(1735797192.283:116): prog-id=42 op=UNLOAD
[2] [audit.log] には膨大なログが記録されるため、Audit パッケージには特定のログを検索することができる [ausearch] コマンドが同梱されています。
# ログインに関するログを検索

[root@dlp ~]#
ausearch --message USER_LOGIN --interpret

----
type=USER_LOGIN msg=audit(12/14/2024 18:40:57.476:117) : pid=1007 uid=root auid=root ses=1 subj=system_u:system_r:local_login_t:s0-s0:c0.c1023 msg='op=login id=root exe=/usr/bin/login hostname=localhost.localdomain addr=? terminal=ttyS0 res=success'
----
type=USER_LOGIN msg=audit(12/19/2024 10:43:22.432:100) : pid=967 uid=root auid=root ses=1 subj=system_u:system_r:local_login_t:s0-s0:c0.c1023 msg='op=login id=root exe=/usr/bin/login hostname=localhost.localdomain addr=? terminal=ttyS0 res=success'
----
type=USER_LOGIN msg=audit(12/20/2024 09:42:09.172:110) : pid=950 uid=root auid=root ses=1 subj=system_u:system_r:local_login_t:s0-s0:c0.c1023 msg='op=login id=root exe=/usr/bin/login hostname=localhost.localdomain addr=? terminal=ttyS0 res=success'
.....
.....

# ユーザー ID 1000 の sudo 実行履歴を検索

[root@dlp ~]#
ausearch -x sudo -ua 1000

----
time->Thu Jan  2 14:55:20 2025
type=USER_AUTH msg=audit(1735797320.415:144): pid=1797 uid=1000 auid=0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=pam_unix acct="cent" exe="/usr/bin/sudo" hostname=dlp.srv.world addr=? terminal=/dev/ttyS0 res=success'
----
time->Thu Jan  2 14:55:20 2025
type=USER_ACCT msg=audit(1735797320.416:145): pid=1797 uid=1000 auid=0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:accounting grantors=pam_unix acct="cent" exe="/usr/bin/sudo" hostname=dlp.srv.world addr=? terminal=/dev/ttyS0 res=success'
----
time->Thu Jan  2 14:55:20 2025
type=USER_CMD msg=audit(1735797320.417:146): pid=1797 uid=1000 auid=0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='cwd="/home/cent" cmd=636174202F6574632F736861646F77 exe="/usr/bin/sudo" terminal=ttyS0 res=success'
.....
.....

# [dlp.srv.world] で発生した失敗イベントの履歴を検索

[root@dlp ~]#
ausearch --host dlp.srv.world --success no

----
time->Thu Jan  2 14:57:41 2025
type=USER_AUTH msg=audit(1735797461.270:171): pid=1824 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:local_login_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="redhat" exe="/usr/bin/login" hostname=dlp.srv.world addr=? terminal=/dev/ttyS0 res=failed'
----
time->Thu Jan  2 14:57:43 2025
type=USER_LOGIN msg=audit(1735797463.848:172): pid=1824 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:local_login_t:s0-s0:c0.c1023 msg='op=login acct="redhat" exe="/usr/bin/login" hostname=dlp.srv.world addr=? terminal=ttyS0 res=failed'
----
time->Thu Jan  2 14:57:56 2025
type=USER_AUTH msg=audit(1735797476.476:230): pid=1910 uid=1000 auid=0 ses=3 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/bin/su" hostname=dlp.srv.world addr=? terminal=/dev/ttyS0 res=failed'
.....
.....

# 2025/1/1 ~ 2025/1/2 間に発生したログインユーザー ID が 1000 のログを検索

[root@dlp ~]#
ausearch --start 01/01/2025 --end 01/02/2025 -ul 1000

----
time->Thu Jan  2 14:59:15 2025
type=PROCTITLE msg=audit(1735797555.909:157): proctitle=2F62696E2F6C6F67696E002D70002D2D
type=SYSCALL msg=audit(1735797555.909:157): arch=c000003e syscall=1 success=yes exit=4 a0=3 a1=7fffc54a5e20 a2=4 a3=0 items=0 ppid=1 pid=1761 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=1000 fsgid=0 tty=ttyS0 ses=3 comm="login" exe="/usr/bin/login" subj=system_u:system_r:local_login_t:s0-s0:c0.c1023 key=(null)
type=LOGIN msg=audit(1735797555.909:157): pid=1761 uid=0 subj=system_u:system_r:local_login_t:s0-s0:c0.c1023 old-auid=4294967295 auid=1000 tty=ttyS0 old-ses=4294967295 ses=3 res=1
----
time->Thu Jan  2 14:59:15 2025
type=USER_ROLE_CHANGE msg=audit(1735797555.909:158): pid=1761 uid=0 auid=1000 ses=3 subj=system_u:system_r:local_login_t:s0-s0:c0.c1023 msg='op=pam_selinux default-context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 selected-context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 exe="/usr/bin/login" hostname=node01.srv.world addr=? terminal=/dev/ttyS0 res=success'
----
time->Thu Jan  2 14:59:15 2025
type=PROCTITLE msg=audit(1735797555.936:163): proctitle="(systemd)"
type=SYSCALL msg=audit(1735797555.936:163): arch=c000003e syscall=1 success=yes exit=4 a0=7 a1=7ffe708ccd20 a2=4 a3=0 items=0 ppid=1 pid=1774 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4 comm="(systemd)" exe="/usr/lib/systemd/systemd-executor" subj=system_u:system_r:init_t:s0 key=(null)
type=LOGIN msg=audit(1735797555.936:163): pid=1774 uid=0 subj=system_u:system_r:init_t:s0 old-auid=4294967295 auid=1000 tty=(none) old-ses=4294967295 ses=4 res=1
.....
.....
関連コンテンツ