使用 Splunk 与 SPL 分析 Windows 事件日志:从暴力破解检测到取证时间线构建
2026/9/10 6:03:44 网站建设 项目流程

使用 Splunk 与 SPL 分析 Windows 事件日志:从暴力破解检测到取证时间线构建

【免费下载链接】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

导读

本文是一份面向 SOC 分析师、检测工程师与事件响应人员的实战指南,核心主题是基于 Splunk SPL 查询分析 Windows Security、System 与 Sysmon 事件日志,覆盖认证攻击检测、权限提升、持久化机制、横向移动四大 ATT&CK 战术域,并最终沉淀为可复用的取证时间线与参考查表。该能力在 Anthropic-Cybersecurity-Skills 仓库中由 skills/analyzing-windows-event-logs-in-splunk/SKILL.md 完整承载,配套提供 Python 自动化检测 Agent 与 API 参考文档。读完本文,你将掌握 15+ 条可复制可运行的 SPL 检测查询、Windows/Sysmon 关键事件 ID 的语义,以及将检测结果映射到 MITRE ATT&CK 技术编号的完整方法。

使用场景与适用边界

该技能面向以下典型场景:

  • SOC 分析师调查告警:与 Windows 认证、进程执行或 Active Directory 变更相关的告警需要深入取证时;
  • 检测工程师编写检测规则:基于 Windows 事件日志构建 SPL 检测查询,落地威胁检测用例;
  • 事件响应人员构建取证时间线:还原 Windows 终端或域控制器上攻击者完整的活动路径;
  • 周期性威胁狩猎:针对 Windows 特有的 ATT&CK 技术进行定向狩猎。

明确不适用的边界:本技能不适用于 Linux/macOS 终端分析,也不适用于纯网络侧(无主机事件)的取证调查。

前置条件与数据接入

在运行任何检测查询之前,需要确认以下数据链路已经打通:

前置条件说明
Splunk 已接入 Windows 事件日志sourcetype 至少包含WinEventLog:SecurityWinEventLog:System,Sysmon 日志使用XmlWinEventLog:Microsoft-Windows-Sysmon/Operational
Sysmon 已部署到终端建议使用 SwiftOnSecurity 或 Olaf Hartong 的公开配置,以获取进程、网络与文件活动的高保真日志
Splunk CIM 数据模型加速建议启用 Endpoint 与 Authentication 两个数据模型的加速,便于跨数据源归一化查询
基础知识熟悉 Windows Security Event ID 与 Sysmon 事件类型的语义(可参考下文关键概念表)

从部署架构看,Windows 事件通常通过 Windows Event Forwarding (WEF) 集中到收集服务器后再进入 Splunk;Sysmon 提供比原生安全日志更细粒度的进程、网络与文件活动记录,二者互补构成了"安全日志 + 行为日志"的双通道数据源,这正是后续检测查询得以交叉验证的基础。

六步检测工作流

整个分析流程分为六个步骤:认证攻击检测 → 权限提升检测 → 持久化检测 → 横向移动检测 → 取证时间线构建 → 参考查表建设。每一步都对应明确的 ATT&CK 技术编号,可直接落地为检测用例。

Step 1:认证攻击检测(T1110)

暴力破解检测(EventCode 4625 — 登录失败):该查询以src_ipLogon_TypeStatus三个维度聚合失败登录事件,通过Logon_Type判别攻击面(网络、RDP 或本机交互),并通过Status状态码解释失败原因:

index=wineventlog sourcetype="WinEventLog:Security" EventCode=4625 | stats count, dc(TargetUserName) AS unique_users, values(TargetUserName) AS targeted_users by src_ip, Logon_Type, Status | where count > 20 | eval attack_type = case( Logon_Type=3, "Network Brute Force", Logon_Type=10, "RDP Brute Force", Logon_Type=2, "Interactive Brute Force", 1=1, "Other" ) | eval status_meaning = case( Status="0xc000006d", "Bad Username or Password", Status="0xc000006a", "Incorrect Password (valid user)", Status="0xc0000234", "Account Locked Out", Status="0xc0000072", "Account Disabled", 1=1, Status ) | sort - count | table src_ip, attack_type, status_meaning, count, unique_users, targeted_users

密码喷洒检测:密码喷洒的典型特征是单源 IP 在短时间内对大量账户各尝试少量密码,因此判断条件是"唯一用户数多、但总尝试次数不显著高于用户数":

index=wineventlog sourcetype="WinEventLog:Security" EventCode=4625 Logon_Type=3 | bin _time span=10m | stats dc(TargetUserName) AS unique_users, count AS total_attempts, values(TargetUserName) AS users_targeted by src_ip, _time | where unique_users > 10 AND total_attempts < unique_users * 3 | eval spray_confidence = if(unique_users > 25, "HIGH", "MEDIUM")

失败后成功的登录(账户失陷指标):攻击者暴力破解成功后必然伴随一次成功登录(4624),该查询以"失败次数 > 10 且存在成功"为判据,并计算从首次失败到成功的时间差time_to_success,时间越短说明口令猜测越高效、失陷风险越高:

index=wineventlog sourcetype="WinEventLog:Security" (EventCode=4625 OR EventCode=4624) src_ip!="127.0.0.1" | sort _time | stats earliest(_time) AS first_seen, latest(_time) AS last_seen, sum(eval(if(EventCode=4625,1,0))) AS failures, sum(eval(if(EventCode=4624,1,0))) AS successes by src_ip, TargetUserName, ComputerName | where failures > 10 AND successes > 0 | eval time_to_success = round((last_seen - first_seen)/60, 1) | sort - failures

Step 2:权限提升检测

新建管理员账户(T1136.001):通过 4720(账户创建)左连接 4732(加入 Administrators 组)两个事件,直接定位"创建即提权"的可疑账户:

index=wineventlog sourcetype="WinEventLog:Security" EventCode=4720 | join TargetUserName type=left [ search index=wineventlog EventCode=4732 TargetUserName="Administrators" | rename MemberName AS TargetUserName ] | table _time, SubjectUserName, TargetUserName, ComputerName | eval alert = "New account created and added to Administrators group"

特殊权限分配(EventCode 4672):先剔除 SYSTEM、LOCAL SERVICE、NETWORK SERVICE 等合法服务账户,再聚焦SeDebugPrivilegeSeTcbPrivilegeSeBackupPrivilegeSeRestorePrivilegeSeAssignPrimaryTokenPrivilege这五类高风险特权——这些特权常被攻击者用于注入、令牌模拟或备份密钥窃取:

index=wineventlog sourcetype="WinEventLog:Security" EventCode=4672 SubjectUserName!="SYSTEM" SubjectUserName!="LOCAL SERVICE" SubjectUserName!="NETWORK SERVICE" | stats count, values(PrivilegeList) AS privileges by SubjectUserName, ComputerName | where count > 0 | search privileges IN ("SeDebugPrivilege", "SeTcbPrivilege", "SeBackupPrivilege", "SeRestorePrivilege", "SeAssignPrimaryTokenPrivilege")

令牌操纵检测(T1134):借助 Sysmon EventCode 10(进程访问)监控对lsass.exe的可疑句柄请求。GrantedAccess中的0x1010(读取)、0x1038(读取+查询)、0x1fffff(完全控制)、0x40(进程查询)均与 Mimikatz 等凭据窃取工具的典型请求模式相符,同时排除系统合法进程以降低误报:

index=sysmon EventCode=10 TargetImage="*\\lsass.exe" GrantedAccess IN ("0x1010", "0x1038", "0x1fffff", "0x40") | stats count by SourceImage, SourceUser, Computer, GrantedAccess | where NOT match(SourceImage, "(svchost|csrss|wininit|MsMpEng|CrowdStrike)") | sort - count

Step 3:持久化机制检测

计划任务创建(T1053.005):同时覆盖两条数据链路——Security 日志的 4698(计划任务创建)与 Sysmon 的进程创建事件(检测schtasks.exe执行),并用coalesce合并字段后过滤包含 PowerShell、cmd、HTTP 或 Temp 目录特征的任务内容:

index=wineventlog (sourcetype="WinEventLog:Security" EventCode=4698) OR (sourcetype="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" EventCode=1 Image="*\\schtasks.exe") | eval task_info = coalesce(TaskContent, CommandLine) | search task_info="*powershell*" OR task_info="*cmd*" OR task_info="*http*" OR task_info="*\\Temp\\*" | table _time, Computer, SubjectUserName, TaskName, task_info

注册表 Run 键修改(T1547.001):监控 Sysmon EventCode 13(注册表值设置),覆盖RunRunOnceRunServicesExplorer\Shell Folders四类自启动位置,并排除 explorer、msiexec、setup 等合法写入方:

index=sysmon EventCode=13 TargetObject IN ( "*\\CurrentVersion\\Run\\*", "*\\CurrentVersion\\RunOnce\\*", "*\\CurrentVersion\\RunServices\\*", "*\\Explorer\\Shell Folders\\*" ) | stats count by Computer, Image, TargetObject, Details | where NOT match(Image, "(explorer\.exe|msiexec\.exe|setup\.exe)") | sort - count

WMI 事件订阅(T1546.003):WMI 持久化是典型的无文件攻击手段,Sysmon EventCode 20(WMI 事件活动)与 21(WMI 过滤器绑定)直接暴露攻击者注册的恶意消费者与命名空间:

index=sysmon EventCode=20 OR EventCode=21 | stats count by Computer, Operation, Consumer, EventNamespace | where count > 0

Step 4:横向移动检测

远程服务利用(T1021.002 — SMB/Windows 管理共享):以"单一来源账户登录目标主机数超过 3 台"为异常基线,识别 SMB 共享驱动的批量横向移动:

index=wineventlog sourcetype="WinEventLog:Security" EventCode=4624 Logon_Type=3 | stats dc(ComputerName) AS unique_destinations, values(ComputerName) AS targets by src_ip, TargetUserName | where unique_destinations > 3 | sort - unique_destinations | table src_ip, TargetUserName, unique_destinations, targets

PsExec 检测(T1021.002):PsExec 家族的指纹特征集中在进程名(psexec.exe)、服务端(psexesvc.exe)与编译原始文件名(psexec.c)三处,任一路径命中即可告警:

index=sysmon EventCode=1 (Image="*\\psexec.exe" OR Image="*\\psexesvc.exe" OR ParentImage="*\\psexesvc.exe" OR OriginalFileName="psexec.c") | table _time, Computer, User, ParentImage, Image, CommandLine

RDP 横向移动(T1021.001):通过 Logon_Type=10(远程交互登录)聚合 RDP 登录目标数,单账户访问超过 2 台主机即触发:

index=wineventlog sourcetype="WinEventLog:Security" EventCode=4624 Logon_Type=10 | stats count, dc(ComputerName) AS rdp_targets, values(ComputerName) AS destinations by src_ip, TargetUserName | where rdp_targets > 2 | sort - rdp_targets

Step 5:构建取证时间线

针对被入侵主机(示例为WORKSTATION-042),跨 Security 与 Sysmon 两个索引构建统一事件视图,将原始事件编号翻译为人类可读的描述(登录、进程、网络、文件、注册表等),按时间排序后即为完整的攻击活动时间线:

(index=wineventlog OR index=sysmon) Computer="WORKSTATION-042" earliest="2024-03-14T00:00:00" latest="2024-03-16T00:00:00" | eval event_description = case( EventCode=4624, "Logon: ".TargetUserName." (Type ".Logon_Type.")", EventCode=4625, "Failed Logon: ".TargetUserName, EventCode=4688 OR (sourcetype="XmlWinEventLog:*Sysmon*" AND EventCode=1), "Process: ".Image." CMD: ".CommandLine, EventCode=4698, "Scheduled Task: ".TaskName, EventCode=3, "Network: ".DestinationIp.":".DestinationPort, EventCode=11, "File Created: ".TargetFilename, EventCode=13, "Registry: ".TargetObject, 1=1, "Event ".EventCode ) | sort _time | table _time, EventCode, event_description, User, src_ip

Step 6:创建参考查表用于富化

为每个事件 ID 建立"描述 + ATT&CK 技术 + 严重级别"的上下文映射,供检测结果即时富化:

| inputlookup windows_eventcode_lookup.csv | table EventCode, Description, ATT_CK_Technique, Severity

若查表不存在,可按以下格式创建windows_eventcode_lookup.csv

EventCode,Description,ATT_CK_Technique,Severity 4624,Successful Logon,T1078,Informational 4625,Failed Logon,T1110,Low 4648,Explicit Credential Logon,T1078,Medium 4672,Special Privileges Assigned,T1134,Medium 4688,New Process Created,T1059,Informational 4698,Scheduled Task Created,T1053.005,Medium 4720,User Account Created,T1136.001,High 4732,Member Added to Security Group,T1098,High 4768,Kerberos TGT Requested,T1558,Informational 4769,Kerberos Service Ticket,T1558.003,Low 4771,Kerberos Pre-Auth Failed,T1110,Low

关键概念速查

术语定义
EventCode 4624成功登录事件 —— Logon_Type 2(交互)、3(网络)、10(RDP)、7(解锁)
EventCode 4625失败登录事件 —— Status 状态码指示失败原因(密码错误、账户锁定、账户禁用)
Sysmon EventCode 1进程创建事件,包含完整命令行、父进程与哈希信息
Sysmon EventCode 3进程发起的网络连接事件 —— 源/目标 IP、端口与进程上下文
Logon Type 3网络登录(SMB、WMI、PowerShell Remoting)—— 横向移动的关键指标
Logon Type 10通过 RDP/终端服务的远程交互登录

登录类型全景(来自 API 参考文档):

Type描述上下文
2Interactive本地控制台登录
3NetworkSMB、WMI、PowerShell Remoting
7Unlock工作站解锁
9NewCredentialsrunas /netonly
10RemoteInteractiveRDP 登录

Sysmon 关键事件 ID:1(进程创建)、3(网络连接)、7(镜像加载/DLL)、10(进程访问——LSASS 凭据窃取)、11(文件创建)、13(注册表值设置)、22(DNS 查询)。

常见攻击场景的检测要点

  • Kerberoasting(T1558.003):检测 EventCode 4769 中加密类型为 0x17(RC4)且服务名非krbtgt的票据请求——这通常意味着攻击者在离线破解服务账户哈希;
  • DCSync(T1003.006):检测 EventCode 4662 中对象类型为domainDNS且属性包含Replicating Directory Changes的非域控来源——这是目录复制权限被滥用的直接证据;
  • 黄金票据(T1558.001):检测 EventCode 4769 中票据属性异常(过长的票据寿命、非标准加密类型);
  • Pass-the-Hash(T1550.002):检测 EventCode 4624 中来自异常来源、使用 NTLM 认证的 Logon_Type 3 网络登录;
  • DLL 侧加载(T1574.002):Sysmon EventCode 7 显示合法进程加载了未签名 DLL。

从人工查询到自动化 Agent:源码级实现

仓库为上述手工 SPL 查询提供了完整的 Python 自动化实现,见 scripts/agent.py。其设计结构为"连接 → 检测函数 → 全量狩猎",每个检测函数与本文的 SPL 查询一一对应:

连接与搜索基座:基于splunklib.client建立连接(支持环境变量SPLUNK_HOSTSPLUNK_PORTSPLUNK_USERNAMESPLUNK_PASSWORD注入),并通过exec_mode="blocking"提交阻塞式搜索任务,以 JSON 格式读取结果:

import splunklib.client as client import splunklib.results as results def connect(host, port, username, password): return client.connect( host=host, port=port, username=username, password=password, autologin=True ) def search(service, query, earliest="-24h", latest="now"): job = service.jobs.create( f"search {query}", **{"earliest_time": earliest, "latest_time": latest, "exec_mode": "blocking"} ) reader = results.JSONResultsReader(job.results(output_mode="json")) rows = [r for r in reader if isinstance(r, dict)] job.cancel() return rows

检测函数与 SPL 的对应关系

Agent 函数对应检测能力默认时间窗阈值参数
detect_brute_force暴力破解(4625 按登录类型分类)-24hthreshold=20
detect_password_spray密码喷洒(10 分钟桶)-24hunique_users > 10
detect_new_admin_accounts新建管理员账户(T1136.001)-7d
detect_lsass_accessLSASS 凭据窃取(T1003.001)-24hGrantedAccess 白名单
detect_lateral_movement_smbSMB 横向移动(T1021.002)-24h目标主机> 3
detect_psexecPsExec 执行(T1021.002)-24h
build_forensic_timeline主机取证时间线--hostname指定

命令行用法:通过--action参数选择单项检测或full_hunt全量狩猎,--hostname指定取证时间线的目标主机:

# 全量狩猎(默认动作) python3 scripts/agent.py --host splunk --port 8089 --username admin --password "$SPLUNK_PASSWORD" --action full_hunt # 仅检测暴力破解,自定义阈值 python3 scripts/agent.py --action brute_force --earliest "-48h" # 构建指定主机的取证时间线 python3 scripts/agent.py --action timeline --hostname "WORKSTATION-042" --earliest "-7d"

执行结果以 JSON 输出,包含generated_at时间戳与按检测类型分组的 findings 结构,便于下游 SOAR 或工单系统消费。

框架映射:ATT&CK、NIST CSF 与 D3FEND

该技能在仓库中被系统化地映射到多个安全框架(见 SKILL.md 的 YAML frontmatter),这使其既可作为检测用例库,也可作为合规覆盖证据:

  • MITRE ATT&CK:T1110(暴力破解)、T1053.005(计划任务)、T1547.001(注册表 Run 键)、T1021.002(SMB/Windows 管理共享)、T1558.003(Kerberoasting)、T1003.006(DCSync)等;
  • NIST CSF 2.0:DE.CM-01(持续监控)、DE.AE-02(异常事件分析)、DE.AE-06(关联信息形成分析结论)、RS.MA-01(指示器分析);
  • D3FEND:Restore Access、Password Authentication、Strong Password Policy、Restore User Account Access 等防御计数。

仓库级覆盖证据可在 ATTACK_COVERAGE.md 中交叉验证:本技能在 T1078、T1110、T1136.001、T1546.003、T1547.001、T1558.003、T1021.002 等多个技术上被列为覆盖技能之一,且与building-detection-rule-with-splunk-spldetecting-lateral-movement-with-splunkdetecting-dcsync-attack-in-active-directory等相邻技能构成互补的检测能力簇(详见 mappings/mitre-attack/README.md 的技术映射方法论与 mappings/attack-navigator-layer.json 的覆盖可视化层)。

输出格式与报告模板

分析完成后,建议按以下结构化模板输出结论,将统计数字、可疑发现与 ATT&CK 映射整合为可直接进入工单或复盘报告的结果:

WINDOWS EVENT LOG ANALYSIS — HOST: WORKSTATION-042 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Period: 2024-03-14 to 2024-03-15 Events: 12,847 total (Security: 9,231 | Sysmon: 3,616) Authentication Summary: Successful Logons (4624): 487 (Type 3: 312, Type 10: 45, Type 2: 130) Failed Logons (4625): 847 (from 192.168.1.105 — BRUTE FORCE) Explicit Creds (4648): 12 Suspicious Findings: [HIGH] 847 failed logons followed by success at 14:35 from 192.168.1.105 [HIGH] New user "backdoor_admin" created (4720) at 14:38 [HIGH] User added to Administrators group (4732) at 14:38 [MEDIUM] schtasks.exe creating persistence task at 14:42 [MEDIUM] PowerShell encoded command execution at 14:45 ATT&CK Mapping: T1110.001 — Password Guessing (847 failed logons) T1136.001 — Local Account Creation (backdoor_admin) T1053.005 — Scheduled Task (persistence) T1059.001 — PowerShell (encoded execution)

小结

本文以 SKILL.md 为骨架,完整覆盖了 Windows 事件日志分析的六步实战工作流:从 4624/4625 认证事件识别暴力破解与密码喷洒,经 4672/4720/4698/1547 等事件定位提权与持久化,再以 Logon_Type 3/10 与 Sysmon 事件 1/10 追踪横向移动,最后通过跨索引时间线与事件 ID 查表完成取证闭环。配合仓库中的 自动化 Agent 脚本,SOC 团队可以将这些检测逻辑从手工查询升级为可定时执行的批量狩猎任务;借助 ATT&CK 覆盖 与 NIST CSF 对齐,这些检测用例同时具备威胁知情的防御价值与合规审计价值。

【免费下载链接】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),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询