THREAT-BEC-OAuthDeviceCode Sumo Logic CSE · Sumo

Detect Business Email Compromise via OAuth Device Code Flow Phishing in Sumo Logic CSE

OAuth Device Code Flow phishing is a prevalent Business Email Compromise (BEC) technique actively used by Scattered Spider, Storm-2372, and nation-state actors including Midnight Blizzard. The attacker sends a phishing message containing a Microsoft device code (a short alphanumeric code from https://microsoft.com/devicelogin), social-engineered to appear as an IT helpdesk request, MFA enrollment notification, or remote support session. When the victim enters the code, the attacker receives a valid OAuth access token and refresh token for the victim's Microsoft 365 account — with no password required. The attacker then has full access to email, Teams, SharePoint, OneDrive, and any M365 service the victim is licensed for. Refresh tokens may persist for 90 days, providing long-term access even after password reset. This technique bypasses MFA entirely because the device code flow is a legitimate Microsoft authentication mechanism.

MITRE ATT&CK

Tactic
Credential Access Collection

Sumo Detection Query

Sumo Logic CSE (Sumo)
sql
(_sourceCategory="o365" OR _sourceCategory="azure/signin")
| json field=_raw "Operation", "UserId", "ClientIP", "AuthenticationDetails", "Parameters", "UserAgent", "Location", "AppDisplayName", "ResourceDisplayName" nodrop
| where Operation in ("UserLoggedIn", "New-InboxRule", "Set-InboxRule", "Set-Mailbox")
| eval device_code = if(Operation = "UserLoggedIn" AND matches(AuthenticationDetails, "(?i)deviceCode"), "true", "false")
| eval suspicious_agent = if(matches(UserAgent, "(?i)(python-requests|curl|wget|Go-http-client|okhttp|axios)"), "true", "false")
| eval inbox_rule_fwd = if(
    Operation in ("New-InboxRule", "Set-InboxRule", "Set-Mailbox") AND
    matches(Parameters, "(?i)(ForwardTo|DeleteMessage|RedirectTo|ForwardAsAttachmentTo|MoveToFolder)") AND
    !matches(Parameters, "(?i)Junk Email"),
    "true", "false"
  )
| where device_code = "true" OR inbox_rule_fwd = "true"
| where suspicious_agent = "true" OR inbox_rule_fwd = "true" OR (device_code = "true" AND Location not in ("GB", "US"))
| timeslice 4h
| stats
    count as Events,
    values(Operation) as Operations,
    values(ClientIP) as IPs,
    values(AuthenticationDetails) as AuthDetails,
    values(Parameters) as RuleParams,
    values(UserAgent) as UserAgents,
    values(Location) as Locations
  by UserId, _timeslice
| where Events > 1 OR inbox_rule_fwd = "true"
| fields UserId, _timeslice, Events, Operations, IPs, AuthDetails, RuleParams, UserAgents, Locations
| sort by Events desc
critical severity high confidence

Detects OAuth Device Code Flow BEC phishing in Microsoft 365 by identifying device code authentication events from suspicious user agents or anomalous locations, followed by inbox rule creation with forwarding or deletion actions — a hallmark post-compromise BEC pattern used by Scattered Spider, Storm-2372, and Midnight Blizzard.

Data Sources

Microsoft 365 Management Activity LogsAzure AD Sign-In Logs

Required Tables

o365 management activity logs ingested under _sourceCategory=o365 or azure/signin

False Positives & Tuning

  • Legitimate IT administrators using scripting tools (Python, curl) to automate M365 management tasks via device code flow
  • Users traveling internationally who authenticate via device code from unfamiliar locations
  • Inbox rules created by users for legitimate email management such as auto-forwarding to a secondary personal account
  • Helpdesk or IT onboarding workflows that provision inbox rules as part of standard user setup

Other platforms for THREAT-BEC-OAuthDeviceCode


Testing Methodology

Validate this detection against 2 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.

  1. Test 1OAuth Device Code Flow Token Request (Simulated Phishing)

    Expected signal: Azure AD Sign-in logs record a DeviceCode flow initiation. When user enters the code, AADSignInLogs records a successful authentication with AuthenticationProtocol=deviceCode.

  2. Test 2Create BEC Inbox Forwarding Rule via Exchange Online PowerShell

    Expected signal: O365 Unified Audit Log records New-InboxRule operation with ForwardTo parameter for the authenticated user.

Unlock Pro Content

Get the full detection package for THREAT-BEC-OAuthDeviceCode including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections