10 Essential KQL Queries for Microsoft Sentinel M365 & Entra Threat Hunting
Hunting Microsoft 365 intrusions in Microsoft Sentinel or Defender XDR relies on correlating four core KQL tables—SigninLogs, AADNonInteractiveUserSignInLogs, AuditLogs, and OfficeActivity—across AiTM user-agents, valid-password MFA stalls (50074), rogue security-info/OAuth changes, stealth Inbox Rules, and SharePoint bursts. AuditVane ships matching client-side rules (AV-001 to AV-012) when Sentinel isn’t available.
Detection Objective & Threat Scope
SOC engineers running Microsoft Sentinel rely on Kusto Query Language (KQL) for live tenant-wide detection—yet during M&A assessments, customer IR retainers on Business Premium/E3, or standalone incident escalations where Sentinel wasn’t connected beforehand, analysts get handed raw Purview CSVs and Entra JSON downloads instead.
Keeping identical detection logic across your Sentinel KQL hunting pack and AuditVane’s offline browser engine ensures zero blind spots regardless of whether a client has Log Analytics or only raw exports.
Every AuditVane detection (`AV-001` through `AV-012`) maps cleanly onto standard Microsoft Sentinel and Defender XDR schemas (`OfficeActivity`, `SigninLogs`, `AADNonInteractiveUserSignInLogs`, and `AuditLogs`). Note one crucial syntax difference: Exchange `OfficeActivity` stores `UserId` in mixed case, whereas Entra `SigninLogs` stores `UserPrincipalName`—always join using case-insensitive `in~` or `tolower()`.
Below are battle-tested KQL hunting queries covering the complete M365 attack chain—from initial AiTM replay through OAuth persistence and SharePoint exfiltration.
Forensic Telemetry Fields & High-Signal Indicators
| Telemetry Field / Pattern | Meaning in M365 / Entra | High-Signal Threat Indicator |
|---|---|---|
OfficeActivity | Purview Unified Audit Log ingested into Sentinel | Covers InboxRules, MailItemsAccessed, SharePoint, Teams |
SigninLogs | Entra ID Interactive Sign-Ins | Covers IP, CA status, Risk, ResultType (50074/53003), UA |
AADNonInteractiveUserSignInLogs | Silent OAuth refresh token exchanges | Catches long-dwell AiTM cookie replay persistence |
AuditLogs | Entra Directory & Application Audit changes | Covers MFA registration, OAuth consent, PIM & role adds |
AADServicePrincipalSignInLogs | Daemon Service Principal authentications | Catches rogue client secret / certificate backdoors |
Case-Insensitive Joins (`in~`) | Essential when joining SigninLogs <-> OfficeActivity | Prevents missed joins due to UPN capitalization |
Production Sentinel KQL Hunting Pack (AiTM, BEC, OAuth & Exfil)
// 1. AiTM -> MFA Change -> Inbox Rule Cross-Table Chain:
let SuspectUsers = SigninLogs | where TimeGenerated > ago(7d)
| where RiskLevelDuringSignIn == "high" or UserAgent has_any ("axios","python","curl","go-http")
| distinct tolower(UserPrincipalName);
OfficeActivity | where TimeGenerated > ago(7d) and tolower(UserId) in (SuspectUsers)
| where Operation in ("New-InboxRule","Set-InboxRule","UpdateInboxRules","Set-Mailbox")
| project TimeGenerated, UserId, Operation, ClientIP, Parameters
// 2. Password Compromised Stopped at MFA / CA (50074 / 50076 / 53003):
SigninLogs | where TimeGenerated > ago(7d) and ResultType in ("50074","50076","50079","53003")
| summarize Hits=count(), IPs=make_set(IPAddress) by UserPrincipalName, ResultType
// 3. Illicit OAuth Consent & Service Principal Secret Backdoors:
AuditLogs | where TimeGenerated > ago(14d)
| where OperationName in ("Consent to application","Add OAuth2PermissionGrant","Add app role assignment to service principal","Add service principal credentials")
| project TimeGenerated, OperationName, InitiatedBy, TargetResources
// 4. SharePoint Anonymous Sharing & Mass Download Bursts:
OfficeActivity | where TimeGenerated > ago(7d)
| where Operation in ("AnonymousLinkCreated","AnonymousLinkUsed","FileDownloaded","FileSyncDownloadedFull")
| summarize Count=count(), Files=make_set(SourceFileName, 10) by Operation, UserId, ClientIP
Sample Sentinel Cross-Table KQL Output
TimeGenerated UserId Operation ClientIP Parameters
------------- ------ --------- -------- ----------
2026-12-01T08:18:55Z finance.director@contoso.invalid New-InboxRule 185.220.101.45 [{"Name":"MoveToFolder","Value":"RSS Feeds"}]
Microsoft Sentinel KQL vs. AuditVane Offline Workbench
| Workflow Dimension | Microsoft Sentinel / Log Analytics | AuditVane Browser Workbench |
|---|---|---|
| Best For | Continuous multi-month SIEM alerting across all users | Fast ad-hoc incident response on exported CSV/JSON files |
| Setup & Cost | Requires Azure subscription, ingestion connectors & E5/ingest fees | Free static GitHub Pages site; zero tenant setup |
| AuditData JSON Parsing | Requires `parse_json()` / `mv-expand` KQL expressions | Automatic recursive flattening + Name/Value expansion |
| Data Locality | Stored in Azure Log Analytics workspace | 100% browser RAM (0 bytes transmitted) |
Rule Equivalence Map: Sentinel KQL -> AuditVane Engine
{
"AV-001": "OfficeActivity | Stealth InboxRule Parameters",
"AV-002": "SigninLogs | Legacy ClientAppUsed (IMAP4/POP3/SMTP)",
"AV-003": "SigninLogs | Programmatic UserAgent (axios/python/curl)",
"AV-004": "AuditLogs | Security Info / MFA Mutations",
"AV-005": "AuditLogs | OAuth Consent & App Role / Secret Grants",
"AV-010": "OfficeActivity | SharePoint FileDownloaded & AnonymousLink"
}
Every AuditVane detection card also displays its exact matching KQL hunting query inside the methodology reference so analysts can paste rules directly from offline triage back into Microsoft Sentinel.
Real-World Incident Walkthrough
An MSSP runs weekly scheduled KQL hunts across 20 managed Sentinel tenants while carrying AuditVane on jump boxes for non-Sentinel IR engagements. When a KQL hunt spots `RiskLevelDuringSignIn == "high"` followed by `UpdateInboxRules` on an onboarding client without Sentinel retention, the responder pulls 90-day Purview CSV exports into AuditVane to finish the historical blast-radius timeline offline.
Step-by-Step Triage, Containment & Verification
- Run the four Sentinel KQL hunting queries above weekly (or convert them into Scheduled Analytics Rules with 1-hour lookbacks).
- Always enable `AADNonInteractiveUserSignInLogs` ingestion in Entra Diagnostic Settings—it is frequently disabled by default to save ingestion cost, creating a fatal AiTM blind spot!
- Normalize UPNs with `tolower()` whenever joining `SigninLogs` against `OfficeActivity`.
- When responding to external clients or unmonitored tenants without Sentinel, export raw Purview CSV + Entra JSON and drop them into AuditVane to run all 12 rules offline.
- Feed newly discovered attacker IPs from AuditVane (`Export IOCs JSON`) directly into a Sentinel Watchlist for retrospective sweeping.
How to Verify Containment Completed Cleanly
- OfficeActivity, SigninLogs, AADNonInteractiveUserSignInLogs, and AuditLogs verified ingesting into Sentinel.
- Case-insensitive UPN matching used in all cross-table KQL joins.
- Matching KQL queries documented on AuditVane Detection Rules page.
Analyst Blind Spots, Licensing Quirks & False Positives
A frequent Sentinel ingestion pitfall: `OfficeActivity` uses `OfficeObjectId` / `SourceFileName` and `RawEventData` (not `AuditData`), whereas raw Purview CSV exports name the column `AuditData`! Adapt column names when migrating KQL to local scripts.
Also watch Sentinel cost surprises from `AADNonInteractiveUserSignInLogs` and noisy `MailItemsAccessed`—use Log Analytics Basic/Auxiliary tiers or targeted filtering if budget is tight, while retaining at least 30 days in hot storage.
Frequently Asked Questions
Does AuditVane publish KQL queries for all 12 rules?
Yes! Visit the Detection Rules Methodology page on AuditVane to copy the Sentinel KQL equivalent for AV-001 through AV-012.
Why must I monitor AADNonInteractiveUserSignInLogs in Sentinel?
Because AiTM stolen cookies and refresh tokens renew silently inside Non-Interactive logs without ever creating new Interactive SigninLogs entries.
Can I run these detection checks without Microsoft Sentinel?
Yes—export your Entra JSON and Purview CSV files and drop them into AuditVane to execute the same 12 detections locally in your browser.
Why do joins between SigninLogs and OfficeActivity sometimes return zero rows?
Case sensitivity (User.Name@ vs. user.name@) or IP port suffixes (`1.2.3.4:51422` in OfficeActivity vs. `1.2.3.4` in SigninLogs). Always normalize both with `tolower()` and strip trailing ports!