Audit フレームワーク

提供: ArchWiki
2016年1月24日 (日) 10:11時点におけるAosho235 (トーク | 投稿記録)による版 (英語版より部分的に翻訳)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

Linux の audit フレームワークは CAPP (Controlled Access Protection Profiles) に準拠した監査システムであり、システム上のセキュリティに関係した(または無関係な)イベントを収集できます。これを使うことにより、システム上で行われた動作を追跡できるようになります。

Linux audit helps make your system more secure by providing you with a means to analyze what is happening on your system in great detail. It does not, however, provide additional security itself—it does not protect your system from code malfunctions or any kind of exploits. Instead, Audit is useful for tracking these issues and helps you take additional security measures, to prevent them.

audit フレームワークはカーネルが報告するイベントを受信し、ログファイルに書き込みます。

ノート: Linux 3.12の時点では、audit フレームワークは名前空間の実装と互換性がありません。名前空間を使っている場合は audit フレームワークを使わないでください。
ノート: システムのパフォーマンスに影響を与える可能性があります。

インストール

CONFIG_AUDIT を有効にしたカスタムカーネルをインストールします。 audit をインストールし、次を実行します:

# systemctl enable auditd.service
# systemctl start auditd.service

audit フレームワークは auditd デーモンから構成されます。アプリケーションやシステムの動作によりカーネルの audit インターフェイスが発動し、audit インターフェイスが生成した audit メッセージを auditd が書き込みます。

このデーモンはいくつかのコマンドとファイルにより制御されます:

  • auditctl : その場でデーモンの挙動をコントロールします。ルールを追加するなど
  • /etc/audit/audit.rules : ルールや auditd のパラメータを記述します
  • aureport : システムの動作レポートを生成します
  • ausearch : イベントを検索します
  • auditspd : イベント通知をディスク上のログに書き込む代わりに他のアプリケーションに中継するデーモンです
  • autrace : プロセスをトレースするためのコマンド。straceに似ています
  • /etc/audit/auditd.conf : ログに関する設定ファイルです

ルールの追加

ルールを追加する前に注意しなければならないのは、audit フレームワークは非常に饒舌で、ルールを実際に運用する前に注意深くテストする必要があることです。実際、たった1つのルールにより2,3分でログを溢れてしまうこともあり得ます。

ファイルとディレクトリへのアクセスを監査する

audit フレームワークの一番簡単な使い方は、特定のファイルへのアクセスをログに記録することです。 それには -w オプションを使います。 一番簡単なルールの例として passwd ファイルへのアクセスを追跡する:

# auditctl -w /etc/passwd -p rwxa

フォルダへのアクセスを追跡するには:

# auditctl -w /etc/security/

最初のルールは /etc/passwd への読み込み r、書き込み w、実行 x、属性変更 a を追跡します。 2番目のルールは /etc/security/ への全てのアクセスを追跡します。

有効なルールのリストを表示するには:

# auditctl -l

全てのルールを削除するには:

# auditctl -D

ルールが正しく動作することを確認したら、それを /etc/audit/audit.rules に書きます:

-w /etc/audit/audit.rules -p rwxa
-w /etc/security/

システムコールを監査する

The audit framework allow you to audit the syscalls performed with the -a option.

A security related rule is to track the chmod syscall, to detect file ownership changes :

auditctl -a entry,always -S chmod

For a list of all syscalls : man syscalls

A lot of rules and posibilities are available, see man auditctl and man audit.rules

ログを検索する

audit フレームワークにはシステム上で発生したイベントを調べるためのツールがいくつか含まれています。

PIDを指定する

特定の PID に関係するイベントを検索するには ausearch を使います:

# ausearch -p 1

このコマンドを実行すると、ルールに応じて記録されたイベントの中から PID 1 (systemd) に関係するものすべてを表示します。

キーの使い方

イベントを管理するためにキーを使うことが推奨されます。

イベントの検索を容易にするために、ルールに -k オプションをつけます:

# auditctl -w /etc/passwd -p rwxa -k KEY_pwd

するとキー KEY_pwd を使ってイベントを検索できるようになります。次のコマンドにより /etc/passwd に関係するイベントだけを表示できます:

# ausearch -k KEY_pwd

異常を探す

The aureport tool can be used to quicly report any anormal event performed on the system, it include network interface used in promiscous mode, process or thread crashing or exiting with ENOMEM error etc.

The easiest way to use aureport is :

# aureport -n

aureport can be used to generate custom report, see man aureport.

どのファイル・システムコールを監査すべきか?

Keep in mind that each audit rule added will generate logs, so you must be ready to treat this amount of information. Basically, each security-related event/file must be monitored, like ids, ips, anti-rootkits etc. On the other side, it's totally useless to track every write syscall, the smallest compilation will fill your logs with this event.

More complex set of rules can be set up, performing auditing on a very fine-grained base. If you want to do so, the man pages of auditctl are worth-reading.

他のホストからのログを収集する

The audit framework has an plugin system which provides the possibility to send local logfiles to an remote auditd.

ログファイルを送信する

To send your logfiles to an remote host you need the audisp-remote plugin which comes automatically with the audit package. Activate the plugin:

/etc/audisp/plugins.d/au-remote.conf
active = yes
direction = out
path = /usr/bin/audisp-remote
type = always
format = string

and set the remote host where the logs should be send to:

/etc/audisp/audisp-remote.conf
remote_server = domain.name.or.ip
port = 60
##local_port = optional
transport = tcp

ログファイルを受け取る

To make audit listen for remote audispds you just need to set the tcp options:

/etc/audit/auditd.conf
tcp_listen_port = 60
tcp_listen_queue = 5
tcp_max_per_addr = 1
##tcp_client_ports = 1024-65535 #optional
tcp_client_max_idle = 0

Now you can view the logs of all configured hosts in the logfiles of the recieving auditd.