meltedinhex/analyst-ai-pack / skills/hunting-wmi-event-subscription-persistence
hunting-wmi-event-subscription-persistence
VerifiedHunts for malicious WMI permanent event subscription persistence by correlating __EventFilter, CommandLineEventConsumer/ActiveScriptEventConsumer, and FilterToConsumerBinding records from Sysmon Event IDs 19/20/21 or WMI repository exports. Activates for requests to hunt WMI persistence, detect event consumer backdoors, or analyze WMI subscription telemetry.
| File | Kind | Size |
|---|---|---|
| LICENSE | other | 340 B |
| SKILL.md | skill md | 2.8 KB |
| references/api-reference.md | markdown | 1.1 KB |
| scripts/analyst.py | script | 2.9 KB |
scripts/analyst.py
View on GitHub#!/usr/bin/env python3
"""Correlate WMI permanent event subscription records and flag suspicious consumers.
Parses Sysmon WMI telemetry (Event IDs 19/20/21) from CSV or JSON-lines, groups filters,
consumers, and bindings, and flags consumers whose payload runs scripts or encoded commands.
Parses telemetry only; executes nothing.
"""
from __future__ import annotations
import argparse
import csv
import json
import sys
from pathlib import Path
SUSPICIOUS = ["powershell", "-enc", "wscript", "cscript", "mshta", "cmd.exe /c", "http",
"jscript", "vbscript", "scrobj", "regsvr32", "rundll32"]
def _rows(path: str):
text = Path(path).read_text(encoding="utf-8-sig", errors="replace")
if path.lower().endswith(".json") or text.lstrip()[:1] in "{[":
for line in text.splitlines():
line = line.strip()
if line:
try:
yield json.loads(line)
except json.JSONDecodeError:
continue
else:
for row in csv.DictReader(text.splitlines()):
yield row
def _get(row: dict, *keys: str) -> str:
for k in keys:
if row.get(k):
return str(row[k])
return ""
def hunt(path: str) -> dict:
filters, consumers, bindings = [], [], []
for row in _rows(path):
eid = _get(row, "EventID", "event_id", "Id")
etype = _get(row, "EventType", "Operation").lower()
if eid == "19" or "wmifilter" in etype:
filters.append({"name": _get(row, "Name", "Operation"),
"query": _get(row, "Query", "query")})
elif eid == "20" or "wmiconsumer" in etype:
consumers.append({"name": _get(row, "Name", "Operation"),
"destination": _get(row, "Destination", "CommandLineTemplate",
"ScriptText", "destination")})
elif eid == "21" or "wmibinding" in etype:
bindings.append({"consumer": _get(row, "Consumer", "consumer"),
"filter": _get(row, "Filter", "filter")})
flagged = []
for c in consumers:
dest = c["destination"].lower()
hits = [s for s in SUSPICIOUS if s in dest]
if hits:
flagged.append({"consumer": c["name"], "indicators": hits,
"payload": c["destination"][:200]})
return {
"filters": filters, "consumers": consumers, "bindings": bindings,
"suspicious_consumers": flagged,
"subscription_complete": bool(filters and consumers and bindings),
}
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="Hunt WMI event subscription persistence")
sub = parser.add_subparsers(dest="cmd", required=True)
p = sub.add_parser("hunt")
p.add_argument("events")
args = parser.parse_args(argv)
print(json.dumps(hunt(args.events), indent=2))
return 0
if __name__ == "__main__":
sys.exit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |