Communitygithub.com

分析 Linux 審計日誌以進行入侵偵測

使用 Linux 審計框架(auditd)、ausearch 和 aureport 工具進行主機入侵分析與事件重建。

分析 Linux 審計日誌以進行入侵偵測 是什麼?

這項技能專注於利用 Linux Audit (auditd) 框架進行主機層級的入侵偵測與事後鑑識分析。它能幫助安全分析師或 AI 代理通過 kernel 層的系統調用監控,識別未經授權的存取、權限提升、持續性機制和後門安裝等攻擊行為。技能支援所有安裝了 auditd 的 Linux 發行版,並提供從偵測規則部署、使用 ausearch 查詢特定事件、到使用 aureport 生成摘要報告以及重建攻擊時間線的完整工作流程。它還涵蓋了將審計日誌轉發至 SIEM 系統的方法,並內含關鍵術語表和驗證清單。透過集中監控特定檔案(如 /etc/shadow)與敏感系統調用(如 ptrace),此技能將 auditd 轉變為強大的主機入侵偵測系統。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/analyzing-linux-audit-logs-for-intrusion

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

分析 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:驗證審計守護程式狀態與設定

確認審計系統正在運作,並檢查目前的規則集:

# 檢查 auditd 服務狀態
systemctl status auditd

# 顯示核心中目前載入的審計規則
auditctl -l

# 顯示審計守護程式設定
cat /etc/audit/auditd.conf | grep -E "log_file|max_log_file|num_logs|space_left_action"

# 檢查審計 backlog 是否已超限(遺失事件)
auditctl -s

如果 backlog 限制即將達到,請增加其大小:

auditctl -b 8192

步驟 2:部署針對入侵的審計規則

新增針對常見入侵指標的規則。將這些規則放入 /etc/audit/rules.d/intrusion.rules:

# 監控憑證檔案的未授權讀取或修改
-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

# 監控 SSH 設定與授權金鑰
-w /etc/ssh/sshd_config -p wa -k sshd_config_change
-w /root/.ssh/authorized_keys -p wa -k ssh_key_tampering

# 監控使用者與群組管理指令
-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

# 透過 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

# 監控從非典型目錄執行程式
-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

# 偵測核心模組載入(rootkit 安裝)
-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

# 監控用於反向連線的網路 socket 建立
-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

# 偵測 cron 工作修改(持續性)
-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

# 監控日誌刪除或竄改
-w /var/log/ -p wa -k log_tampering

編輯後重新載入規則:

augenrules --load
auditctl -l | wc -l   # 確認規則數量

步驟 3:使用 ausearch 搜尋入侵指標

使用 ausearch 查詢審計日誌中的特定事件:

# 搜尋過去 24 小時內所有失敗的登入嘗試
ausearch -m USER_LOGIN --success no -ts recent

# 搜尋特定使用者執行的指令
ausearch -ua 1001 -m EXECVE -ts today

# 搜尋對 /etc/shadow 的所有檔案存取事件
ausearch -f /etc/shadow -ts this-week

# 搜尋透過 sudo 進行的權限提升
ausearch -m USER_CMD -ts today

# 搜尋核心模組載入事件
ausearch -k kernel_module_load -ts this-month

# 搜尋從 /tmp 執行的程序(常見攻擊暫存區)
ausearch -k exec_from_tmp -ts this-week

# 搜尋 SSH 金鑰修改
ausearch -k ssh_key_tampering -ts this-month

# 根據審計事件 ID 搜尋特定事件
ausearch -a 12345

# 搜尋特定時間範圍內的事件
ausearch -ts 03/15/2026 08:00:00 -te 03/15/2026 18:00:00

# 解譯系統呼叫號碼並以可讀格式輸出
ausearch -k credential_access -i -ts today

步驟 4:使用 aureport 產生摘要報表

使用 aureport 產生彙總摘要以進行分類:

# 所有驗證事件的摘要
aureport -au -ts this-week --summary

# 所有失敗事件的報表(登入、存取等)
aureport --failed --summary -ts today

# 可執行檔執行報表
aureport -x --summary -ts today

# 所有異常事件的報表(segfault、混雜模式等)
aureport --anomaly -ts this-week

# 檔案存取事件報表
aureport -f --summary -ts today

# 依金鑰分類的所有事件報表(對應您的自訂規則金鑰)
aureport -k --summary -ts this-month

# 所有系統呼叫報表
aureport -s --summary -ts today

# 依使用者分組的事件報表
aureport -u --summary -ts this-week

# 用於建立時間線的詳細時間基礎事件報表
aureport -ts 03/15/2026 08:00:00 -te 03/15/2026 18:00:00 --summary

步驟 5:重建攻擊時間線

結合 ausearch 查詢以建立事件的時間順序敘述:

# 步驟 5a:識別初始存取時間戳記
ausearch -m USER_LOGIN -ua 0 --success yes -ts this-week -i | head -50

# 步驟 5b:追蹤攻擊者在取得存取權後做了什麼
# 從受入侵帳戶取得事件視窗內的所有事件
ausearch -ua <UID> -ts "03/15/2026 14:00:00" -te "03/15/2026 18:00:00" -i \
  | aureport -f -i

# 步驟 5c:擷取事件視窗內所有執行的指令
ausearch -m EXECVE -ts "03/15/2026 14:00:00" -te "03/15/2026 18:00:00" -i

# 步驟 5d:檢查是否安裝了持續性機制
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

# 步驟 5e:檢查橫向移動(對外連線)
ausearch -k network_connection -ts "03/15/2026 14:00:00" -i

步驟 6:將審計日誌轉發至 SIEM

設定 audisp-remote 或 auditbeat 將日誌傳送至集中式 SIEM 進行關聯分析:

# 選項 A:使用 audisp-remote 外掛程式
# 編輯 /etc/audit/plugins.d/au-remote.conf
active = yes
direction = out
path = /sbin/audisp-remote
type = always

# 在 /etc/audit/audisp-remote.conf 中設定遠端目標
remote_server = siem.internal.corp
port = 6514
transport = tcp

# 選項 B:使用 Elastic Auditbeat
# 安裝 auditbeat 並設定 /etc/auditbeat/auditbeat.yml
# Auditbeat 直接從核心審計框架讀取

關鍵概念

術語定義
auditdLinux 審計守護程式,從核心接收審計事件並寫入 /var/log/audit/audit.log
auditctl控制審計系統的命令列工具:新增/移除規則、檢查狀態、設定 backlog 大小
ausearch查詢工具,可依訊息類型、使用者、檔案、金鑰、時間範圍或事件 ID 搜尋審計日誌
aureport報表工具,可產生審計事件的彙總摘要以進行分類與合規
審計規則金鑰 (-k)附加至審計規則的使用者定義標籤,可使用 ausearch 和 aureport 快速篩選相關事件
系統呼叫審計對系統呼叫(execve、open、connect、ptrace)的核心層級監控,可擷取程序與檔案活動
augenrules將 /etc/audit/rules.d/ 中的所有檔案合併為 /etc/audit/audit.rules 並載入至核心的公用程式

驗證

  • auditd 正在運作且規則已載入(auditctl -l 傳回預期的規則數量)
  • 無審計 backlog 溢位(auditctl -s 顯示 backlog: 0 或較低值,lost: 0)
  • ausearch 對每個自訂金鑰傳回事件(ausearch -k <key> -ts today 傳回結果)
  • aureport 對驗證、可執行檔與檔案事件產生非空摘要
  • 時間線重建產生了連貫的攻擊者行動時間順序序列
  • 關鍵檔案監控在測試修改時觸發警報(touch /etc/shadow 產生事件)
  • 日誌正在轉發至集中式 SIEM(使用測試事件驗證並確認接收)
  • 審計規則在重新開機後持續存在(規則位於 /etc/audit/rules.d/,而非僅透過 auditctl 設定)

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

相關技能