0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linuxの監視システム Audit

Last updated at Posted at 2020-06-14

Auditの用途

  • ファイルアクセスの監視
  • システムコールの監視
  • ユーザーログインの記録
  • コマンド実行の記録

Auditルールを定義する

Auditルール

  • 制御ルール(Auditの動作に関する設定)
  • ファイルシステムルール(指定したファイル&ディレクトリへのアクセスに対して監査する設定
  • システムコールルール(指定したシステムコールに対して監査する設定)

auditctlコマンド(一時的な定義)

auditctlコマンドで追加した定義はauditdデーモンの再起動を行うと削除される

# 現在の制御ルールの設定値を表示(sオプション)
auditctl -s
enabled 1
failure 1
pid 725
rate_limit 0
backlog_limit 8192
lost 0
backlog 0
loginuid_immutable 0 unlocked
# 現在のファイルシステムルール、システムコールルールを表示
auditctl -l
No rules
# ファイルシステムルールを定義する為のオプション
# wオプション 監視対象のファイル、ディレクトリを指定
# pオプション 監視の種類となるパーミッションを指定(r,w,x,a) aは属性変更
# kオプション 識別する為の任意の名称を指定
auditctl -w /etc/passwd -p wa -k identity
# システムコールルールを定義する為のオプション
# aオプション アクション(always, never) 常に監査記録を生成する、記録を生成しない
# aオプション リスト(exclude, exit, task, user)
# aオプションとdオプション(削除)はアクションとリストを組み合わせて定義
# Fオプション フィールドに値を指定(アーキテクチャ、ユーザーID、プロセスID)
# Sオプション システムコールまたはallを指定 複数指定可(論理和 orとなる)
# kオプション 識別する為の任意の名称を指定
auditctl -a always,exit -F arch=b64 -S adjtimex,settimeofday -k 
 time-change
# 現在のファイルシステムルール、システムコールルールを表示
auditctl -l
-w /etc/passwd -p wa -k identity
-a always,exit -F arch=b64 -S adjtimex,settimeofday -F key=time-change

/etc/audit/audit.rules (/etc/audit/rules.d/audit.rules) 永続的なルールを定義


vi /etc/audit/rules.d/audit.rules

()

## Set failure mode to syslog
# 制御ルールの設定
-e 2
-f 2
# ファイルシステムルールの追加
-w /etc/passwd -p wa -k identity
# システムコールルールの追加
-a always,exit -F arch=64 -S adjtimex,settimeofday -k time-change
# auditdデーモンの再起動
service auditd restart
# 現在のファイルシステムルール、システムコールルールを表示
auditctl -l
-w /etc/passwd -p wa -k identity
-a always,exit -F arch=b64 -S adjtimex,settimeofday -F key=time-change
# 現在の制御ルールの設定値を表示
auditctl -s
enabled 2
failure 2
pid 1519
rate_limit 0
backlog_limit 8192
lost 0
backlog 0
loginuid_immutable 0 unlocked

ausearchコマンド(Auditログファイルの検索)

デフォルトでは /var/log/audit/audit.log ファイルを検索する

ausearch -i -k time-change
----
type=CONFIG_CHANGE msg=audit(06/14/2020 13:45:43.051:126) : auid=root ses=1 op=add_rule key=time-change list=exit res=yes 
----
type=PROCTITLE msg=audit(06/14/2020 13:45:49.544:127) : proctitle=/usr/sbin/chronyd 
type=SYSCALL msg=audit(06/14/2020 13:45:49.544:127) : arch=x86_64 syscall=adjtimex success=yes exit=0 a0=0x7ffcba00d780 a1=0x0 a2=0xa5182 a3=0x2 items=0 ppid=1 pid=771 auid=unset uid=chrony gid=chrony euid=chrony suid=chrony fsuid=chrony egid=chrony sgid=chrony fsgid=chrony tty=(none) ses=unset comm=chronyd exe=/usr/sbin/chronyd key=time-change 
----
type=PROCTITLE msg=audit(06/14/2020 13:45:49.544:128) : proctitle=/usr/sbin/chronyd 
type=SYSCALL msg=audit(06/14/2020 13:45:49.544:128) : arch=x86_64 syscall=adjtimex success=yes exit=0 a0=0x7ffcba00d790 a1=0x0 a2=0xa3314 a3=0x2 items=0 ppid=1 pid=771 auid=unset uid=chrony gid=chrony euid=chrony suid=chrony fsuid=chrony egid=chrony sgid=chrony fsgid=chrony tty=(none) ses=unset comm=chronyd exe=/usr/sbin/chronyd key=time-change 
----
()

aureportコマンド(指定した条件でのログの要約とレポート)

pam_tty_audit.soモジュールを使用して条件を指定

/etc/pam.d/system-auth

account     required      pam_permit.so

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
# 追記
session     required      pam_tty_audit.so disable=* enable=testuser

/etc/pam.d/password-authにも追記


vi /etc/pam.d/password-auth
# %PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        required      pam_faildelay.so delay=2000000
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     
session     required      pam_limits.so
-session     optional      pam_systemd.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so

session     required      pam_tty_audit.so disable=* enable=testuser

# TTY検査結果を表示
aureport --tty
# テスト未実施である為、ログなし
TTY Report
===============================================
# date time event auid term sess comm data
===============================================
<no events of interest were found> 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?