$npx -y skills add killvxk/cybersecurity-skills-zh --skill analyzing-security-logs-with-splunk利用 Splunk Enterprise Security 和 SPL(Search Processing Language,搜索处理语言),通过日志关联、时间线重建和异常检测来调查安全事件。涵盖 Windows 事件日志、防火墙日志、代理日志和认证数据分析。适用于 Splunk 调查、SPL 查询、SIEM 日志分析、安全事件关联或基于日志的事件调查相关请求。
| 1 | # 使用 Splunk 分析安全日志 |
| 2 | |
| 3 | ## 适用场景 |
| 4 | |
| 5 | - 调查需要跨多个日志源进行关联的安全事件 |
| 6 | - 使用已知 TTP 和 IOC 进行威胁狩猎 |
| 7 | - 针对特定攻击模式构建检测规则 |
| 8 | - 从分散的日志源中重建事件时间线 |
| 9 | - 分析异常认证行为、横向移动或数据外泄模式 |
| 10 | |
| 11 | **不适用于**实时数据包级别分析;全流量分析请使用 Wireshark 或 Zeek。 |
| 12 | |
| 13 | ## 前置条件 |
| 14 | |
| 15 | - 安装了 Enterprise Security(ES)应用的 Splunk Enterprise 或 Splunk Cloud |
| 16 | - 已接入的日志源:Windows 事件日志(通过 Splunk Universal Forwarder 或 WEF)、防火墙、代理、DNS、EDR、邮件网关 |
| 17 | - 配置了 Splunk CIM(Common Information Model,通用信息模型)数据模型,用于规范化字段名 |
| 18 | - 中级及以上 SPL 能力 |
| 19 | - 在 Splunk 中拥有 `search` 和 `accelerate_search` 能力的基于角色的访问权限 |
| 20 | |
| 21 | ## 工作流程 |
| 22 | |
| 23 | ### 步骤 1:在 Splunk 中界定调查范围 |
| 24 | |
| 25 | 根据事件分诊数据定义搜索参数: |
| 26 | |
| 27 | ```spl |
| 28 | | 设置初始调查范围 |
| 29 | index=windows OR index=firewall OR index=proxy |
| 30 | earliest="2025-11-14T00:00:00" latest="2025-11-16T00:00:00" |
| 31 | (host="WKSTN-042" OR src_ip="10.1.5.42" OR user="jsmith") |
| 32 | | stats count by index, sourcetype, host |
| 33 | | sort -count |
| 34 | ``` |
| 35 | |
| 36 | 此查询确定哪些日志源包含调查时间段和受影响资产的相关数据。 |
| 37 | |
| 38 | ### 步骤 2:分析认证事件 |
| 39 | |
| 40 | 使用 Windows 安全事件日志调查可疑认证模式: |
| 41 | |
| 42 | ```spl |
| 43 | | 检测暴力破解和撞库攻击 |
| 44 | index=windows sourcetype="WinEventLog:Security" EventCode=4625 |
| 45 | earliest=-24h |
| 46 | | stats count as failed_attempts, values(src_ip) as source_ips, |
| 47 | dc(src_ip) as unique_sources by TargetUserName |
| 48 | | where failed_attempts > 10 |
| 49 | | sort -failed_attempts |
| 50 | |
| 51 | | 检测哈希传递(Logon Type 9 - NewCredentials) |
| 52 | index=windows sourcetype="WinEventLog:Security" EventCode=4624 |
| 53 | Logon_Type=9 |
| 54 | | table _time, host, TargetUserName, src_ip, LogonProcessName |
| 55 | |
| 56 | | 通过 RDP 检测横向移动 |
| 57 | index=windows sourcetype="WinEventLog:Security" EventCode=4624 |
| 58 | Logon_Type=10 |
| 59 | | stats count, values(host) as targets by TargetUserName, src_ip |
| 60 | | where count > 3 |
| 61 | | sort -count |
| 62 | ``` |
| 63 | |
| 64 | ### 步骤 3:追踪进程执行 |
| 65 | |
| 66 | 使用 Sysmon 日志重建进程执行链: |
| 67 | |
| 68 | ```spl |
| 69 | | 带父进程链的进程创建(Sysmon Event ID 1) |
| 70 | index=sysmon EventCode=1 host="WKSTN-042" |
| 71 | earliest="2025-11-15T14:00:00" latest="2025-11-15T15:00:00" |
| 72 | | table _time, ParentImage, ParentCommandLine, Image, CommandLine, User, Hashes |
| 73 | | sort _time |
| 74 | |
| 75 | | 检测可疑 PowerShell 执行 |
| 76 | index=sysmon EventCode=1 Image="*\\powershell.exe" |
| 77 | (CommandLine="*-enc*" OR CommandLine="*-encodedcommand*" |
| 78 | OR CommandLine="*downloadstring*" OR CommandLine="*iex*") |
| 79 | | table _time, host, User, ParentImage, CommandLine |
| 80 | | sort _time |
| 81 | |
| 82 | | 检测 LSASS 凭据转储 |
| 83 | index=sysmon EventCode=10 TargetImage="*\\lsass.exe" |
| 84 | GrantedAccess=0x1010 |
| 85 | | table _time, host, SourceImage, SourceUser, GrantedAccess |
| 86 | ``` |
| 87 | |
| 88 | ### 步骤 4:分析网络活动 |
| 89 | |
| 90 | 将网络日志与端点事件进行关联: |
| 91 | |
| 92 | ```spl |
| 93 | | 检测 C2 信标模式 |
| 94 | index=proxy OR index=firewall dest_ip="185.220.101.42" |
| 95 | | timechart span=1m count by src_ip |
| 96 | | where count > 0 |
| 97 | |
| 98 | | 检测 DNS 隧道(向单一域名发送大量查询) |
| 99 | index=dns |
| 100 | | rex field=query "(?<subdomain>[^\.]+)\.(?<domain>[^\.]+\.[^\.]+)$" |
| 101 | | stats count, avg(len(query)) as avg_query_len by domain, src_ip |
| 102 | | where count > 500 AND avg_query_len > 40 |
| 103 | | sort -count |
| 104 | |
| 105 | | 检测大量数据传输(潜在外泄) |
| 106 | index=proxy action=allowed |
| 107 | | stats sum(bytes_out) as total_bytes by src_ip, dest_ip, dest_host |
| 108 | | eval total_MB=round(total_bytes/1024/1024,2) |
| 109 | | where total_MB > 100 |
| 110 | | sort -total_MB |
| 111 | ``` |
| 112 | |
| 113 | ### 步骤 5:构建事件时间线 |
| 114 | |
| 115 | 跨所有日志源重建统一时间线: |
| 116 | |
| 117 | ```spl |
| 118 | | 统一事件时间线 |
| 119 | index=windows OR index=sysmon OR index=proxy OR index=firewall |
| 120 | (host="WKSTN-042" OR src_ip="10.1.5.42" OR user="jsmith") |
| 121 | earliest="2025-11-15T14:00:00" latest="2025-11-15T16:00:00" |
| 122 | | eval event_summary=case( |
| 123 | sourcetype=="WinEventLog:Security" AND EventCode==4624, "登录: ".TargetUserName." 来自 ".src_ip, |
| 124 | sourcetype=="WinEventLog:Security" AND EventCode==4625, "登录失败: ".TargetUserName, |
| 125 | sourcetype=="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" AND EventCode==1, |
| 126 | "进程: ".Image." 由 ".User." 执行", |
| 127 | sourcetype=="proxy", "Web: ".http_method." ".url, |
| 128 | 1==1, sourcetype.": ".EventCode) |
| 129 | | table _time, sourcetype, host, event_summary |
| 130 | | sort _time |
| 131 | ``` |
| 132 | |
| 133 | ### 步骤 6:创建检测规则 |
| 134 | |
| 135 | 将调查发现转化为持续性 Splunk 关联搜索: |
| 136 | |
| 137 | ```spl |
| 138 | | 关联搜索:Office 应用程序生成的 PowerShell |
| 139 | index=sysmon EventCode=1 |
| 140 | Image="*\\powershell.exe" |
| 141 | (ParentImage="*\\winword.exe" OR ParentImage="*\\excel.exe" |
| 142 | OR ParentImage="*\\outlook.exe") |
| 143 | | eval severity="high" |
| 144 | | eval mitre_technique="T1059.001" |
| 145 | | collect index=notable_events |
| 146 | ``` |
| 147 | |
| 148 | ## 核心概念 |
| 149 | |
| 150 | | 术语 | 定义 | |
| 151 | |------|------| |
| 152 | | **SPL(搜索处理语言)** | Splunk 的查询语言,用于搜索、过滤、转换和可视化机器数据 | |
| 153 | | **CIM(通用信息模型)** | Splunk 的字段规范化标准,将厂商特定字段名映射为通用名称,以支持跨源查询 | |
| 154 | | **Notable Event(显著事件)** | Splunk Enterprise Security 中基于关联搜索匹配而标记供分析师审查的事件 | |
| 155 | | **Data Model(数据模型)** | Splunk 中索引数据的结构化表示,支持加速搜索和基于透视的分析 | |
| 156 | | **Sourcetype(数据源类型)** | Splunk 中定义特定日志类型格式和解析规则的分类标签 | |
| 157 | | **Correlation Search(关联搜索)** | 持续运行的 Splunk 计划搜索,当条件满足时生成显著事件 | |
| 158 | | **Timechart(时间图表)** | SPL 命令,创建时序可视化图表以识别模式、异常和趋势 | |
| 159 | |
| 160 | ## 工具与系统 |
| 161 | |
| 162 | - **Splunk Enterprise Security(ES)**:高级 SIEM 应用,提供关联搜索、基于风险的告警和调查工作台 |
| 163 | - **Splunk SOAR**:与 Splunk ES 集成的编排平台,用于自动化响应手册 |
| 164 | - **Sysmon**:Microsoft 系统监控工具,提供详细的进程、网络和文件变更遥测,并接入 Splunk |
| 165 | - **Splunk Attack Analyzer**:自动化威胁分析工具,对可疑文件和 URL 进行沙箱分析,并将结果输入 Splunk |
| 166 | - **BOSS of the SOC(BOT |