使用 Splunk 分析安全日誌
使用時機
- 調查需要關聯多個日誌來源的安全事件
- 使用已知的 TTP 與 IOC 狩獵攻擊者活動
- 為特定攻擊模式建立偵測規則
- 從分散的日誌來源重建事件時間線
- 分析驗證異常、橫向移動或資料外洩模式
切勿使用於即時封包層級分析;請使用 Wireshark 或 Zeek 進行完整封包擷取分析。
前提條件
- 已安裝 Splunk Enterprise 或 Splunk Cloud 及 Enterprise Security (ES) 應用程式
- 已攝入日誌來源:Windows 事件日誌 (透過 Splunk Universal Forwarder 或 WEF)、防火牆、代理伺服器、DNS、EDR、電子郵件閘道
- 已設定 Splunk CIM (Common Information Model) 資料模型以標準化欄位名稱
- 具備中級或以上的 SPL 熟練度
- 在 Splunk 中擁有具備
search和accelerate_search角色的存取權限
工作流程
步驟 1:在 Splunk 中設定調查範圍
根據事件分類資料定義搜尋參數:
| 設定初始調查範圍
index=windows OR index=firewall OR index=proxy
earliest="2025-11-14T00:00:00" latest="2025-11-16T00:00:00"
(host="WKSTN-042" OR src_ip="10.1.5.42" OR user="jsmith")
| stats count by index, sourcetype, host
| sort -count
此查詢可確定調查時間範圍與受影響資產中相關的日誌來源。
步驟 2:分析驗證事件
使用 Windows 安全事件日誌調查可疑的驗證模式:
| 偵測暴力破解與憑證填充
index=windows sourcetype="WinEventLog:Security" EventCode=4625
earliest=-24h
| stats count as failed_attempts, values(src_ip) as source_ips,
dc(src_ip) as unique_sources by TargetUserName
| where failed_attempts > 10
| sort -failed_attempts
| 偵測 Pass-the-Hash (登入類型 9 - NewCredentials)
index=windows sourcetype="WinEventLog:Security" EventCode=4624
Logon_Type=9
| table _time, host, TargetUserName, src_ip, LogonProcessName
| 透過 RDP 偵測橫向移動
index=windows sourcetype="WinEventLog:Security" EventCode=4624
Logon_Type=10
| stats count, values(host) as targets by TargetUserName, src_ip
| where count > 3
| sort -count
步驟 3:追蹤程序執行
使用 Sysmon 日誌重建程序執行鏈:
| 含父程序鏈的程序建立 (Sysmon 事件 ID 1)
index=sysmon EventCode=1 host="WKSTN-042"
earliest="2025-11-15T14:00:00" latest="2025-11-15T15:00:00"
| table _time, ParentImage, ParentCommandLine, Image, CommandLine, User, Hashes
| sort _time
| 偵測可疑的 PowerShell 執行
index=sysmon EventCode=1 Image="*\\powershell.exe"
(CommandLine="*-enc*" OR CommandLine="*-encodedcommand*"
OR CommandLine="*downloadstring*" OR CommandLine="*iex*")
| table _time, host, User, ParentImage, CommandLine
| sort _time
| 偵測 LSASS 憑證傾印
index=sysmon EventCode=10 TargetImage="*\\lsass.exe"
GrantedAccess=0x1010
| table _time, host, SourceImage, SourceUser, GrantedAccess
步驟 4:分析網路活動
將網路日誌與端點事件關聯:
| 偵測 C2 信標模式
index=proxy OR index=firewall dest_ip="185.220.101.42"
| timechart span=1m count by src_ip
| where count > 0
| 偵測 DNS 隧道 (對單一網域的高查詢量)
index=dns
| rex field=query "(?<subdomain>[^\.]+)\.(?<domain>[^\.]+\.[^\.]+)$"
| stats count, avg(len(query)) as avg_query_len by domain, src_ip
| where count > 500 AND avg_query_len > 40
| sort -count
| 偵測大型資料傳輸 (潛在的外洩)
index=proxy action=allowed
| stats sum(bytes_out) as total_bytes by src_ip, dest_ip, dest_host
| eval total_MB=round(total_bytes/1024/1024,2)
| where total_MB > 100
| sort -total_MB
步驟 5:建立事件時間線
在所有日誌來源中重建統一的時間線:
| 統一的事件時間線
index=windows OR index=sysmon OR index=proxy OR index=firewall
(host="WKSTN-042" OR src_ip="10.1.5.42" OR user="jsmith")
earliest="2025-11-15T14:00:00" latest="2025-11-15T16:00:00"
| eval event_summary=case(
sourcetype=="WinEventLog:Security" AND EventCode==4624, "登入: ".TargetUserName." 來自 ".src_ip,
sourcetype=="WinEventLog:Security" AND EventCode==4625, "登入失敗: ".TargetUserName,
sourcetype=="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" AND EventCode==1,
"程序: ".Image." 由 ".User,
sourcetype=="proxy", "網頁: ".http_method." ".url,
1==1, sourcetype.": ".EventCode)
| table _time, sourcetype, host, event_summary
| sort _time
步驟 6:建立偵測規則
將調查結果轉化為持續執行的 Splunk 相關性搜尋:
| 相關性搜尋:由 Office 應用程式啟動的 PowerShell
index=sysmon EventCode=1
Image="*\\powershell.exe"
(ParentImage="*\\winword.exe" OR ParentImage="*\\excel.exe"
OR ParentImage="*\\outlook.exe")
| eval severity="high"
| eval mitre_technique="T1059.001"
| collect index=notable_events
關鍵概念
| 術語 | 定義 |
|---|---|
| SPL (Search Processing Language) | Splunk 的查詢語言,用於搜尋、過濾、轉換和視覺化機器資料 |
| CIM (Common Information Model) | Splunk 的欄位標準化模型,將供應商特定的欄位名稱對應到通用名稱,以便進行跨來源查詢 |
| Notable Event | Splunk Enterprise Security 中根據相關性搜尋比對而被標記供分析師審查的事件 |
| 資料模型 (Data Model) | Splunk 中索引資料的結構化表示,支援加速搜尋和基於樞紐的分析 |
| Sourcetype | Splunk 中的分類標籤,定義特定日誌類型的格式和解析規則 |
| 相關性搜尋 (Correlation Search) | 在 Splunk 中排程的持續執行搜尋,當條件符合時產生 Notable 事件 |
| 時間圖表 (Timechart) | SPL 指令,用於建立時間序列視覺化以識別模式、異常和趨勢 |
工具與系統
- Splunk Enterprise Security (ES):進階 SIEM 應用程式,提供相關性搜尋、基於風險的警報和調查工作檯
- Splunk SOAR:與 Splunk ES 整合的協調平台,用於自動化回應劇本
- Sysmon:Microsoft 系統監控工具,提供詳細的程序、網路和檔案變更遙測資料,並攝入 Splunk
- Splunk Attack Analyzer:自動化威脅分析工具,可引爆可疑檔案和 URL,並將結果饋送至 Splunk
- BOSS of the SOC (BOTS):SANS/Splunk 培訓資料集,用於練習事件調查的 SPL 查詢
常見情境
情境:調查導致帳號劫持的憑證填充攻擊
背景:安全維運中心收到警報,顯示一個帳號在 30 分鐘內從地理上分散的 IP 位址成功登入多次。
方法:
- 查詢受影響帳號的事件 ID 4624,以繪製所有登入來源和時間
- 使用 Splunk 查閱表格將登入 IP 與威脅情报饋送進行關聯
- 檢查代理伺服器日誌中從驗證會話產生的可疑活動
- 搜尋來自身分遭洩露帳號的橫向移動 (對其他主機的事件 ID 4624 類型 3)
- 建立時間線,顯示憑證填充嘗試、成功登入和入侵後活動
- 建立相關性搜尋以偵測其他帳號的類似模式
陷阱:
- 僅搜尋過去 24 小時,而憑證填充可能發生在數週內
- 未檢查 VPN 日誌,這些日誌可能顯示同一帳號從不可能的旅行距離進行驗證
- 未能標準化跨不同時區日誌來源的時間戳記
輸出格式
SPLUNK 調查報告
============================
事件編號: INC-2025-1547
分析師: [姓名]
調查期間: 2025-11-14 00:00 UTC - 2025-11-16 00:00 UTC
搜尋範圍
索引: windows, sysmon, proxy, firewall, dns
主機: WKSTN-042, SRV-FILE01
使用者: jsmith, svc-backup
來源 IP: 10.1.5.42, 10.1.10.15
主要發現
1. [時間戳記] - 透過網路釣魚初始入侵 (Sysmon 事件 1)
2. [時間戳記] - 建立 C2 (代理伺服器日誌,偵測到信標模式)
3. [時間戳記] - 憑證遭竊 (Sysmon 事件 10,LSASS 存取)
4. [時間戳記] - 橫向移動至 SRV-FILE01 (事件 4624 類型 3)
5. [時間戳記] - 資料分階段與外洩 (代理伺服器 bytes_out 異常)
使用的 SPL 查詢
[含說明的關鍵查詢編號清單]
已識別的偵測缺口
- SRV-FILE01 上未部署 Sysmon (盲區)
- 代理伺服器日誌缺少對 C2 網域的 SSL 檢查
- 未啟用 PowerShell ScriptBlock 記錄
建議的偵測規則
1. Office 啟動 PowerShell 的相關性搜尋
2. LSASS 存取模式的閾值警示
3. 信標間隔網路流量的行為規則