Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

detection-authoring

FreeRuns bundled scriptsNot checked

Create, deploy, update, and manage custom detection rules in Microsoft Defender XDR via the Graph API (/beta/security/rules/detectionRules), or hand the…

SCStelzby SCStelz★ 256 GitHub stars

About this skill

Custom Detection Authoring — Instructions

Purpose

This skill deploys custom detection rules to Microsoft Defender XDR via the Microsoft Graph API (/beta/security/rules/detectionRules). It handles:

  • Query adaptation — Converting Sentinel KQL queries into custom detection format
  • Wizard-link hand-off — Turning a validated manifest rule into a prefilled Detection Wizard link the analyst reviews and Saves (no Graph consent, no tenant change by the agent)
  • Single-rule deployment — Creating one rule via Graph API
  • Batch deployment — Deploying multiple rules from a JSON manifest
  • Lifecycle management — Listing, updating, enabling/disabling, and deleting rules
  • Validation — Dry-run queries in Advanced Hunting before deployment

Entity Type: Custom detection rules (Defender XDR)

Starting from threat intelligence? A Microsoft Perception threat-intelligence report (via perception-extract-threat-intel) lists TTPs with Detection opportunity and Telemetry; use a TTP row as the seed for kql-query-authoring, then author the rule here (manifest + wizard link).

Writing new detection queries from scratch? This skill focuses on deploying and managing detection rules — not query creation. If you need to write detection KQL from scratch (schema validation, community examples, performance optimization), use the kql-query-authoring skill first with CD intent markers (say "create custom detection queries for [scenario]"). It will produce Sentinel-format queries with cd-metadata blocks ready for this skill to adapt and deploy.


📑 TABLE OF CONTENTS

  1. Prerequisites — Auth, scopes, PowerShell modules
  2. Critical Rules — Mandatory constraints (includes query adaptation checklist)
  3. Naming Convention — Standardized displayName format (no prefixes, no MITRE IDs, colon separators)
  4. API Reference — Graph API schema and field values
  5. Frequency & Lookback — Schedule periods, lookback windows, NRT constraints
  6. Deployment Paths — Graph API script vs prefilled Detection Wizard link
  7. Deployment Workflow — Step-by-step process
  8. Batch Deployment — Manifest-driven multi-rule deployment
  9. Lifecycle Management — CRUD operations
  10. Existing Rule Discovery — Search Analytic Rules & Custom Detections by table, EventID, or keyword
  11. Known Pitfalls — Lessons learned (20 pitfalls documented)
  12. CD Metadata Contract — Schema for query file ↔ detection skill coordination

Prerequisites

Required PowerShell Module

# Microsoft.Graph.Authentication — provides Invoke-MgGraphRequest
Install-Module Microsoft.Graph.Authentication -Scope CurrentUser

Required Graph API Scopes

Operation Scope Type
List / Get rules CustomDetection.Read.All Delegated
Create / Update / Delete CustomDetection.ReadWrite.All Delegated

Authentication

# Read-only
Connect-MgGraph -Scopes "CustomDetection.Read.All" -NoWelcome

# Full CRUD
Connect-MgGraph -Scopes "CustomDetection.ReadWrite.All" -NoWelcome

Why Invoke-MgGraphRequest? The Graph MCP server and az rest both return 403 for custom detection endpoints — they lack the CustomDetection.* scopes. Invoke-MgGraphRequest uses interactive delegated auth with consent, which works.

Companion Script

Deploy-CustomDetections.ps1 — PowerShell script for manifest-driven batch deployment. See Batch Deployment.

wizard_link.py — Python helper (stdlib only, no Graph scopes) that validates a manifest rule and builds a prefilled Detection Wizard link. See Deployment Paths.


⚠️ CRITICAL RULES — READ FIRST ⚠️

Mandatory Query Requirements

Custom detection queries have strict requirements that differ from Sentinel analytic rules:

Requirement Detail
🔴 Author-only by default The default behavior is to author, validate, and write the manifest only — do NOT call the Graph API to deploy rules unless the user explicitly says "deploy", "create the rule", "push to Defender", or similar deployment-intent language. If deployment intent is ambiguous, ask before calling the API. Generating a Detection Wizard link (see Deployment Paths) changes no tenant state and is allowed in author mode.
Timestamp column must be projected as-is The query MUST project the timestamp c
Full SKILL.md on GitHub

Install detection-authoring in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

Deploy-CustomDetections.ps1example-manifest.jsonwizard_link.py

FAQ

What does the detection-authoring skill do?

Create, deploy, update, and manage custom detection rules in Microsoft Defender XDR via the Graph API (/beta/security/rules/detectionRules), or hand the analyst a prefilled Detection Wizard link to review and Save. Covers query adaptation from Sentinel KQL to custom detection format, deployment via PowerShell (Invoke-MgGraphRequest), manifest-driven batch deployment, wizard-link generation/validation (wizard_link.py), and lifecycle management (list, enable/disable, delete). Companion scripts: Deploy-CustomDetections.ps1, wizard_link.py.

How do I install the detection-authoring skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the detection-authoring skill run scripts?

Yes, this skill bundles executable scripts. Review the source before installing.

Related skills

Compare detection-authoring with