mcpField
H
hunting-for-persistence-via-wmi-subscriptions

hunting-for-persistence-via-wmi-subscriptions

github.com/mukul975安全35.2k45 次安装8 周前更新
代码仓库

关于 hunting-for-persistence-via-wmi-subscriptions

面向 Windows 事件响应人员的 WMI 持久化狩猎技能,利用 Sysmon、Windows 事件和 PowerShell 日志检查订阅创建、触发条件及其执行行为。

主要功能

  1. 01枚举永久 WMI 事件订阅
  2. 02监测 Sysmon 事件 19、20、21
  3. 03检查消费者类型与触发条件
  4. 04调查 WmiPrvSe.exe 子进程
  5. 05关联 mofcomp.exe 与订阅创建

适用场景

  1. 01排查重启后仍存在的恶意持久化
  2. 02调查 WmiPrvSe.exe 启动的异常进程
  3. 03检查标准持久化位置之外的可疑活动

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill hunting-for-persistence-via-wmi-subscriptions

安装后在 Claude Code 中输入/hunting-for-persistence-via-wmi-subscriptions确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
assets/
template.md
references/
api-reference.md
standards.md
workflows.md
scripts/
agent.py
process.py

详细介绍

通过 WMI 订阅狩猎持久化

何时使用

  • 在 Windows 环境中主动搜索无文件持久化机制时
  • 当威胁情报报告指出 APT 组织(APT29、APT32、FIN8)使用基于 WMI 的持久化时
  • 在调查那些尽管尝试清理但恶意软件仍能跨重启存活的系统时
  • 在事件响应期间,当标准持久化位置(Run 键、计划任务)干净时
  • 当观察到 WmiPrvSe.exe 生成意外子进程时

前置条件

  • 启用 Sysmon 事件 ID 19、20、21(WMI 事件筛选器/消费者/绑定)
  • 来自 Microsoft-Windows-WMI-Activity 的 Windows 事件 ID 5861(WMI 活动日志记录)
  • 启用 PowerShell 日志记录(脚本块日志记录、模块日志记录)
  • 具备用于枚举的 WMI 存储库访问权限
  • 用于事件关联的 SIEM 平台

工作流

  1. 枚举现有 WMI 订阅:查询目标系统上所有永久 WMI 事件订阅。干净的系统通常只有极少数或零个永久订阅,因此异常很容易被发现。
  2. 监控 WMI 事件创建(Sysmon 19/20/21):Sysmon 事件 19 捕获 WmiEventFilter 活动,事件 20 捕获 WmiEventConsumer 活动,事件 21 捕获 WmiEventConsumerToFilter 绑定。
  3. 分析消费者类型:重点关注 ActiveScriptEventConsumer(运行 VBScript/JScript)和 CommandLineEventConsumer(执行命令)——这些是用于持久化的危险类型。
  4. 检查事件筛选器触发器:检查是什么触发了订阅。常见的恶意触发器包括系统启动(Win32_ProcessStartTrace)、用户登录或基于计时器的执行间隔。
  5. 调查 WmiPrvSe.exe 子进程:当 WMI 订阅触发时,操作由 WmiPrvSe.exe 执行。狩猎 WmiPrvSe.exe 的不寻常子进程。
  6. 与 MOF 编译关联:检测 mofcomp.exe 的使用,它通过编程方式编译 MOF 文件以创建 WMI 订阅。
  7. 验证与响应:确认恶意订阅,将其移除,并追溯至初始感染途径。

关键概念

概念描述
T1546.003事件触发执行:WMI 事件订阅
__EventFilter定义触发条件的 WMI 类
__EventConsumer定义要执行的操作的 WMI 类
__FilterToConsumerBinding将筛选器链接到消费者
ActiveScriptEventConsumer运行 VBScript 或 JScript 的消费者
CommandLineEventConsumer执行命令行的消费者
WmiPrvSe.exe执行订阅操作的 WMI Provider Host
MOF 文件用于定义 WMI 对象的托管对象格式

检测查询

Splunk -- 通过 Sysmon 检测 WMI 订阅创建
index=sysmon (EventCode=19 OR EventCode=20 OR EventCode=21)
| eval event_type=case(EventCode=19, "EventFilter", EventCode=20, "EventConsumer", EventCode=21, "FilterToConsumerBinding")
| table _time Computer User event_type EventNamespace Name Query Destination Operation
Splunk -- 通过 Windows 事件 5861 检测 WMI 订阅
index=wineventlog source="Microsoft-Windows-WMI-Activity/Operational" EventCode=5861
| table _time Computer NamespaceName Operation PossibleCause
PowerShell -- 枚举 WMI 订阅
Get-WmiObject -Namespace root\subscription -Class __EventFilter
Get-WmiObject -Namespace root\subscription -Class __EventConsumer
Get-WmiObject -Namespace root\subscription -Class __FilterToConsumerBinding
KQL -- WmiPrvSe.exe 生成可疑子进程
DeviceProcessEvents
| where Timestamp > ago(7d)
| where InitiatingProcessFileName =~ "wmiprvse.exe"
| where FileName in~ ("cmd.exe", "powershell.exe", "wscript.exe", "cscript.exe", "mshta.exe", "rundll32.exe")
| project Timestamp, DeviceName, FileName, ProcessCommandLine
Sigma 规则
title: WMI Event Subscription Persistence
status: stable
logsource:
    product: windows
    category: wmi_event
detection:
    selection_consumer:
        EventID: 20
        Destination|contains:
            - 'ActiveScriptEventConsumer'
            - 'CommandLineEventConsumer'
    condition: selection_consumer
level: high
tags:
    - attack.persistence
    - attack.t1546.003

常见场景

  1. APT29 WMI 持久化:创建一个 ActiveScriptEventConsumer,在系统启动时执行 VBScript 后门,可在重启和凭据重置后存活。
  2. Turla WMI 后门:使用 Win32_ProcessStartTrace 筛选器结合 CommandLineEventConsumer 进行隐蔽命令执行。
  3. FIN8 WMI 计时器:基于间隔的 __IntervalTimerEvent 每 30 分钟触发编码 PowerShell 下载。
  4. 基于 MOF 的安装:攻击者投放一个 .mof 文件并用 mofcomp.exe 编译它,以静默创建持久化订阅。

输出格式

Hunt ID: TH-WMI-[DATE]-[SEQ]
Host: [Hostname]
Subscription Name: [Filter/Consumer name]
Filter Query: [WQL trigger condition]
Consumer Type: [ActiveScript/CommandLine]
Consumer Action: [Script content or command]
Binding: [Filter-to-Consumer link]
Created: [Timestamp]
User Context: [SYSTEM/User]
Risk Level: [Critical/High/Medium/Low]

评论

支持 Markdown