基于 Splunk 检测横向移动(Lateral Movement)实战指南:SPL 查询、事件源映射与脚本化狩猎参考
【免费下载链接】Anthropic-Cybersecurity-Skills817 structured cybersecurity skills for AI agents · Mapped to 6 frameworks: MITRE ATT&CK, NIST CSF 2.0, MITRE ATLAS, D3FEND, NIST AI RMF & MITRE F3 (Fight Fraud) · agentskills.io standard · Works with Claude Code, GitHub Copilot, Codex CLI, Cursor, Gemini CLI & 20+ platforms · 29 security domains · Apache 2.0项目地址: https://gitcode.com/GitHub_Trending/an/Anthropic-Cybersecurity-Skills
本文是 Anthropic-Cybersecurity-Skills 仓库中detecting-lateral-movement-with-splunk技能(SKILL)的完整技术参考,围绕 MITRE ATT&CK TA0008(Lateral Movement)战术展开:从 Windows 认证日志、SMB 流量与远程服务滥用(WMI / PsExec / RDP / WinRM)的检测原理,到可直接落地运行的 Splunk SPL 查询、splunklib Python SDK 调用与命令行狩猎脚本。读完本文,你将掌握一套覆盖网络登录分析、管理共享访问、服务创建、WMI/DCOM 远程执行、认证图构建与异常检测的横向移动狩猎方案,并能够在 Splunk 环境中复现执行。
一、横向移动检测全景:关键技术、MITRE ID 与事件源映射
横向移动(Lateral Movement)指攻击者利用已获取的凭据或会话,在多个受控系统之间跳跃,逐步逼近高价值目标的过程。在 Splunk 中检测横向移动,核心思路是把每条“移动”映射为可查询的认证事件、进程事件与网络事件。下表是 api-reference.md 给出的核心检测矩阵:
| 技术 | MITRE ID | 事件源 |
|---|---|---|
| Pass-the-Hash | T1550.002 | Event 4624 Logon_Type=3 NTLM |
| PSExec | T1569.002 | Sysmon Event 1 (PSEXESVC.exe) |
| WMI Remote Exec | T1047 | Sysmon Event 1 (wmiprvse.exe) |
| RDP Pivoting | T1021.001 | Event 4624 Logon_Type=10 |
| SMB/Admin Share | T1021.002 | Network logs dest_port=445 |
| WinRM | T1021.006 | Sysmon Event 1 (wsmprovhost.exe) |
在 standards.md 中,这一矩阵被进一步扩展为更完整的 ATT&CK 战术覆盖:
| 技术 | 名称 | 事件特征 |
|---|---|---|
| T1021.001 | Remote Desktop Protocol | Logon Type 10、RDP 证书事件 |
| T1021.002 | SMB/Windows Admin Shares | Logon Type 3、ADMIN$/C$/IPC$ 访问 |
| T1021.003 | Distributed COM | Logon Type 3、DCOM 进程创建 |
| T1021.004 | SSH | OpenSSH 认证事件 |
| T1021.006 | Windows Remote Management | WinRM/WSMan 登录事件 |
| T1047 | Windows Management Instrumentation | WMI 远程进程创建 |
| T1569.002 | Service Execution | PsExec 服务安装 + Type 3 登录 |
| T1570 | Lateral Tool Transfer | 通过 SMB/RDP 复制文件 |
| T1550.002 | Pass the Hash | Type 3 登录 + NTLM 认证 |
| T1550.003 | Pass the Ticket | 无前置 TGT 的 Kerberos TGS |
技能元数据(见 SKILL.md 的 frontmatter)同时声明了对应的 D3FEND 防护技术(Application Protocol Command Analysis、Network Isolation、Network Traffic Analysis、Client-server Payload Profiling、Network Traffic Community Deviation)与 NIST CSF 控制项(DE.CM-01、DE.AE-02、DE.AE-07、ID.RA-05),说明该技能在设计时同时面向威胁狩猎与合规映射两大场景。
二、适用场景与数据前提
根据 SKILL.md,该技能适用于以下场景:
- 在多个受控系统之间狩猎攻击者移动行为;
- 检测到凭据窃取后,追踪随后的横向活动;
- 调查全网范围内不寻常的认证模式;
- 在事件响应期间界定入侵的波及范围;
- 主动狩猎 TA0008(Lateral Movement)战术技术。
运行前提包括:
- Splunk Enterprise 或 Splunk Cloud,且已接入 Windows 事件数据;
- Windows Security Event Log 已转发(重点事件 4624、4625、4648、4672、4768、4769);
- 已部署 Sysmon 以获取进程创建与网络连接数据;
- 有网络流量数据或防火墙日志用于 SMB/RDP/WinRM 关联;
- 有 Active Directory 用户与组成员引用数据。
三、SPL 查询语法:核心检测模式
api-reference.md 给出了两个最基础的 SPL 检测模板:
# Pass-the-Hash detection index=wineventlog EventCode=4624 Logon_Type=3 | where Authentication_Package="NTLM" | stats dc(Computer) as targets by Source_Network_Address | where targets > 3 # PSExec detection index=sysmon EventCode=1 | where ParentImage="*\\services.exe" AND Image="*\\PSEXESVC.exe"第一段查询的逻辑是:网络登录(Type 3)+ NTLM 认证包 → 按源 IP 统计去重目标主机数 → 超过 3 台即告警。这对应 Pass-the-Hash 的典型行为——攻击者用一个 NTLM 哈希在短时间内横向认证到多台机器。第二段则直接匹配 Sysmon 进程创建事件中services.exe派生的PSEXESVC.exe,这是 PsExec 服务执行的标志性特征。
3.1 Phase 1:网络登录分析
workflows.md 将狩猎流程拆为六个阶段,第一阶段聚焦网络登录。
Step 1.1 - Type 3 网络登录(SMB、WinRM):
index=wineventlog EventCode=4624 Logon_Type=3 | where NOT match(Account_Name, "(?i)(SYSTEM|ANONYMOUS|\\$)") | stats count dc(Computer) as unique_destinations values(Computer) as destinations by Account_Name Source_Network_Address | where unique_destinations > 3 | sort -unique_destinationsStep 1.2 - Type 10 RDP 登录:
index=wineventlog EventCode=4624 Logon_Type=10 | stats count by Account_Name Source_Network_Address Computer | lookup dnslookup clientip as Source_Network_Address OUTPUT clienthost as src_hostname | table Account_Name src_hostname Source_Network_Address Computer count | sort -countStep 1.3 - 显式凭据登录(PsExec、RunAs):
index=wineventlog EventCode=4648 | where NOT match(Target_Server_Name, "(?i)(localhost|\\$)") | stats count values(Target_Server_Name) as targets by Account_Name Process_Name Computer | sort -count3.2 Phase 2:管理共享访问检测
Step 2.1 - ADMIN$ 与 C$ 共享访问:
index=wineventlog EventCode=5140 | where Share_Name IN ("\\\\*\\ADMIN$", "\\\\*\\C$", "\\\\*\\IPC$") | where NOT match(Account_Name, "(?i)(\\$|SYSTEM)") | stats count values(Share_Name) as shares by Account_Name Source_Address Computer | sort -countStep 2.2 - 管理共享上的 SMB 文件操作:
index=wineventlog EventCode=5145 | where match(Share_Name, "(?i)(ADMIN\\$|C\\$)") | where match(Relative_Target_Name, "(?i)(\\.exe|\\.dll|\\.ps1|\\.bat|\\.cmd)") | stats count by Account_Name Source_Address Share_Name Relative_Target_Name Computer3.3 Phase 3:基于服务的横向移动
Step 3.1 - PsExec 服务安装:
index=wineventlog EventCode=7045 | where match(Service_File_Name, "(?i)(psexec|PSEXESVC|cmd\.exe|powershell)") | table _time Computer Service_Name Service_File_Name Service_AccountStep 3.2 - 远程服务创建关联(将服务创建事件与 Type 3 网络登录 join,追溯横向移动来源):
index=wineventlog EventCode=7045 | eval is_suspicious=if(match(Service_File_Name, "(?i)(temp|appdata|cmd|powershell)"), 1, 0) | where is_suspicious=1 | join Computer [ search index=wineventlog EventCode=4624 Logon_Type=3 | rename Computer as Computer, Source_Network_Address as lateral_src ] | table _time Computer Service_Name Service_File_Name lateral_src3.4 Phase 4:WMI 与 DCOM 横向移动
Step 4.1 - 远程 WMI 执行:
index=sysmon EventCode=1 | where match(ParentImage, "(?i)WmiPrvSE\.exe") AND NOT match(Image, "(?i)(WmiApSrv|scrcons)") | table _time Computer User ParentImage Image CommandLineStep 4.2 - DCOM 横向移动(利用 mmc.exe、excel.exe、outlook.exe 等 DCOM 宿主进程派生命令行的模式):
index=sysmon EventCode=1 | where match(ParentImage, "(?i)(mmc\.exe|excel\.exe|outlook\.exe)") | where match(Image, "(?i)(cmd\.exe|powershell\.exe|mshta\.exe)") | table _time Computer User ParentImage Image CommandLine四、认证图分析与异常检测
横向移动检测的进阶目标是从“单条告警”升级为“全网移动路径”。
Step 5.1 - 构建横向移动图(以源IP -> 目标主机为边聚合):
index=wineventlog EventCode=4624 Logon_Type IN (3, 10) | where NOT match(Account_Name, "(?i)(\\$|SYSTEM|ANONYMOUS)") | eval connection=Source_Network_Address."->".Computer | stats count first(_time) as first_seen last(_time) as last_seen by connection Account_Name | sort -countStep 5.2 - 首次出现的源-目标对(用子查询排除过去 30 天的历史基线,识别“从未见过”的新关系):
index=wineventlog EventCode=4624 Logon_Type IN (3, 10) earliest=-1d | where NOT match(Account_Name, "(?i)(\\$|SYSTEM)") | eval pair=Account_Name.":".Source_Network_Address."->".Computer | search NOT [ | search index=wineventlog EventCode=4624 Logon_Type IN (3, 10) earliest=-30d latest=-1d | eval pair=Account_Name.":".Source_Network_Address."->".Computer | dedup pair | fields pair ] | stats count by pair | sort -countStep 6.1 - 速度异常(短时间多主机访问):
index=wineventlog EventCode=4624 Logon_Type=3 | where NOT match(Account_Name, "(?i)(\\$|SYSTEM)") | bin _time span=10m | stats dc(Computer) as hosts_accessed values(Computer) as destinations by _time Account_Name Source_Network_Address | where hosts_accessed > 5 | sort -hosts_accessedStep 6.2 - 非工作时间横向移动:
index=wineventlog EventCode=4624 Logon_Type IN (3, 10) | where NOT match(Account_Name, "(?i)(\\$|SYSTEM)") | eval hour=strftime(_time, "%H") | where hour < 6 OR hour > 22 | stats count by Account_Name Source_Network_Address Computer hour | sort -countStep 6.3 - 服务账户横向移动:
index=wineventlog EventCode=4624 Logon_Type=10 | where match(Account_Name, "(?i)(svc_|service|admin)") | stats count by Account_Name Source_Network_Address Computer | sort -count五、Windows 登录类型与关键事件 ID 参考
理解 Logon Type 是解读认证日志的基础。api-reference.md 给出常用子集:
| Type | 描述 |
|---|---|
| 2 | Interactive(控制台) |
| 3 | Network(SMB、PSExec) |
| 7 | Unlock |
| 10 | RemoteInteractive(RDP) |
standards.md 提供了完整版本,供日常对照:
| Type | 名称 | 描述 |
|---|---|---|
| 2 | Interactive | 本地控制台登录 |
| 3 | Network | SMB、映射驱动器、WinRM |
| 4 | Batch | 计划任务执行 |
| 5 | Service | 服务启动 |
| 7 | Unlock | 工作站解锁 |
| 8 | NetworkCleartext | IIS 基本认证 |
| 9 | NewCredentials | RunAs /netonly |
| 10 | RemoteInteractive | RDP、终端服务 |
| 11 | CachedInteractive | 缓存域登录 |
横向移动中,Type 3(Network)与 Type 10(RemoteInteractive)是两条最高频的攻击通道:SMB/WinRM/共享映射走 Type 3,RDP 走 Type 10。
关键 Windows 事件 ID 参考表(来自 standards.md):
| 事件 ID | 来源 | 描述 |
|---|---|---|
| 4624 | Security | 账户登录成功 |
| 4625 | Security | 账户登录失败 |
| 4648 | Security | 使用显式凭据登录 |
| 4672 | Security | 分配特殊权限(管理员登录) |
| 4768 | Security | 请求 Kerberos TGT |
| 4769 | Security | 请求 Kerberos TGS |
| 4776 | Security | NTLM 凭据验证 |
| 5140 | Security | 访问网络共享 |
| 5145 | Security | 网络共享对象访问检查 |
| 7045 | System | 安装了新服务 |
| 1 | Sysmon | 进程创建 |
| 3 | Sysmon | 网络连接 |
六、认证协议指标与 Splunk 数据模型
不同横向移动方式使用不同的认证协议,standards.md 总结了协议级检测要点:
| 协议 | 横向移动类型 | 事件特征 |
|---|---|---|
| NTLM | Pass-the-Hash | Event 4776、NtLmSsp 包 |
| Kerberos | Pass-the-Ticket | Event 4768/4769、票据异常 |
| CredSSP | RDP | Event 4624 Type 10 |
| WSMan | WinRM | Event 4624 Type 3、WSMan 来源 |
在 Splunk 中建议使用以下数据模型(Data Model)加速检索与加速(Acceleration):
Authentication:登录事件;Network_Traffic:连接数据;Endpoint.Processes:进程创建事件;Change.Endpoint_Changes:服务安装。
七、splunklib Python SDK 集成
api-reference.md 提供了通过 Python 直接向 Splunk 提交搜索作业的示例。使用splunklib(Splunk 官方 Python SDK)时,通过service.jobs.create()创建异步搜索作业,再用JSONResultsReader流式读取结果:
import splunklib.client as client import splunklib.results as results service = client.connect(host="splunk", port=8089, token="...") job = service.jobs.create("search index=wineventlog EventCode=4624") for result in results.JSONResultsReader(job.results(output_mode="json")): print(result)这段代码的典型落地场景是:配合下文介绍的agent.py生成查询 → 提交给 Splunk → 将返回的 JSON/CSV 结果交给解析器自动提取横向移动发现(findings)。
八、CLI 用法:脚本化 SPL 生成与结果解析
api-reference.md 定义了三个核心 CLI 用法:
python agent.py --generate-queries python agent.py --generate-queries --techniques pass_the_hash psexec_execution python agent.py --parse-results splunk_output.json这三个命令对应 agent.py 中main()的实现逻辑:
--generate-queries:从内置技术注册表LATERAL_MOVEMENT_QUERIES(共 8 项技术)生成带 MITRE 映射与严重级别的 SPL 查询;--techniques:按技术名过滤,可选值包括pass_the_hash、psexec_execution、wmi_remote_execution、rdp_pivoting、smb_lateral、winrm_execution、service_creation、scheduled_task_remote;--parse-results:解析 Splunk 导出的 JSON/CSV 结果,当去重目标主机数target_count >= 3时生成发现,>= 10则标记为CRITICAL,否则为HIGH。
agent.py中几个查询的技术细节值得注意(对应源码 agent.py):
- pass_the_hash(T1550.002,CRITICAL):
Logon_Type=3+Authentication_Package="NTLM"+Logon_Process="NtLmSsp",并排除127.0.0.1、::1、-等非远端来源; - psexec_execution(T1569.002,HIGH):同时覆盖
services.exe -> PSEXESVC.exe的服务路径与psexec.exe/psexec64.exe客户端路径; - wmi_remote_execution(T1047,HIGH):匹配
svchost.exe -> wmiprvse.exe且CommandLine非空; - rdp_pivoting(T1021.001,MEDIUM):按源 IP 聚合 Type 10 登录目标数,
> 3告警; - smb_lateral(T1021.002,HIGH):直接对网络日志
dest_port=445按src_ip聚合去重目标数,> 5告警; - service_creation(T1543.003,HIGH):针对 7045 事件中
Service_File_Name命中cmd|powershell|\\|%COMSPEC%的情况。
九、离线狩猎:process.py 的多检测器实现
除了在线查询 Splunk,仓库还提供离线分析脚本 process.py,可直接解析导出的 JSON/CSV 认证日志并运行多检测器:
python process.py hunt --input events.json --output ./latmov_output python process.py queriesprocess.py的实现与 SPL 查询形成一一对照(源码 process.py):
detect_network_logon:检测 4624 + Type 3/10 网络登录,过滤系统账户(SYSTEM、ANONYMOUS LOGON、$结尾账户)与本地来源 IP,命中 NTLM 包时风险分 +10 并标注“potential Pass-the-Hash”;detect_explicit_creds:检测 4648 显式凭据登录,固定风险分 35,标记“possible PsExec/RunAs”;detect_share_access:检测 5140 管理共享访问(admin$、c$风险分 40,ipc$、d$、e$风险分 25);detect_service_lateral:对 7045/4697 服务安装事件做正则匹配(psexec、PSEXESVC、csexec、remcom、cmd.exe /c、powershell -enc),命中即风险分 60;analyze_velocity:滑动窗口速度分析,账户在短时间内访问 ≥5 台主机即产生CRITICAL级别的VELOCITY_ANOMALY;build_movement_graph:基于发现构建源 -> 目标移动图,供报告输出横向移动路径。
检测结果统一按风险分映射等级:>=70CRITICAL、>=50HIGH、>=30MEDIUM、其余 LOW。hunt命令会在输出目录生成两份产物:lateral_movement_findings.json(结构化发现、统计与移动图)和hunt_report.md(人类可读的 Markdown 报告)。
十、狩猎输出格式与报告模板
无论走 SPL 在线狩猎还是脚本离线狩猎,SKILL.md 规定了统一的发现输出格式:
Hunt ID: TH-LATMOV-[DATE]-[SEQ] Movement Type: [RDP/SMB/WinRM/WMI/DCOM/PsExec] Source Host: [Hostname/IP] Destination Host: [Hostname/IP] Account Used: [Username] Logon Type: [3/10/other] First Seen: [Timestamp] Event Count: [Number of events] Risk Level: [Critical/High/Medium/Low] Lateral Movement Path: [A -> B -> C -> D]仓库还提供了可复用的书面狩猎模板 template.md,包含狩猎元数据(Hunt ID、分析员、日期、状态)、假设陈述、待调查技术清单、路径图、发现表格、受影响账户与建议(遏制、凭据重置、检测规则)。一个典型假设示例如下:
"Adversaries are moving laterally via SMB admin shares using compromised domain admin credentials."
路径图则以文本形式可视化移动链,例如:
[Source A] --RDP--> [Host B] --SMB--> [Host C] --WMI--> [Host D] | | +--PsExec--> [Host E] +--WinRM--> [Server F]十一、完整狩猎流程(Workflow)回顾
综合 SKILL.md 与 workflows.md,一次完整的横向移动狩猎按以下七步推进:
- 界定横向移动范围:明确要狩猎的技术(RDP、SMB/Admin Shares、WinRM、PsExec、WMI、DCOM、SSH);
- 查询认证事件:用 SPL 搜索全网 Type 3(Network)与 Type 10(RemoteInteractive)登录;
- 构建认证图:映射源-目标认证关系,识别异常连接模式;
- 检测首次出现关系:识别历史基线中从未出现的新源-目标对;
- 关联进程活动:将认证事件与目标主机上随后的进程创建相关联;
- 识别异常模式:标记针对敏感服务器、非常规时间、服务账户滥用或快速多主机访问;
- 报告与遏制:记录移动路径与受影响系统,协调遏制响应。
工具链方面,SKILL.md 推荐以 Splunk Enterprise(配合 Splunk Enterprise Security 生成 notable events)为核心,Windows Event Forwarding 集中 Windows 日志,Sysmon 提供细粒度进程/网络遥测,并可结合 BloodHound 做 AD 攻击路径分析、PingCastle 做 AD 安全评估来交叉验证发现。
结语
横向移动是攻击链中最具可检测性的阶段之一:它必然产生认证、进程或网络痕迹。本技能将 MITRE ATT&CK 技术映射、Windows 事件语义、Splunk SPL 查询与 Python 脚本化分析串联为一条完整链路,既可在线执行 SPL 狩猎,也可离线批量分析导出的日志。所有查询与脚本均可在获取相应日志数据后直接复现;需要深入研究的读者可继续阅读仓库内的 SKILL.md、workflows.md 与 agent.py 源码,并结合自身环境的日志字段与数据模型做适配。
【免费下载链接】Anthropic-Cybersecurity-Skills817 structured cybersecurity skills for AI agents · Mapped to 6 frameworks: MITRE ATT&CK, NIST CSF 2.0, MITRE ATLAS, D3FEND, NIST AI RMF & MITRE F3 (Fight Fraud) · agentskills.io standard · Works with Claude Code, GitHub Copilot, Codex CLI, Cursor, Gemini CLI & 20+ platforms · 29 security domains · Apache 2.0项目地址: https://gitcode.com/GitHub_Trending/an/Anthropic-Cybersecurity-Skills
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考