Detect illicit OAuth consent grants (KQL)
In an illicit consent-grant attack, a user is tricked into approving a malicious OAuth application that then reads mail, files or other data using the granted delegated permissions — no password or MFA needed afterwards. This AuditLogs query returns consent operations, resolves the actor and application, and pulls out the permissions requested and whether the grant was admin consent.
Prioritise grants that include high-impact scopes (Mail.Read, Files.ReadWrite.All, offline_access) or that were admin-consented tenant-wide.
The query
AuditLogs
| where TimeGenerated > ago(24h)
| where OperationName in (
"Consent to application",
"Add OAuth2PermissionGrant",
"Add delegated permission grant")
| extend Actor = coalesce(
tostring(InitiatedBy.user.userPrincipalName),
tostring(InitiatedBy.app.displayName))
| mv-expand TargetResources
| extend AppName = tostring(TargetResources.displayName)
| mv-apply mp = TargetResources.modifiedProperties on (
where tostring(mp.displayName) in (
"ConsentAction.Permissions", "ConsentContext.IsAdminConsent")
| project Detail = strcat(tostring(mp.displayName), " = ", tostring(mp.newValue))
)
| project TimeGenerated, Actor, AppName, Detail, Result
| sort by TimeGenerated descLine-by-line explanation
| where OperationName in ("Consent to application", ...)These operations are written when a user or admin consents to an app or a delegated permission grant is created.
where tostring(mp.displayName) == "ConsentAction.Permissions"ConsentAction.Permissions lists the scopes the app was granted — the detail that separates a benign app from a data-exfiltration one.
"ConsentContext.IsAdminConsent"Tells you whether this was tenant-wide admin consent (far higher impact) or a single user granting consent for themselves.
Required tables and columns
OperationNameThe consent-related operation, such as 'Consent to application'.TargetResourcesThe application and the modifiedProperties describing the permissions and consent type.InitiatedByThe user or app that granted consent.ResultWhether the consent succeeded.
MITRE ATT&CK mapping
- Tactic
- Credential AccessTA0006
- Technique
- T1528· Steal Application Access Token
Tuning and false positives
- Parse ConsentAction.Permissions and alert when it contains high-risk scopes like Mail.ReadWrite, Files.ReadWrite.All or full_access_as_app.
- Allow-list verified publisher apps and your own line-of-business app ids to cut routine consent noise.
Limitations
- Benign users consent to legitimate apps constantly; without scope filtering this is noisy. Pair it with app-risk and verified-publisher signals.
- The permission detail format varies; confirm the modifiedProperties names in your tenant's log sample.
Related queries
References
Last reviewed 2026-11-18.