Detection engineering

From brucesongs/kali-claw · View interactive version

Detection engineering is an AI agent skill from the GitHub repository brucesongs/kali-claw. Detection-as-code engineering covering Sigma rule authoring, YARA signature development, Splunk SPL / Kusto KQL / Elastic EQL queries, MITRE ATT&CK mapping, detection CI/CD pipelines, false-positive tuning, and rule testing against EVTX-ATTACK-SAMPLES — using SigmaHQ, Yara-Rules, Loki, yarGen, hayab

How to use this skill

Skill file

Skill: Detection Engineering

Supplementary Files:

- payloads.md — Sigma rule anatomy & authoring patterns, SigmaCLI usage, YARA rule anatomy & patterns, yarGen auto-generation, Loki scanning, Splunk SPL / Kusto KQL / Elastic EQL detection libraries, hayabusa & zircollo Sigma-to-EVTX pipelines, MITRE ATT&CK mapping, GitHub Actions / GitLab CI detection CI/CD, false-positive tuning methodology, and the detection-as-code lifecycle checklist

- test-cases.md — 12 structured test cases (Sigma authoring, YARA authoring, SigmaCLI translation, yarGen generation, Loki scan, hayabusa scan, zircollo offline, ATT&CK mapping, CI pipeline, FP tuning, KQL/SPL/EQL backends, lifecycle) with severity ratings and summary tables

- guides/detection-engineering-playbook.md — End-to-end detection engineering playbook (lifecycle, rule anatomy deep-dives, CI/CD pipeline recipes, FP-tuning matrix, ATT&CK coverage measurement, integration with threat-hunting and logging-monitoring)

- guides/soc-playbook-mapping-to-nist-csf-2-0.md — SOC playbook mapping detections to NIST CSF 2.0 and MITRE ATT&CK (Function mapping for Govern/Identify/Protect/Detect/Respond/Recover, Sigma → ATT&CK → CSF traceability matrix, detection-as-code pipeline, use-case prioritization matrix, detection maturity model DMM, purple-team validation with Atomic Red Team + RTA, and SOC KPIs)

Summary

Detection Engineering skill domain covering the craft of writing, testing, deploying, and retiring detection rules as code.

Tools: SigmaHQ + SigmaCLI, YARA + Yara-Rules, yarGen, Loki, hayabusa, zircollo, Splunk SPL, Microsoft Sentinel KQL, Elastic EQL/Lucene, MITRE ATT&CK, EVTX-ATTACK-SAMPLES, pySigma, sigma-scanner

Domain: defense

MITRE ATT&CK: TA0040-Detection (detection engineering discipline); rules in this skill provide coverage across every ATT&CK technique via the Sigma taxonomy.

Description

Detection engineering is the discipline of treating detection content — Sigma rules, YARA signatures, SIEM queries, EDR detections — as first-class software artifacts with version control, peer review, automated tests, staged rollouts, and retirement criteria. The detection engineer reads threat intelligence and red-team tradecraft, drafts a Sigma rule (or YARA signature, or SPL query) that captures the TTP, writes unit tests that assert the rule fires on known-malicious samples from EVTX-ATTACK-SAMPLES and stays silent on known-benign baseline data, ships it through a GitHub Actions / GitLab CI pipeline that validates YAML schema and ATT&CK tag coverage, deploys to staging for a false-positive soak, and only then promotes to production. This is detection-as-code and it is what separates a SOC that pages on noise from a SOC that pages on signal.

Difference from threat-hunting: Threat hunting is the analytic practice of forming a hypothesis and walking the telemetry to test whether an adversary is inside. Detection engineering is the craft practice of authoring, testing, and shipping the rules that hunting and the SOC rely on. Hunting consumes telemetry; detection engineering manufactures the reusable detectors that consume telemetry. A hunt that finds something becomes a detection-engineering work item; a detection that fires becomes a hunt hypothesis for refinement. They are paired: hunting supplies the empirical truth that detection engineers encode, and detection engineers supply the detectors that hunters lean on for breadth.

Difference from logging-monitoring: Logging & monitoring is infrastructure — the sensors, shippers, indexes, retention, and tamper-proof storage that produce the telemetry in the first place. Detection engineering is content — the queries and rules that run against that infrastructure. You cannot engineer a detection for an event that is not logged; you can log forever and have zero detections. logging-monitoring builds the grid; detection-engineering writes what runs on it.

Difference from deception-honeypot: Deception manufactures high-fidelity telemetry from fake assets — every hit is signal because no legitimate user touches a decoy. Detection engineering trades in noisy telemetry — production logs where legitimate admin activity blends with adversary tradecraft — and the craft is in writing rules that suppress the former while catching the latter. The two complement: a honeypot produces a near-zero-FP detection (covered in deception-honeypot); detection engineering produces the bulk of SOC detections where FP tuning is the central craft problem.

Detection engineering lifecycle: threat intel / TTP → rule draft → unit test against positive and negative corpora → CI validation (schema, ATT&CK tags, syntax) → staging soak → FP tuning → production ship → coverage layer update → quarterly review → retirement. This skill teaches every phase.

Use Cases

Core Tools

Sigma Ecosystem

| Tool | Purpose | Command / Usage |

|------|---------|-----------------|

| Sigma | Vendor-neutral YAML signature format for log detection — the "YARA for logs." Author once, translate to any SIEM. | Author .yml; the YAML is the source of truth |

| SigmaHQ/sigma | The reference rule repository — 3000+ community Sigma rules mapped to ATT&CK, organized by tactic. | git clone https://github.com/SigmaHQ/sigma; consume rules or submit PRs |

| SigmaCLI (sigma-cli) | Command-line interface to the pySigma translation engine. Converts Sigma YAML → Splunk, Sentinel, Elastic, QRadar, ArcSight, Logpoint, etc. | sigma-cli convert -t splunk -p splunk_windows rule.yml |

| pySigma | The Python library underlying SigmaCLI; supports custom backends, pipelines, and validators. | from sigma.collection import SigmaCollection; from sigma.backends.splunk import SplunkBackend |

YARA Ecosystem

| Tool | Purpose | Command / Usage |

|------|---------|-----------------|

| YARA | Pattern-matching engine for files and memory — the malware-family classification standard. | yara -r rules.yar /opt/samples/ |

| Yara-Rules/rules | The community YARA rule repository — signature packs for malware families, exploits, and tools. | git clone https://github.com/Yara-Rules/rules.git |

| yarGen | Auto-generates YARA rules from a set of malware samples by extracting strings that do NOT appear in a benign corpus. | python3 yarGen.py -m /opt/malware/ -o /tmp/rule.yar --top 20 |

| Loki (Neo23x0) | IOC + YARA scanner — Sweeps a host or directory against a curated YARA + IOC database (Suricata ET, ThreatFox, custom). | python3 loki.py -p /opt/samples --rules /opt/signatures/ |

EVTX Scanners (Sigma-to-EVTX)

| Tool | Purpose | Command / Usage |

|------|---------|-----------------|

| hayabusa (Yamato Security) | Fast Sigma-to-EVTX scanner written in Rust — applies the full SigmaHQ rule set to a folder of .evtx files in minutes. | ./hayabusa csv-timeline -d /opt/evtx/ -o timeline.csv -r rules/ |

| zircollo | Lightweight Sigma-to-EVTX scanner — converts Sigma rules to SQLite SQL, then queries EVTX-to-SQLite exports. | python3 zircollo.py -e evtx/ -r rules.yml -o matches.json |

| EVTX-ATTACK-SAMPLES (sbousseaden) | Reference corpus of attack-generated EVTX files mapped to ATT&CK — the positive test corpus for detection testing. | git clone https://github.com/sbousseaden/EVTX-ATTACK-SAMPLES.git |

SIEM Query Languages (Detection Backends)

| Platform | Language | Example Detection |

|----------|----------|-------------------|

| Splunk | SPL (Search Processing Language) | index=win sourcetype=XmlWinEventLog:Microsoft-Windows-Sysmon/Operational EventCode=1 Image="*\\rundll32.exe" CommandLine="*MiniDump*" |

| Microsoft Sentinel / Defender | KQL (Kusto Query Language) | DeviceProcessEvents \| where FileName =~ "rundll32.exe" \| where ProcessCommandLine has "MiniDump" |

| Elastic Stack | Lucene + EQL (Event Query Language) + ES\|QL | process where process.name == "rundll32.exe" and process.command_line == "*MiniDump*" |

Frameworks & References

| Framework | Purpose |

|-----------|---------|

| MITRE ATT&CK Enterprise | Canonical TTP taxonomy — every Sigma rule carries attack.tXXXX[.XXX] tags; coverage is measured by tag union. |

| MITRE ATT&CK Navigator | Visualizes coverage as a heatmap layer — generated from Sigma rule tags. |

| OSSEM | Common data model — used in Sigma field mapping for cross-vendor portability. |

| SigmaHQ pySigma-pipeline-sysmon | Field-name mapping pipeline that translates generic Sigma fields to Sysmon-specific names. |

Methodology

Detection Engineering Six-Phase Lifecycle

Phase 1            Phase 2            Phase 3            Phase 4            Phase 5            Phase 6
Threat Intel   →   Rule Draft      →  Unit Test      →  CI Validation   →  Staging Soak   →  Production &
& TTP Intake       Authoring          (pos + neg corpus)  (schema + tags +    (FP measurement)    Retirement
   │                  │                  │                  backends)            │                  │
   ▼                  ▼                  ▼                  ▼                    ▼                  ▼
Read TI report,  Draft Sigma YAML  Test rule against   GitHub Actions:     Deploy to staging  Ship to prod,
red-team report, or YARA signature EVTX-ATTACK-       sigma-cli convert   SIEM, observe for  update ATT&CK
or ATT&CK         matching the      SAMPLES (must      to every backend;   7-30 days; FP     Navigator layer;
technique →       technique         fire) + benign     schema validate;   tune below        quarterly review
detection gap                       EVTX (must stay    lint ATT&CK tags   threshold; ship   → retire if silent
                                    silent)                                                  > 24 months

Phase 1: Threat Intel & TTP Intake

Every detection begins with a TTP (technique, tactic, procedure) drawn from threat intel, red-team findings, or an ATT&CK coverage gap.

Intake sources:
- Threat intel reports (vendor blogs, CISA advisories, MISP events)
- Red-team debrief ("we emulated T1003.001 via comsvcs.dll; did you catch it?")
- ATT&CK Navigator coverage layer (red cells = uncovered techniques)
- Incident retrospectives ("we missed X; build a detection for it")
- Community Sigma rule PRs to SigmaHQ/sigma

Output: a one-paragraph "detection design" capturing:
  - ATT&CK ID(s) covered
  - Log source(s) required (Sysmon EID 1, WinEvent 4688, Zeek dns.log, etc.)
  - Hypothesis: "if TTP X happened, we would see Y in log source Z"
  - Expected FP rate (TTP-level hunts have lower FP than IOC-level)
  - Pyramid-of-Pain elevation (TTP-level > behavior-level > IOC-level)

Phase 2: Rule Draft Authoring

Draft the Sigma YAML (or YARA signature, or SIEM-native query). The Sigma file is the source of truth.

# Sigma rule draft — Mimikatz credential dumping (T1003.001)
title: Mimikatz Command Line Patterns
id: c6e3dea0-e1a7-4d2e-9f17-c1f3f0d4a7b2
status: experimental
description: >-
  Detects Mimikatz command-line invocations matching the canonical
  sekurlsa::logonpasswords / lsadump::sam / kerberos::ptt patterns.
  TTP: T1003.001 LSASS Memory, T1003.002 Security Account Manager.
references:
  - https://attack.mitre.org/techniques/T1003/001/
  - https://github.com/gentilkiwi/mimikatz
author: kali-claw detection-engineering skill
date: 2026/06/17
tags:
  - attack.credential_access
  - attack.t1003.001
  - attack.t1003.002
logsource:
  product: windows
  category: process_creation
detection:
  selection_mimikatz_image:
    Image|endswith:
      - '\mimikatz.exe'
  selection_mimikatz_commandline:
    CommandLine|contains:
      - 'sekurlsa::logonpasswords'
      - 'sekurlsa::minidump'
      - 'lsadump::sam'
      - 'lsadump::dcsync'
      - 'kerberos::ptt'
      - 'kerberos::golden'
      - 'crypto::capi'
      - 'privilege::debug'
  filter_legitimate_admin:
    ParentImage|endswith:
      - '\sccm.exe'         # SCCM admin tasks
      - '\wsca.exe'         # in-house IT tooling
  condition: selection_mimikatz_image or
             (CommandLine and selection_mimikatz_commandline and not filter_legitimate_admin)
fields:
  - Computer
  - User
  - Image
  - CommandLine
  - ParentImage
falsepositives:
  - Authorized mimikatz use by the internal red team (filter by ParentUser)
  - Security training exercises (filter by host naming convention)
level: high

Phase 3: Unit Testing (Positive + Negative Corpora)

A detection without tests is a hypothesis, not a detector. Test on:

Positive corpus (rule MUST fire):
  - EVTX-ATTACK-SAMPLES/Windows/.../mimikatz-logonpasswords.evtx
  - Red-team emulation logs (atomic-red-team or CALDERA output)
  - Lab-generated: run mimikatz, capture Sysmon log, ship to corpus

Negative corpus (rule MUST stay silent):
  - 30 days of benign EVTX from production workstations
  - SCCM admin activity
  - Antivirus scans
  - Software-deployment activity

Test command (hayabusa):
  ./hayabusa csv-timeline -d evtx-positive/ -r rule.yml
  # Expect: 1+ match in the positive folder

  ./hayabusa csv-timeline -d evtx-negative/ -r rule.yml
  # Expect: 0 matches in the negative folder

Phase 4: CI Validation

Every PR to the detections repo runs through a CI pipeline. Failures block merge.

# .github/workflows/detection-ci.yml
name: Detection CI
on: [pull_request, push]
jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: '3.11' }

      - name: Install SigmaCLI
        run: pip install sigma-cli pySigma-backend-splunk pySigma-backend-elasticsearch

      - name: Schema validate every Sigma rule
        run: |
          for f in $(find rules/ -name '*.yml'); do
            sigma-cli parse "$f" || exit 1
          done

      - name: ATT&CK tag coverage check
        run: |
          python3 scripts/check-tags.py rules/
          # Asserts every rule has >= 1 attack.tXXXX tag

      - name: Translate to every backend (catch syntax errors)
        run: |
          for f in $(find rules/ -name '*.yml'); do
            sigma-cli convert -t splunk "$f" > /dev/null || exit 1
            sigma-cli convert -t lucene "$f" > /dev/null || exit 1
            sigma-cli convert -t kibana-ndjson "$f" > /dev/null || exit 1
          done

      - name: Positive corpus test
        run: |
          docker run --rm -v $PWD:/work yamatosecurity/hayabusa:latest \
            csv-timeline -d /work/test-data/positive/ -r /work/rules/ \
            -o /tmp/pos.csv
          test -s /tmp/pos.csv  # must produce non-empty output

      - name: Negative corpus test
        run: |
          docker run --rm -v $PWD:/work yamatosecurity/hayabusa:latest \
            csv-timeline -d /work/test-data/negative/ -r /work/rules/ \
            -o /tmp/neg.csv
          # Expect zero matches for any rule tagged level>=medium

Phase 5: Staging Soak & FP Tuning

Deploy to the staging SIEM, observe for 7-30 days, measure FP rate. Tune until FP rate < target threshold (typically < 1 hit/day).

FP tuning workflow:
1. Pull every hit from staging over the soak period
2. Group by (ParentImage, ParentUser, Computer, CommandLine signature)
3. For each cluster > 5 hits/day: identify if it is benign
4. If benign: add a filter clause, re-test on the historical soak data
5. Re-deploy, observe for another soak period
6. Repeat until FP rate < target OR escalate to "rule is too noisy, redesign"

Common FP-tuning patterns:
- Filter by parent process (SCCM, GPO, in-house tools)
- Filter by signer (Microsoft, the org's code-signing cert)
- Filter by host naming convention (jump hosts, build servers)
- Constrain CommandLine pattern (anchor to start, require exact flag)
- Add a timeframe aggregation (only fire if N hits in T minutes)

Phase 6: Production & Retirement

Ship to production SIEM. Update the ATT&CK Navigator coverage layer. Set a quarterly review reminder. A rule that goes silent for 24 months is retired.

# Ship: commit the rule, the PR merges after CI passes
git add rules/credential_access/mimikatz-cmdline.yml
git commit -m "feat(detection): T1003.001 mimikatz cmdline patterns (FP <0.5/day over 30d soak)"

# Update coverage layer
python3 scripts/build-navigator-layer.py rules/ -o coverage.json
# Upload to ATT&CK Navigator

# Quarterly review
python3 scripts/rule-liveness.py --since 90d
# Reports each rule's hit count; rules with 0 hits across all SIEMs
# for 24 months are candidates for retirement

Quick Selection Guide

| Scenario | Primary Tool | Alternative |

|----------|--------------|-------------|

| Author a vendor-neutral log detection | Sigma YAML + SigmaCLI | YARA (if file-based) |

| Translate Sigma to Splunk SPL | sigma-cli convert -t splunk | pySigma SplunkBackend |

| Translate Sigma to Sentinel KQL | sigma-cli convert -t microsoft-365-defender | Hand-translate using ATT&CK workbooks |

| Translate Sigma to Elastic EQL | sigma-cli convert -t eql | pySigma ElasticsearchBackend |

| Auto-generate YARA from malware samples | yarGen.py -m /opt/samples | Hand-author after string analysis |

| Scan a host's EVTX with Sigma rules | hayabusa csv-timeline -d evtx/ -r rules/ | zircollo.py -e evtx/ -r rules.yml |

| Scan files for malware family IOCs | loki.py -p /opt/samples --rules signatures/ | yara -r rules.yar /opt/samples/ |

| Test a rule against known-malicious EVTX | EVTX-ATTACK-SAMPLES + hayabusa | Atomic Red Team + lab EVTX |

| CI-validate a Sigma rule on every PR | GitHub Actions + sigma-cli | GitLab CI + sigma-cli |

| Build a coverage heatmap | ATT&CK Navigator + Sigma tag union | MITRE CAR coverage mapping |

Defense Perspective

This skill IS the defense perspective. Detection engineering is the practice of building the reusable detectors that the SOC, threat hunters, and IR all rely on. Quality gates are central:

| Defense Output | Description |

|----------------|-------------|

| Detection-as-code repository | A Git repo (Sigma rules, YARA signatures, SPL/KQL/EQL queries) where every rule has: an author, a date, an ATT&CK tag, a status (experimental/stable/deprecated), a level, and a documented FP rate. CI runs on every PR. |

| Unit-tested detections | Every rule ships with a positive-corpus test (fires on known-malicious EVTX) and a negative-corpus test (silent on known-benign EVTX). Untested rules do not ship. |

| CI/CD pipeline | A GitHub Actions / GitLab CI pipeline that validates YAML schema, ATT&CK tag coverage, backend translation, and positive/negative corpus behavior. Pipeline failures block the merge. |

| FP-tuning discipline | Every production rule has a documented FP rate. Hits above threshold trigger a tuning sprint. Rules that cannot be tuned below threshold are deprecated. |

| Coverage measurement | An ATT&CK Navigator layer generated from the union of rule tags. Quarterly review with the red team prioritizes new detections for uncovered techniques. |

| Lifecycle discipline | Rules move experimental → stable → deprecated. Quarterly reviews identify silent rules (24 months without a hit) for retirement. The detections repo does not grow unbounded. |

| Detection backends | Sigma is the source of truth; SIEM queries are generated. A rule update propagates to every SIEM via CI; no manual duplication. |

Practical Steps

Detailed payloads in payloads.md, complete test checklist in test-cases.md.

Exercise 1: Author a Sigma Rule for Mimikatz (T1003.001)

Goal: draft, test, and ship a Sigma rule for Mimikatz command-line invocations.

mkdir -p detections/t1003-001-mimikatz
cd detections/t1003-001-mimikatz

# Draft the Sigma rule (see Phase 2 above for the full YAML)
$EDITOR mimikatz-cmdline.yml

# Validate the schema
sigma-cli parse mimikatz-cmdline.yml

# Translate to Splunk SPL
sigma-cli convert -t splunk -p sysmon mimikatz-cmdline.yml

# Translate to Elastic Lucene
sigma-cli convert -t lucene mimikatz-cmdline.yml

# Translate to Kibana NDJSON (importable rule)
sigma-cli convert -t kibana-ndjson mimikatz-cmdline.yml > kibana-import.ndjson

# Test against positive corpus (EVTX-ATTACK-SAMPLES)
git clone https://github.com/sbousseaden/EVTX-ATTACK-SAMPLES.git /tmp/evtx-attack
hayabusa csv-timeline -d /tmp/evtx-attack/ -r mimikatz-cmdline.yml -o hits.csv
# Expect: matches in Triggers/ credential-access/ subfolder

# Commit
git add mimikatz-cmdline.yml
git commit -m "feat(detection): T1003.001 mimikatz cmdline patterns"

Exercise 2: Author a YARA Rule for a Malware Family

Goal: write a YARA rule for the Cobalt Strike beacon PE loader.

mkdir -p yara-rules/malware-family
$EDITOR cobalt_strike_beacon.yar

# cobalt_strike_beacon.yar
# rule CobaltStrike_Beacon_Loader {
#   meta:
#     description = "Cobalt Strike beacon loader - PE rich header pattern"
#     author = "kali-claw detection-engineering skill"
#     date = "2026-06-17"
#     reference = "https://attack.mitre.org/software/S0154/"
#     malpedia = "win.cobalt_strike"
#   strings:
#     $rich1 = { 68 02 00 00 03 00 00 00 }   # DOS stub pattern
#     $rich2 = "DanS" wide ascii              # rich header magic
#     $xor_loop = { 80 30 ?? 46 49 75 ?? }   # XOR decrypt loop
#     $api_resolve = "VirtualAlloc" wide ascii
#   condition:
#     uint16(0) == 0x5A4D and       # PE MZ magic
#     $rich1 and $rich2 and
#     ($xor_loop or $api_resolve) and
#     filesize < 500KB
# }

# Validate syntax
yara cobalt_strike_beacon.yar /tmp/any-file.bin

# Test against positive corpus (known CS beacon samples)
yara -r cobalt_strike_beacon.yar /opt/samples/cobalt-strike/
# Expect: matches on each sample

# Test against negative corpus (benign PE files)
yara -r cobalt_strike_beacon.yar /opt/samples/benign-pe/
# Expect: zero matches

# Commit
git add cobalt_strike_beacon.yar
git commit -m "feat(yara): Cobalt Strike beacon loader signature"

Exercise 3: Translate a Sigma Rule to Three SIEM Backends

Goal: take one Sigma YAML, produce Splunk SPL, Sentinel KQL, and Elastic EQL.

# Single Sigma rule
cat > rules/aws-console-login-new-geo.yml <<'EOF'
title: AWS Console Login from New Geographic Location
id: f0d1a2b3-c4d5-6789-abcd-ef0123456789
status: experimental
description: >-
  Detects AWS Management Console logins (ConsoleLogin) from a geographic
  location not seen for this user in the preceding 14 days. T1078 Valid Accounts.
references:
  - https://attack.mitre.org/techniques/T1078/
tags:
  - attack.initial_access
  - attack.t1078
logsource:
  product: aws
  service: cloudtrail
detection:
  selection_console_login:
    eventName: ConsoleLogin
    eventSource: signin.amazonaws.com
    responseElements_ConsoleLogin: Success
  condition: selection_console_login
falsepositives:
  - User travel (legitimate new geo)
  - VPN / corporate egress changes
level: medium
EOF

# Translate to Splunk SPL
sigma-cli convert -t splunk rules/aws-console-login-new-geo.yml

# Translate to Microsoft Sentinel / Defender KQL
sigma-cli convert -t microsoft-365-defender rules/aws-console-login-new-geo.yml

# Translate to Elastic EQL
sigma-cli convert -t eql rules/aws-console-login-new-geo.yml

# The Sigma file is the source of truth; the platform queries are
# generated artifacts, committed alongside the rule for auditability.

Exercise 4: Generate a YARA Rule with yarGen

Goal: auto-generate a YARA rule from a folder of malware samples.

# Clone yarGen
git clone https://github.com/Neo23x0/yarGen.git
cd yarGen
pip install -r requirements.txt

# Initialize the benign string database (one-time, ~1 hour)
python3 yarGen.py --update

# Generate a rule from a folder of malware samples
python3 yarGen.py \
  --malware /opt/samples/malware-family-x/ \
  --top 20 \
  --exclude-extensions pdf,docx \
  --output /tmp/family-x.yar

# Review the generated rule
cat /tmp/family-x.yar
# yarGen emits a rule with the highest-signal strings it found;
# the engineer reviews, removes low-signal strings (e.g., "MZ",
# "This program cannot be run in DOS mode"), and tightens the condition.

# Test the generated rule
yara -r /tmp/family-x.yar /opt/samples/malware-family-x/   # expect matches
yara -r /tmp/family-x.yar /opt/samples/benign/             # expect zero matches

Exercise 5: Scan a Host's EVTX with hayabusa

Goal: take a Windows host's EVTX files and enumerate every ATT&CK technique observed.

# Download hayabusa
wget https://github.com/YamatoSecurity/hayabusa/releases/latest/download/hayabusa-2.18.0-linux.zip
unzip hayabusa-2.18.0-linux.zip -d hayabusa
cd hayabusa

# Update the built-in Sigma rules
./hayabusa update-rules

# Pull EVTX from the suspect host (off-host, no tip-off)
# SCP from the Windows host:
# C:\Windows\System32\winevt\Logs\*.evtx

# Run a full timeline
./hayabusa csv-timeline \
  -d /opt/evtx/suspect-host/ \
  -r rules/ \
  -o timeline.csv \
  --min-level medium \
  --no-color

# Summary: which ATT&CK techniques fired
./hayabusa metrics \
  -d /opt/evtx/suspect-host/ \
  -o metrics.csv

# Output is a CSV timeline; pivot to ATT&CK Navigator for visualization

Exercise 6: Scan Files with Loki (YARA + IOC)

Goal: sweep a directory of binaries against a curated YARA + IOC database.

# Clone Loki
git clone https://github.com/Neo23x0/Loki.git
cd Loki
pip install -r requirements.txt

# Update the signature database
python3 loki.py --update

# Scan a directory
python3 loki.py \
  --path /opt/samples \
  --rules /opt/signatures/custom-yara/ \
  --results /tmp/loki-results.csv \
  --alert-level 40 \
  --no-sigs \
  --force

# Review alerts
jq -r 'select(.severity >= 70)' /tmp/loki-results.csv | head -50

# Loki flags: --no-sigs disables Suricata-style NIDS rules,
# --force re-scans even if hashes were previously clean

Exercise 7: Build a Detection CI Pipeline (GitHub Actions)

Goal: every PR to rules/ runs schema validation, backend translation, and corpus tests.

mkdir -p .github/workflows
$EDITOR .github/workflows/detection-ci.yml
# .github/workflows/detection-ci.yml (full content in payloads.md §14)
name: Detection CI
on: [pull_request, push]
jobs:
  sigma-validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: '3.11' }
      - run: pip install sigma-cli pySigma-backend-splunk pySigma-backend-elasticsearch
      - name: Parse every rule
        run: |
          for f in $(find rules/ -name '*.yml'); do
            sigma-cli parse "$f" || exit 1
          done
      - name: Translate to backends
        run: |
          for f in $(find rules/ -name '*.yml'); do
            sigma-cli convert -t splunk "$f" > /dev/null || exit 1
            sigma-cli convert -t lucene "$f" > /dev/null || exit 1
          done
  corpus-test:
    needs: sigma-validate
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run hayabusa on positive corpus
        run: |
          docker run --rm -v $PWD:/work \
            yamatosecurity/hayabusa:latest \
            csv-timeline -d /work/test-data/positive/ \
            -r /work/rules/ -o /tmp/pos.csv
          test -s /tmp/pos.csv

Exercise 8: Tune a Noisy Detection's False-Positive Rate

Goal: a Sigma rule is firing 200×/day on legitimate SCCM activity. Tune it.

# Pull every hit from the last 7 days
index=win sourcetype=XmlWinEventLog:Microsoft-Windows-Sysmon/Operational
  EventCode=1 Image="*\\rundll32.exe" CommandLine="*comsvcs.dll*MiniDump*"
| stats count by Computer, User, ParentImage
| sort -count
| outputlookup noisy-detection-hits.csv

# Identify the top FP cluster: SCCM (\sccm.exe parent), running a legit
# crash-dump workflow during patch Tuesday.

# Add a filter to the Sigma rule
$EDITOR rules/credential_access/comsvcs-minidump.yml
# Add to detection:
#   filter_sccm:
#     ParentImage|endswith:
#       - '\sccm.exe'
#       - '\cmmcompiler.exe'
#   condition: selection and not filter_sccm

# Re-test against 30 days of historical data
sigma-cli convert -t splunk rules/comsvcs-minidump.yml | splunk search -e -30d
# Verify FP rate is now < 1/day

# Commit the tuned rule
git add rules/credential_access/comsvcs-minidump.yml
git commit -m "fix(detection): filter SCCM parent for comsvcs minidump (FP 200/d → 0.3/d)"

Exercise 9: Measure ATT&CK Coverage and Identify Gaps

Goal: produce an ATT&CK Navigator layer from the rule repository.

# Build the coverage layer from every Sigma rule's tags
python3 scripts/build-navigator-layer.py rules/ -o coverage.json
# The script reads every rule, extracts attack.tXXXX[.XXX] tags,
# and emits a Navigator layer where each technique is colored by
# the number of rules covering it.

# Upload to ATT&CK Navigator
# https://mitre-attack.github.io/attack-navigator/
# Layer → Open Layer → Upload coverage.json

# Identify red cells (techniques with zero coverage)
python3 scripts/coverage-gaps.py coverage.json
# Output: list of ATT&CK techniques with no rule, sorted by
# prevalence in current threat intel reports.

# Quarterly review with red team: pick top 5 red cells, file
# detection-engineering tickets for each.

Exercise 10: Retire a Deprecated Detection

Goal: a Sigma rule for a 5-year-old ransomware family has not fired in 24 months. Retire it.

# Confirm silence
python3 scripts/rule-liveness.py rules/malware/old-ransom-family.yml --since 730d
# Output: 0 hits across all SIEMs in the last 730 days

# Move to deprecated/
mkdir -p rules/deprecated
git mv rules/malware/old-ransom-family.yml rules/deprecated/

# Update the rule's status
$EDITOR rules/deprecated/old-ransom-family.yml
# Change: status: stable → status: deprecated

# Commit
git add -A
git commit -m "chore(detection): retire old-ransom-family rule (silent 24m+)"
# Coverage layer regenerates on next CI run; the technique may now show
# as partially covered (if other rules cover it) or uncovered.

Detection Methods

Detection Engineering Quality Metrics

Detection Rule Validation

Defense Evasion Techniques

Bypass Detection Engineering

Defense Evasion Specific Techniques

SIEM/Logging Blind Spots

Cross-References

This skill is the craft layer that produces detectors consumed by hunting, IR, and the SOC.

Safety Notes

Hacker Laws

Learning Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.