detection-authoring
FreeRuns bundled scriptsNot checkedCreate, deploy, update, and manage custom detection rules in Microsoft Defender XDR via the Graph API (/beta/security/rules/detectionRules), or hand the…
by SCStelz★ 256 GitHub starsAbout 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 forkql-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-metadatablocks ready for this skill to adapt and deploy.
📑 TABLE OF CONTENTS
- Prerequisites — Auth, scopes, PowerShell modules
- Critical Rules — Mandatory constraints (includes query adaptation checklist)
- Naming Convention — Standardized
displayNameformat (no prefixes, no MITRE IDs, colon separators) - API Reference — Graph API schema and field values
- Frequency & Lookback — Schedule periods, lookback windows, NRT constraints
- Deployment Paths — Graph API script vs prefilled Detection Wizard link
- Deployment Workflow — Step-by-step process
- Batch Deployment — Manifest-driven multi-rule deployment
- Lifecycle Management — CRUD operations
- Existing Rule Discovery — Search Analytic Rules & Custom Detections by table, EventID, or keyword
- Known Pitfalls — Lessons learned (20 pitfalls documented)
- 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 andaz restboth return 403 for custom detection endpoints — they lack theCustomDetection.*scopes.Invoke-MgGraphRequestuses 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 |
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
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
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
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
by Anthropic