1. Resources
  2. Detection rules
  3. Device Code Phishing

Device Code Phishing detection rules

An attacker starts the OAuth device code flow and tricks a user into entering the code on Microsoft's real sign-in page. The user completes MFA and the attacker's session receives the tokens.

Platform
Microsoft Entra ID
Severity
High
Log source
Microsoft Entra ID sign-in logs
Last updated
Rule formats
Sigmaand queries for: SplunkMicrosoft Sentinel
What an attacker needs
Device code flow that is not blocked by Conditional Access for the targeted users, and a way to reach the victim while the code is still valid.
Impact
Access and refresh tokens for the victim's account, issued after the victim completed MFA, which the attacker can turn into durable access by registering a device.
Response
Revoke the sessions and refresh tokens of the user at once, and delete every device that was registered for the user after the device code sign-in.
Mitigation
Block device code flow with a Conditional Access authentication flows policy, and exclude only the documented accounts that need it.

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.

LevelHighStatusExperimentalLog sourceMicrosoft Entra ID sign-in logs
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.

LevelMediumStatusExperimentalLog sourceMicrosoft Entra ID sign-in logs
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

Detection hypothesisJoins two logsNeeds your own listsNeeds a baseline

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.

  1. Sign-in log: a successful sign-in (ResultType 0) with AuthenticationProtocol deviceCode. Take UserPrincipalName, SessionId, IPAddress and AutonomousSystemNumber.
  2. Interactive and non-interactive sign-in logs, the following 24 hours: sign-ins of the same user with the same SessionId whose OriginalTransferMethod is device code flow (deviceCodeFlow in the Microsoft Graph sign-in resource).
  3. Keep those whose IPAddress is outside your known egress ranges and was not used by the user in the 30 days before, or whose AutonomousSystemNumber differs from that of the device code sign-in.
  4. 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

Detection hypothesisSequence of eventsJoins two logs

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.

  1. Sign-in log: a successful sign-in (ResultType 0) with AuthenticationProtocol deviceCode. Take UserPrincipalName and the time.
  2. Interactive and non-interactive sign-in logs, the following 2 hours: a successful sign-in of the same user whose ResourceDisplayName is Device Registration Service.
  3. Audit log, same window: Add registered owner to device with the same user in TargetResources, which names the new device.
  4. 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:

  1. 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.
  2. 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.
  3. Remove what the attacker added to the account, such as authentication methods, inbox and forwarding rules and application consents.
  4. 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.
  5. 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

We respect your privacy

We use cookies to keep this site secure and working properly. With your permission, we also use optional cookies to understand usage and improve the experience. Cookie Policy

You can change your choice at any time.