Microsoft 365 Threat Detection: Defender XDR and Sentinel KQL Queries for BEC, Token Theft and OAuth Abuse

November 19, 2026 · 3 min read · IT Guiders Team

Microsoft 365 Threat Detection: Defender XDR and Sentinel KQL Queries for BEC, Token Theft and OAuth Abuse

Detect Microsoft 365 attacks with Defender XDR and Microsoft Sentinel: connectors, audit log setup and KQL queries for password spray, impossible travel, OAuth consent and mailbox rules.

Most Microsoft 365 intrusions show up in identity and audit logs long before data is stolen. With the right logs enabled and a handful of tested queries, a small team can detect business email compromise, token theft and malicious app consent early.

Prerequisites

  • Turn on the unified audit log and mailbox auditing (on by default for most tenants; verify).
  • Connect Microsoft Entra ID (sign-in and audit logs), Microsoft 365 (Exchange, SharePoint, Teams) and Defender XDR connectors to Microsoft Sentinel.
  • Send Entra sign-in logs, including non-interactive and service principal sign-ins, to a Log Analytics workspace.
  • Check retention: 90 days hot, longer in archive if regulations require.

Detection 1: password spray

SigninLogs
| where TimeGenerated > ago(1h) and ResultType in ("50126","50053")
| summarize Attempts=count(), Users=dcount(UserPrincipalName), Apps=make_set(AppDisplayName) by IPAddress
| where Users >= 10 and Attempts >= 30

Detection 2: successful sign-in after many failures

let failed = SigninLogs | where TimeGenerated > ago(1d) and ResultType != "0"
  | summarize Fails=count() by UserPrincipalName, IPAddress | where Fails > 10;
SigninLogs
| where TimeGenerated > ago(1d) and ResultType == "0"
| join kind=inner failed on UserPrincipalName, IPAddress
| project TimeGenerated, UserPrincipalName, IPAddress, AppDisplayName, Fails

Detection 3: new or unusual sign-in location with MFA satisfied by token

Token theft often shows as a sign-in from a new IP with MfaDetail empty and an existing session.

SigninLogs
| where TimeGenerated > ago(1d) and ResultType == "0"
| where AuthenticationRequirement == "singleFactorAuthentication" or isempty(tostring(MfaDetail))
| where RiskLevelDuringSignIn in ("medium","high")
| project TimeGenerated, UserPrincipalName, IPAddress, Location, AppDisplayName, RiskLevelDuringSignIn

Combine with Entra ID Protection risk detections where available.

AuditLogs
| where TimeGenerated > ago(7d) and OperationName in ("Consent to application","Add delegated permission grant")
| extend app = tostring(TargetResources[0].displayName), who = tostring(InitiatedBy.user.userPrincipalName)
| where tostring(TargetResources[0].modifiedProperties) has_any ("Mail.Read","Mail.ReadWrite","Files.ReadWrite.All","offline_access")
| project TimeGenerated, who, app

Restrict user consent in Entra ID to verified publishers and low-risk permissions, and enable the admin consent workflow.

Detection 5: suspicious inbox rules (Defender XDR advanced hunting)

CloudAppEvents
| where Timestamp > ago(7d) and ActionType in ("New-InboxRule","Set-InboxRule")
| extend p = tostring(RawEventData.Parameters)
| where p has_any ("ForwardTo","RedirectTo","DeleteMessage")
| project Timestamp, AccountDisplayName, IPAddress, p

Detection 6: mass download or sharing

OfficeActivity
| where TimeGenerated > ago(1d) and Operation in ("FileDownloaded","FileSyncDownloadedFull")
| summarize Files=count() by UserId, ClientIP, bin(TimeGenerated,1h)
| where Files > 200

Turn queries into analytics rules

Create scheduled analytics rules with sensible frequency (5 to 60 minutes), map entities (Account, IP), tag MITRE ATT&CK techniques (T1110 Brute Force, T1550 Use Alternate Authentication Material, T1114 Email Collection, T1098 Account Manipulation) and attach a playbook that disables the user and revokes sessions after analyst approval.

Tune and measure

Record true and false positives for every rule, add allow-lists with an expiry date and review rules monthly. Track mean time to detect and respond, rules per ATT&CK technique and incidents closed with root cause.

Common mistakes

Collecting logs with no rules; copying community queries without testing; alerts without an owner; forgetting service principal and non-interactive sign-ins, where many token attacks appear.

IT Guiders builds Microsoft Sentinel and Defender detections and can run them under a managed SOC agreement.

microsoft sentinel kql detectionsmicrosoft-solutions

This article is general information, not legal, audit or compliance advice.

Related articles

Ready To Transform Your Technology Strategy?

Talk to an expert about your goals. No obligation, direct access to specialists.