A collection of KQL (Kusto Query Language) queries and Microsoft Defender XDR / Sentinel custom detection rules for Microsoft 365, Entra ID, and Modern Workplace security monitoring.
This repo is organized by topic, with each subfolder covering a specific monitoring area. New Modern Work-related KQL content will be added over time.
Custom detection rules for monitoring the organization's break glass (emergency access) accounts in Microsoft Defender XDR, without triggering automated remediation that could inadvertently lock out emergency access.
| # | Rule | Severity | Frequency | Table |
|---|---|---|---|---|
| 1 | Detect the Sign-in with the Break Glass Account | High | Continuous (NRT) | EntraIdSignInEvents |
| 2 | Detection-FailedSignin-Threshold (3+/hour) | Medium | Hourly | EntraIdSignInEvents |
| 3 | MFA / authentication method & credential changes | High | Hourly | CloudAppEvents |
| 4 | Detect Removal from CA Exclusion Group | High | Hourly | CloudAppEvents |
| 5 | Detect Deletion or Restore of BG Account | High | Continuous (NRT) | CloudAppEvents |
- Many Entra ID audit
ActionTypevalues end with a trailing period (e.g."Update user.","Remove member from group.") — always verify the exact string against liveRawEventDatabefore finalizing a query. - Event JSON structure varies by activity type: sign-in/consent events use
TargetResources; directory management events (user/group) useObjectId(target) +ModifiedProperties, with the actor inAccountObjectId/AccountDisplayName. - Prefer matching on Object ID (GUID) over UPN — a deleted user's UPN gets auto-prefixed with its Object ID, breaking UPN-based substring matches.
- For credential/auth-method changes, filter on the generic
"Included Updated Properties"field insideModifiedPropertiesrather than enumerating every possible property name. - Queries using
summarizeormv-expanddisqualify a rule from Continuous (NRT) frequency — Defender falls back to a fixed interval (hourly). CloudAppEventsingestion typically lags 15–60 minutes behind the Entra ID audit log UI — check the portal audit log first when validating a test event.- Defender alert title/description accepts a maximum of 3 distinct column placeholders combined.
- Omit Mailbox entity mapping unless it's genuinely relevant — it can incorrectly map a UPN as a mailbox address and add noise.
- Browse to the relevant module folder.
- Copy the
.kqlquery into Defender → Advanced Hunting or a new Custom detection rule. - Replace tenant-specific placeholders (UPNs, Object IDs, group IDs) with your own values.
- Configure alert metadata, entity mapping, and MITRE ATT&CK tags as documented in the module README.
- Test with a controlled event before relying on the rule in production.
AADSignInEventsBeta → EntraIdSignInEvents) — always validate against your own tenant's live data before deploying.
New Modern Work-related KQL (Conditional Access, privileged role monitoring, Exchange Online, Teams, etc.) is welcome as new module folders following the same structure: a module README + individual .kql files.