KQLHunting query: tune before alertingShadow AI and AI-powered attackers
Entra ID user or admin consent granted to an AI application
AI assistants, meeting bots and writing tools ask for delegated Microsoft Graph access to mail, files and chats; a single Allow click gives a third party durable access (offline_access) to that data. Entra records each grant as the ApplicationManagement activity "Consent to application", with ConsentContext.IsAdminConsent and ConsentAction.Permissions in the modified properties. This hunt filters grants to apps whose names match an AI keyword list and highlights the scopes Microsoft's consent playbook calls out as most abused.
- Log source
- Microsoft Sentinel / Log Analytics: AuditLogs (Entra ID)
- Techniques
- ASI03 Identity and Privilege Abuse · LLM02 Sensitive Information Disclosure · LLM06 Excessive Agency
- MITRE ATT&CK
- T1528Steal Application Access TokenT1671Cloud Application Integration
- Reviewed
- 2026-11-10
Query
let ai_app_keywords = dynamic(["ChatGPT", "OpenAI", "Claude", "Anthropic", "Gemini", "Copilot", "Perplexity",
"Otter", "Fireflies", "Read AI", "Grammarly", "Notion", "Glean", "DeepSeek", "Manus"]);
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName == "Consent to application"
| where Result =~ "success"
| extend AppName = tostring(TargetResources[0].displayName), ServicePrincipalId = tostring(TargetResources[0].id)
| where AppName has_any (ai_app_keywords)
| mv-apply prop = TargetResources[0].modifiedProperties on (
summarize IsAdminConsent = take_anyif(tostring(prop.newValue), tostring(prop.displayName) == "ConsentContext.IsAdminConsent"),
Permissions = take_anyif(tostring(prop.newValue), tostring(prop.displayName) == "ConsentAction.Permissions"))
| extend Actor = coalesce(tostring(InitiatedBy.user.userPrincipalName), tostring(InitiatedBy.app.displayName))
| extend HighRiskScope = Permissions matches regex @"(?i)(Mail\.|Files\.|Sites\.|Chat\.|Contacts\.|MailboxSettings\.|Notes\.|offline_access)"
| project TimeGenerated, Actor, AppName, ServicePrincipalId, IsAdminConsent, HighRiskScope, Permissions
| order by HighRiskScope desc, TimeGenerated desc Expected false positives
- Sanctioned AI apps that users are expected to connect (filter by ServicePrincipalId)
- Non-AI apps whose names contain a keyword (for example Notion without AI features)
Sources
- Microsoft Entra audit log activity reference
- Azure Monitor: AuditLogs table reference
- Microsoft: App consent grant investigation playbook
- SigmaHQ: End User Consent (Entra ID)
Reviewed against vendor documentation, not tested in your environment. Defensive use only.