实战指南:SPL 查询、事件源映射与脚本化狩猎参考)
基于 Splunk 检测横向移动Lateral Movement实战指南SPL 查询、事件源映射与脚本化狩猎参考【免费下载链接】Anthropic-Cybersecurity-Skills817 structured cybersecurity skills for AI agents · Mapped to 6 frameworks: MITRE ATTCK, 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 ATTCK TA0008Lateral 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-HashT1550.002Event 4624 Logon_Type3 NTLMPSExecT1569.002Sysmon Event 1 (PSEXESVC.exe)WMI Remote ExecT1047Sysmon Event 1 (wmiprvse.exe)RDP PivotingT1021.001Event 4624 Logon_Type10SMB/Admin ShareT1021.002Network logs dest_port445WinRMT1021.006Sysmon Event 1 (wsmprovhost.exe)在 standards.md 中这一矩阵被进一步扩展为更完整的 ATTCK 战术覆盖技术名称事件特征T1021.001Remote Desktop ProtocolLogon Type 10、RDP 证书事件T1021.002SMB/Windows Admin SharesLogon Type 3、ADMIN$/C$/IPC$ 访问T1021.003Distributed COMLogon Type 3、DCOM 进程创建T1021.004SSHOpenSSH 认证事件T1021.006Windows Remote ManagementWinRM/WSMan 登录事件T1047Windows Management InstrumentationWMI 远程进程创建T1569.002Service ExecutionPsExec 服务安装 Type 3 登录T1570Lateral Tool Transfer通过 SMB/RDP 复制文件T1550.002Pass the HashType 3 登录 NTLM 认证T1550.003Pass 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该技能适用于以下场景在多个受控系统之间狩猎攻击者移动行为检测到凭据窃取后追踪随后的横向活动调查全网范围内不寻常的认证模式在事件响应期间界定入侵的波及范围主动狩猎 TA0008Lateral 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 indexwineventlog EventCode4624 Logon_Type3 | where Authentication_PackageNTLM | stats dc(Computer) as targets by Source_Network_Address | where targets 3 # PSExec detection indexsysmon EventCode1 | 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、WinRMindexwineventlog EventCode4624 Logon_Type3 | 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 登录indexwineventlog EventCode4624 Logon_Type10 | 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、RunAsindexwineventlog EventCode4648 | 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$ 共享访问indexwineventlog EventCode5140 | 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 文件操作indexwineventlog EventCode5145 | 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 服务安装indexwineventlog EventCode7045 | 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追溯横向移动来源indexwineventlog EventCode7045 | eval is_suspiciousif(match(Service_File_Name, (?i)(temp|appdata|cmd|powershell)), 1, 0) | where is_suspicious1 | join Computer [ search indexwineventlog EventCode4624 Logon_Type3 | rename Computer as Computer, Source_Network_Address as lateral_src ] | table _time Computer Service_Name Service_File_Name lateral_src3.4 Phase 4WMI 与 DCOM 横向移动Step 4.1 - 远程 WMI 执行indexsysmon EventCode1 | 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 宿主进程派生命令行的模式indexsysmon EventCode1 | 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 - 目标主机为边聚合indexwineventlog EventCode4624 Logon_Type IN (3, 10) | where NOT match(Account_Name, (?i)(\\$|SYSTEM|ANONYMOUS)) | eval connectionSource_Network_Address.-.Computer | stats count first(_time) as first_seen last(_time) as last_seen by connection Account_Name | sort -countStep 5.2 - 首次出现的源-目标对用子查询排除过去 30 天的历史基线识别“从未见过”的新关系indexwineventlog EventCode4624 Logon_Type IN (3, 10) earliest-1d | where NOT match(Account_Name, (?i)(\\$|SYSTEM)) | eval pairAccount_Name.:.Source_Network_Address.-.Computer | search NOT [ | search indexwineventlog EventCode4624 Logon_Type IN (3, 10) earliest-30d latest-1d | eval pairAccount_Name.:.Source_Network_Address.-.Computer | dedup pair | fields pair ] | stats count by pair | sort -countStep 6.1 - 速度异常短时间多主机访问indexwineventlog EventCode4624 Logon_Type3 | where NOT match(Account_Name, (?i)(\\$|SYSTEM)) | bin _time span10m | 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 - 非工作时间横向移动indexwineventlog EventCode4624 Logon_Type IN (3, 10) | where NOT match(Account_Name, (?i)(\\$|SYSTEM)) | eval hourstrftime(_time, %H) | where hour 6 OR hour 22 | stats count by Account_Name Source_Network_Address Computer hour | sort -countStep 6.3 - 服务账户横向移动indexwineventlog EventCode4624 Logon_Type10 | 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描述2Interactive控制台3NetworkSMB、PSExec7Unlock10RemoteInteractiveRDPstandards.md 提供了完整版本供日常对照Type名称描述2Interactive本地控制台登录3NetworkSMB、映射驱动器、WinRM4Batch计划任务执行5Service服务启动7Unlock工作站解锁8NetworkCleartextIIS 基本认证9NewCredentialsRunAs /netonly10RemoteInteractiveRDP、终端服务11CachedInteractive缓存域登录横向移动中Type 3Network与 Type 10RemoteInteractive是两条最高频的攻击通道SMB/WinRM/共享映射走 Type 3RDP 走 Type 10。关键 Windows 事件 ID 参考表来自 standards.md事件 ID来源描述4624Security账户登录成功4625Security账户登录失败4648Security使用显式凭据登录4672Security分配特殊权限管理员登录4768Security请求 Kerberos TGT4769Security请求 Kerberos TGS4776SecurityNTLM 凭据验证5140Security访问网络共享5145Security网络共享对象访问检查7045System安装了新服务1Sysmon进程创建3Sysmon网络连接六、认证协议指标与 Splunk 数据模型不同横向移动方式使用不同的认证协议standards.md 总结了协议级检测要点协议横向移动类型事件特征NTLMPass-the-HashEvent 4776、NtLmSsp 包KerberosPass-the-TicketEvent 4768/4769、票据异常CredSSPRDPEvent 4624 Type 10WSManWinRMEvent 4624 Type 3、WSMan 来源在 Splunk 中建议使用以下数据模型Data Model加速检索与加速AccelerationAuthentication登录事件Network_Traffic连接数据Endpoint.Processes进程创建事件Change.Endpoint_Changes服务安装。七、splunklib Python SDK 集成api-reference.md 提供了通过 Python 直接向 Splunk 提交搜索作业的示例。使用splunklibSplunk 官方 Python SDK时通过service.jobs.create()创建异步搜索作业再用JSONResultsReader流式读取结果import splunklib.client as client import splunklib.results as results service client.connect(hostsplunk, port8089, token...) job service.jobs.create(search indexwineventlog EventCode4624) for result in results.JSONResultsReader(job.results(output_modejson)): 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.pypass_the_hashT1550.002CRITICALLogon_Type3Authentication_PackageNTLMLogon_ProcessNtLmSsp并排除127.0.0.1、::1、-等非远端来源psexec_executionT1569.002HIGH同时覆盖services.exe - PSEXESVC.exe的服务路径与psexec.exe/psexec64.exe客户端路径wmi_remote_executionT1047HIGH匹配svchost.exe - wmiprvse.exe且CommandLine非空rdp_pivotingT1021.001MEDIUM按源 IP 聚合 Type 10 登录目标数 3告警smb_lateralT1021.002HIGH直接对网络日志dest_port445按src_ip聚合去重目标数 5告警service_creationT1543.003HIGH针对 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.pydetect_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$风险分 40ipc$、d$、e$风险分 25detect_service_lateral对 7045/4697 服务安装事件做正则匹配psexec、PSEXESVC、csexec、remcom、cmd.exe /c、powershell -enc命中即风险分 60analyze_velocity滑动窗口速度分析账户在短时间内访问 ≥5 台主机即产生CRITICAL级别的VELOCITY_ANOMALYbuild_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 3Network与 Type 10RemoteInteractive登录构建认证图映射源-目标认证关系识别异常连接模式检测首次出现关系识别历史基线中从未出现的新源-目标对关联进程活动将认证事件与目标主机上随后的进程创建相关联识别异常模式标记针对敏感服务器、非常规时间、服务账户滥用或快速多主机访问报告与遏制记录移动路径与受影响系统协调遏制响应。工具链方面SKILL.md 推荐以 Splunk Enterprise配合 Splunk Enterprise Security 生成 notable events为核心Windows Event Forwarding 集中 Windows 日志Sysmon 提供细粒度进程/网络遥测并可结合 BloodHound 做 AD 攻击路径分析、PingCastle 做 AD 安全评估来交叉验证发现。结语横向移动是攻击链中最具可检测性的阶段之一它必然产生认证、进程或网络痕迹。本技能将 MITRE ATTCK 技术映射、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 ATTCK, 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),仅供参考