How the attack works
The OAuth 2.0 device authorization grant lets devices without a browser, such as conference room systems or command-line tools, sign in: the device shows a short code and the user enters it on microsoft.com/devicelogin from another device. In device code phishing the attacker requests the code, sends it to the victim with a pretext (a meeting invite, a document share) and waits. The victim signs in on a genuine Microsoft page, satisfies MFA, and Microsoft Entra ID issues the access and refresh tokens to the attacker's session.
Nothing about the sign-in page is fake, so password managers, MFA and user training on look-alike domains do not help. The sign-in log entry belongs to the victim and records AuthenticationProtocol as deviceCode, but the IP address and device that use the tokens afterwards are the attacker's. When the attacker requests the code for the Microsoft Authentication Broker client, the tokens can be used to register a device and obtain a Primary Refresh Token, which turns a phished session into durable access.
What an attacker needs
- Device code flow not blocked by a Conditional Access authentication flows policy for the targeted users.
- A way to reach the victim (email, chat, collaboration invites) within the roughly 15 minutes a device code stays valid.
Impact
Access and refresh tokens for the victim's account, issued after the victim completed MFA. The attacker can read mail and files, move to other Microsoft 365 workloads with the refresh token, and, through the authentication broker, register a device to obtain a Primary Refresh Token that satisfies device-based Conditional Access.
Detection rules
Device Code Sign-In to the Microsoft Authentication Broker
Detects a successful device code sign-in whose client is the Microsoft Authentication Broker (29d9ed98-a469-4536-ade2-f981bc1d605e). Tokens issued to this client can be used to register a device and obtain a Primary Refresh Token, a pattern Microsoft reported in device code phishing campaigns.
title: Device Code Sign-In to the Microsoft Authentication Broker
id: 3d36d91f-f465-401b-849b-acb268a1aa0b
status: experimental
description: >-
Detects a successful device code sign-in whose client is the Microsoft
Authentication Broker (29d9ed98-a469-4536-ade2-f981bc1d605e). Tokens issued
to this client can be used to register a device and obtain a Primary Refresh
Token, a pattern Microsoft reported in device code phishing campaigns.
references:
- https://www.microsoft.com/en-us/security/blog/2025/02/13/storm-2372-conducts-device-code-phishing-campaign/
- https://learn.microsoft.com/en-us/entra/identity/devices/troubleshoot-mac-sso-extension-plugin
author: Forestall
date: 2026-11-10
tags:
- attack.credential-access
- attack.t1528
logsource:
product: azure
service: signinlogs
detection:
selection:
AuthenticationProtocol: deviceCode
AppId: 29d9ed98-a469-4536-ade2-f981bc1d605e
ResultType: '0' # string column: "0" is success
condition: selection
falsepositives:
- Device enrollment that legitimately uses the device code flow; confirm with the user and the device inventory, and exclude documented enrollment accounts by UserPrincipalName.
level: high
False positives
- Device enrollment that legitimately uses the device code flow; confirm with the user and the device inventory, and exclude documented enrollment accounts by UserPrincipalName.
Successful Sign-In With the Device Code Flow
Detects a successful interactive sign-in that used the OAuth device code flow (AuthenticationProtocol deviceCode). Most users never need it, so every occurrence outside known tools and devices deserves a look.
title: Successful Sign-In With the Device Code Flow
id: c687032f-0dae-41c5-a165-831e38ba2a80
status: experimental
description: >-
Detects a successful interactive sign-in that used the OAuth device code
flow (AuthenticationProtocol deviceCode). Most users never need it, so every
occurrence outside known tools and devices deserves a look.
references:
- https://learn.microsoft.com/en-us/entra/identity/conditional-access/concept-authentication-flows
- https://learn.microsoft.com/en-us/azure/azure-monitor/reference/tables/signinlogs
author: Forestall
date: 2026-11-10
tags:
- attack.credential-access
- attack.t1528
logsource:
product: azure
service: signinlogs
detection:
selection:
AuthenticationProtocol: deviceCode
ResultType: '0' # string column: "0" is success
condition: selection
falsepositives:
- Teams Rooms and other shared devices, and administrators who sign in to command-line tools with a code; add a filter on their UserPrincipalName or AppId once each use is documented.
level: medium
False positives
- Teams Rooms and other shared devices, and administrators who sign in to command-line tools with a code; add a filter on their UserPrincipalName or AppId once each use is documented.
Detection logic
Patterns that need more than one event, a baseline or knowledge of your own environment. Each is a hypothesis to build and tune in your SIEM, not a ready rule.
Tokens from a device code sign-in used from an address outside the organization
In device code phishing the victim enters the code on their own device, but the tokens go to the client that requested the code, which the attacker runs. Microsoft keeps a session that started with the device code flow marked through every later token refresh, so the later sign-ins of that session show where the tokens are really used. A session that continues from an address the organization does not use, and that the user never used, carries the attacker's client.
- Sign-in log: a successful sign-in (
ResultType0) withAuthenticationProtocoldeviceCode. TakeUserPrincipalName,SessionId,IPAddressandAutonomousSystemNumber. - Interactive and non-interactive sign-in logs, the following 24 hours: sign-ins of the same user with the same
SessionIdwhoseOriginalTransferMethodis device code flow (deviceCodeFlowin the Microsoft Graph sign-in resource). - Keep those whose
IPAddressis outside your known egress ranges and was not used by the user in the 30 days before, or whoseAutonomousSystemNumberdiffers from that of the device code sign-in. - Alert, and raise the priority when the later sign-ins reach mail, files or the Device Registration Service.
LimitsA legitimate command-line tool or meeting room device also redeems its tokens from another address than the browser where the code was typed, so exclude the known ranges and the documented device code users first. Microsoft does not document how long a session keeps its SessionId; check in your own logs that the refresh sign-ins carry the identifier of the device code sign-in. The 24 hours and 30 days are starting points.
Device code sign-in followed by a device registration for the same user
Microsoft reported device code phishing campaigns in which the attacker requested the code for the Microsoft Authentication Broker and then registered a device to obtain a Primary Refresh Token. A device registration for the user shortly after a device code sign-in is that second step, and it turns one phished session into lasting access.
- Sign-in log: a successful sign-in (
ResultType0) withAuthenticationProtocoldeviceCode. TakeUserPrincipalNameand the time. - Interactive and non-interactive sign-in logs, the following 2 hours: a successful sign-in of the same user whose
ResourceDisplayNameis Device Registration Service. - Audit log, same window:
Add registered owner to devicewith the same user inTargetResources, which names the new device. - Alert on the pair, and treat it as confirmed when the user did not enroll a device at that time.
EventsAdd registered owner to device
LimitsDevice enrollment that uses the device code flow on purpose produces the same pair, so exclude the documented enrollment accounts. A device registered later with the stolen refresh token falls outside the window, so widen it for the Microsoft Authentication Broker client. The 2 hours are a starting point.
Triage
- Check whether the user expected to sign in with a code (Azure CLI, a meeting room device) at that time; ask them how they received the code.
- Compare the IP address and location of the device code sign-in with the user's normal sign-ins, then look for later non-interactive sign-ins and token use from a different IP address.
- If the application is the Microsoft Authentication Broker, look for a new device registration for the user shortly after the sign-in.
- If malicious, revoke the user's sessions and refresh tokens, remove any device registered after the sign-in and review mailbox and file access during the window.
Response
Once the attack is confirmed:
- Revoke the sessions and refresh tokens of the user at once. The tokens are in the hands of the attacker, so the access continues until they are revoked.
- Delete every device that was registered for the user after the device code sign-in. A device registered by the attacker can hold a Primary Refresh Token and keep the access alive.
- Remove what the attacker added to the account, such as authentication methods, inbox and forwarding rules and application consents.
- Review the mail and files the account accessed between the sign-in and the revocation, and warn the recipients of messages sent in the name of the user.
- Search the sign-in log for other users with a successful device code sign-in in the same period, and ask them how they received the code. Handle each confirmed case in the same way.
Mitigation
- Block device code flow with a Conditional Access authentication flows policy, and exclude only the documented accounts that need it (for example Teams Rooms resource accounts).
- Inventory current device code usage in the sign-in logs before enforcement, then treat every remaining exception as a monitored risk acceptance.
- Require compliant or hybrid-joined devices for sensitive resources and restrict who can register devices in Microsoft Entra ID.
- Teach users that a sign-in code should never be entered because someone else sent it.
Frequently asked questions
Why does MFA not stop device code phishing?
The user signs in on a genuine Microsoft page and completes MFA themselves. Microsoft Entra ID then issues the access and refresh tokens to the session that requested the code, which is the attacker's. Nothing about the sign-in page is fake, so training on look-alike domains does not help either.
Does revoking the user's sessions cut the attacker off immediately?
Not always. After the refresh tokens are revoked the attacker cannot obtain new tokens with them, but Microsoft notes that an application using an access token keeps its access until that token expires, by default after one hour. Applications that support continuous access evaluation can end it sooner. A device the attacker registered has to be removed separately.
Who uses the device code flow legitimately?
Devices without a browser, such as conference room systems, and command-line tools that administrators sign in to with a code. Device enrollment can use it as well. Most users never need the flow, so document each legitimate use and filter it by UserPrincipalName or AppId.
Why is a device code sign-in to the Microsoft Authentication Broker more serious?
Tokens issued to that client can be used to register a device and obtain a Primary Refresh Token. That turns one phished session into durable access that also satisfies device-based Conditional Access. Microsoft reported this pattern in device code phishing campaigns.
References
- MITRE ATT&CK T1528: Steal Application Access Token
- Conditional Access: Authentication flows
- SigninLogs table reference (AuthenticationProtocol values)
- Microsoft Threat Intelligence: Storm-2372 conducts device code phishing campaign
- Revoke user access in Microsoft Entra ID (when access is revoked)
- AADNonInteractiveUserSignInLogs table reference
- signIn resource type (originalTransferMethod values)
- Microsoft Entra audit log activities (Add registered owner to device)
- Microsoft Entra security operations guide for applications (device code flow)