mcpField
A
analyzing-linux-audit-logs-for-intrusion

analyzing-linux-audit-logs-for-intrusion

github.com/mukul975セキュリティ35.2k525 回インストール8 週間前に更新
リポジトリ

analyzing-linux-audit-logs-for-intrusion について

Linux ホストの調査と監査に使うセキュリティスキルです。auditd ルールの設定、侵入の痕跡の検索、タイムラインの再構成、SIEM へのログ転送を案内します。

主な機能

  1. 01auditd の状態とルールの確認
  2. 02侵入調査用監査ルールの設定
  3. 03イベント、ユーザー、時刻によるログ検索
  4. 04監査サマリーレポートの生成
  5. 05攻撃者の行動タイムラインの再構成
  6. 06監査ログの SIEM 転送

活用シーン

  1. 01Linux ホストへの不正アクセスの調査
  2. 02権限昇格や永続化の追跡
  3. 03重要ファイルの改ざん確認
  4. 04コンプライアンス向け監査イベントの集計

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill analyzing-linux-audit-logs-for-intrusion

インストール後、Claude Code で/analyzing-linux-audit-logs-for-intrusionを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

LICENSE
references/
api-reference.md
scripts/
agent.py

詳細

侵入調査のための Linux 監査ログ分析

使用する場面

  • Linux ホストへの不正アクセスや権限昇格が疑われる場合の調査
  • 悪用、バックドアのインストール、永続化の仕組みに関する証拠の探索
  • システムコールの監視が求められるセキュリティベースライン(CIS、STIG、PCI-DSS)への準拠状況の監査
  • インシデント対応中に攻撃者の行動タイムラインを再構築
  • /etc/passwd、/etc/shadow、SSH 鍵などの重要なシステムファイルへの改ざんを検知

ネットワークレベルの侵入検知には使用しないでください。ネットワークトラフィックの分析には Suricata または Zeek を使用してください。Auditd は個々のホスト上でカーネルレベルで動作します。

前提条件

  • auditd パッケージがインストールされ、監査デーモンが実行中の Linux システム(systemctl status auditd)
  • 監査ルールの設定とログの検索に必要な root または sudo アクセス権
  • /etc/audit/rules.d/*.rules 経由で監査ルールが配置されているか、auditctl で読み込まれていること
  • 推奨:包括的なベースラインを網羅する、GitHub の Neo23x0/auditd ルールセット
  • Linux システムコール(execve、open、connect、ptrace など)の知識
  • 十分な保持期間を確保したログストレージ(デフォルトの保存場所:/var/log/audit/audit.log)

ワークフロー

ステップ 1:監査デーモンの状態と設定を確認する

監査システムが実行中であることを確認し、現在のルールセットを確認します。

# Check auditd service status
systemctl status auditd

# Show current audit rules loaded in the kernel
auditctl -l

# Show audit daemon configuration
cat /etc/audit/auditd.conf | grep -E "log_file|max_log_file|num_logs|space_left_action"

# Check if the audit backlog is being exceeded (dropped events)
auditctl -s

バックログの上限に達している場合は、値を引き上げます。

auditctl -b 8192
ステップ 2:侵入に焦点を当てた監査ルールを配置する

一般的な侵入の兆候を対象とするルールを追加します。これらを /etc/audit/rules.d/intrusion.rules に配置します。

# Monitor credential files for unauthorized reads or modifications
-w /etc/passwd -p wa -k credential_access
-w /etc/shadow -p rwa -k credential_access
-w /etc/gshadow -p rwa -k credential_access
-w /etc/sudoers -p wa -k privilege_escalation
-w /etc/sudoers.d/ -p wa -k privilege_escalation

# Monitor SSH configuration and authorized keys
-w /etc/ssh/sshd_config -p wa -k sshd_config_change
-w /root/.ssh/authorized_keys -p wa -k ssh_key_tampering

# Monitor user and group management commands
-w /usr/sbin/useradd -p x -k user_management
-w /usr/sbin/usermod -p x -k user_management
-w /usr/sbin/groupadd -p x -k user_management

# Detect process injection via ptrace
-a always,exit -F arch=b64 -S ptrace -F a0=0x4 -k process_injection
-a always,exit -F arch=b64 -S ptrace -F a0=0x5 -k process_injection
-a always,exit -F arch=b64 -S ptrace -F a0=0x6 -k process_injection

# Monitor execution of programs from unusual directories
-a always,exit -F arch=b64 -S execve -F exe=/tmp -k exec_from_tmp
-a always,exit -F arch=b64 -S execve -F exe=/dev/shm -k exec_from_shm

# Detect kernel module loading (rootkit installation)
-a always,exit -F arch=b64 -S init_module -S finit_module -k kernel_module_load
-a always,exit -F arch=b64 -S delete_module -k kernel_module_remove
-w /sbin/insmod -p x -k kernel_module_tool
-w /sbin/modprobe -p x -k kernel_module_tool

# Monitor network socket creation for reverse shells
-a always,exit -F arch=b64 -S socket -F a0=2 -k network_socket_created
-a always,exit -F arch=b64 -S connect -F a0=2 -k network_connection

# Detect cron job modifications (persistence)
-w /etc/crontab -p wa -k cron_persistence
-w /etc/cron.d/ -p wa -k cron_persistence
-w /var/spool/cron/ -p wa -k cron_persistence

# Monitor log deletion or tampering
-w /var/log/ -p wa -k log_tampering

編集後、ルールを再読み込みします。

augenrules --load
auditctl -l | wc -l   # Confirm rule count
ステップ 3:ausearch で侵入の兆候を検索する

ausearch を使用して、監査ログから特定のイベントを検索します。

# Search for all failed login attempts in the last 24 hours
ausearch -m USER_LOGIN --success no -ts recent

# Search for commands executed by a specific user
ausearch -ua 1001 -m EXECVE -ts today

# Search for all file access events on /etc/shadow
ausearch -f /etc/shadow -ts this-week

# Search for privilege escalation via sudo
ausearch -m USER_CMD -ts today

# Search for kernel module loading events
ausearch -k kernel_module_load -ts this-month

# Search for processes executed from /tmp (common attack staging)
ausearch -k exec_from_tmp -ts this-week

# Search for SSH key modifications
ausearch -k ssh_key_tampering -ts this-month

# Search for a specific event by audit event ID
ausearch -a 12345

# Search events in a specific time range
ausearch -ts 03/15/2026 08:00:00 -te 03/15/2026 18:00:00

# Interpret syscall numbers and format output readably
ausearch -k credential_access -i -ts today
ステップ 4:aureport でサマリーレポートを生成する

aureport を使用して、トリアージ用の集計サマリーを作成します。

# Summary of all authentication events
aureport -au -ts this-week --summary

# Report of all failed events (login, access, etc.)
aureport --failed --summary -ts today

# Report of executable runs
aureport -x --summary -ts today

# Report of all anomaly events (segfaults, promiscuous mode, etc.)
aureport --anomaly -ts this-week

# Report of file access events
aureport -f --summary -ts today

# Report of all events by key (maps to your custom rule keys)
aureport -k --summary -ts this-month

# Report of all system calls
aureport -s --summary -ts today

# Report of events grouped by user
aureport -u --summary -ts this-week

# Detailed time-based event report for timeline building
aureport -ts 03/15/2026 08:00:00 -te 03/15/2026 18:00:00 --summary
ステップ 5:攻撃のタイムラインを再構築する

ausearch の検索を組み合わせて、時系列に沿った経緯を組み立てます。

# Step 5a: Identify the initial access timestamp
ausearch -m USER_LOGIN -ua 0 --success yes -ts this-week -i | head -50

# Step 5b: Trace what the attacker did after gaining access
# Get all events from the compromised account within the incident window
ausearch -ua <UID> -ts "03/15/2026 14:00:00" -te "03/15/2026 18:00:00" -i \
  | aureport -f -i

# Step 5c: Extract all commands executed during the incident window
ausearch -m EXECVE -ts "03/15/2026 14:00:00" -te "03/15/2026 18:00:00" -i

# Step 5d: Check for persistence mechanisms installed
ausearch -k cron_persistence -ts "03/15/2026 14:00:00" -i
ausearch -k ssh_key_tampering -ts "03/15/2026 14:00:00" -i

# Step 5e: Check for lateral movement (outbound connections)
ausearch -k network_connection -ts "03/15/2026 14:00:00" -i
ステップ 6:監査ログを SIEM に転送する

audisp-remote または auditbeat を設定してログを中央の SIEM に送信し、相関分析できるようにします。

# Option A: Using audisp-remote plugin
# Edit /etc/audit/plugins.d/au-remote.conf
active = yes
direction = out
path = /sbin/audisp-remote
type = always

# Configure remote target in /etc/audit/audisp-remote.conf
remote_server = siem.internal.corp
port = 6514
transport = tcp

# Option B: Using Elastic Auditbeat
# Install auditbeat and configure /etc/auditbeat/auditbeat.yml
# Auditbeat reads directly from the kernel audit framework

主な概念

用語定義
auditdカーネルから監査イベントを受信し、/var/log/audit/audit.log に書き込む Linux Audit デーモン
auditctl監査システムを制御するコマンドラインユーティリティ。ルールの追加・削除、状態の確認、バックログサイズの設定を行います
ausearchメッセージタイプ、ユーザー、ファイル、キー、時間範囲、イベント ID で監査ログを検索するツール
aureportトリアージとコンプライアンス対応のために監査イベントの集計サマリーを生成するレポートツール
監査ルールキー(-k)監査ルールに付与するユーザー定義のラベル。ausearch と aureport で関連イベントをすばやく絞り込めます
システムコール監査システムコール(execve、open、connect、ptrace)をカーネルレベルで監視し、プロセスとファイルのアクティビティを記録します
augenrules/etc/audit/rules.d/ 内のすべてのファイルを /etc/audit/audit.rules に統合し、カーネルに読み込むユーティリティ

検証

  • auditd が実行中で、ルールが読み込まれている(auditctl -l が想定したルール数を返す)
  • 監査バックログのオーバーフローがない(auditctl -s で backlog: 0 または低い値、lost: 0 が表示される)
  • カスタムキーごとに ausearch がイベントを返す(ausearch -k <key> -ts today が結果を返す)
  • aureport が認証、実行ファイル、ファイルイベントについて空でないサマリーを生成する
  • タイムラインの再構築により、攻撃者の行動が一貫した時系列で示される
  • 重要なファイルの監視ルールがテスト変更時にアラートを発する(touch /etc/shadow でイベントが生成される)
  • ログが中央の SIEM に転送されている(テストイベントで確認し、受信を確かめる)
  • 再起動後も監査ルールが保持される(auditctl 経由だけでなく、/etc/audit/rules.d/ にルールがある)

コメント