# How to block device code phishing in Microsoft Entra ID and remove rogue devices

Device code phishing let attackers register their own devices in hundreds of Microsoft 365 tenants in November. This guide shows how to find those sign-ins and devices, cut off access and block the flow with Conditional Access.

By [AI Security Times](https://aisecuritytimes.com/authors/ai-security-times) · Published 2026-12-04T05:24:00Z
Canonical: https://aisecuritytimes.com/guides/block-device-code-phishing-entra-id

Intermediate · 45 min · Last reviewed 2026-12-04 · Tested on Checked against Microsoft Learn documentation as published on Dec 4, 2026; menu names can change

## Prerequisites

- A Microsoft Entra ID tenant (Microsoft 365) and an account with the Conditional Access Administrator and Cloud Device Administrator roles
- Microsoft Entra ID P1 or higher for Conditional Access; tenants on the free tier use security defaults instead (step 6)
- A list of the people and devices that really need device code sign-in, such as meeting-room or shared devices

In November, a phishing campaign tricked people in 305 organizations into approving device sign-in codes, then registered the attackers' own Windows devices in their Microsoft 365 tenants, according to Huntress. A registered device keeps working after a password reset, so many victims may still have an intruder's device in their directory. The full story is in [Device-code phishing campaign planted rogue devices in 305 Microsoft 365 organizations, Huntress says](/cybersecurity/huntress-device-code-phishing-rogue-entra-devices).

This guide covers six steps: find device code sign-ins, find rogue devices, cut off their access, block the flow, tighten device registration and, on the free tier, turn on security defaults. Menu paths and setting names come from Microsoft's documentation as published on Dec 4, 2026.

## What device code flow is

Device code flow is a legitimate way to sign in on devices without a keyboard. Microsoft describes it like this: "Device code flow lets you sign into devices that lack local input devices, like shared devices or digital signage. Device code flow is a high-risk authentication method that can be part of a phishing attack or used to access corporate resources on unmanaged devices."

"Attackers can abuse device code flow in phishing attacks by tricking users into entering a code on another device," Microsoft's security defaults page explains. The resulting tokens go to the attacker. Microsoft's advice is clear: "Microsoft recommends blocking device code flow wherever possible."

## Step 1: Find device code sign-ins

In the Microsoft Entra admin center, open the sign-in logs and use the **Authentication Protocol** filter with the **Device code** option. Microsoft suggests exactly this to see how the flow is used before blocking it.

Look for sign-ins that users cannot explain. In the campaign Huntress tracked, the phishing sign-in went through the Microsoft Authentication Broker application, and the non-interactive logs then showed a switch to a new address and a programmatic user agent such as `python-requests`.

## Step 2: Find rogue devices

Go to **Entra ID > Devices > Overview**, then **All devices**. The **Download devices** option exports a CSV file that includes, among other columns, `displayName`, `operatingSystemVersion`, `trustType`, `registrationDateTime` and `owner`.

Check the export against the marks Huntress found on the rogue devices:

| What to check | Rogue devices in the Huntress campaign |
|---|---|
| Device name | `MH-` followed by 16 uppercase hexadecimal characters, matching `^MH-[0-9A-F]{16}$` |
| OS version | `10.0.19041.928`, the default in the public ROADtools toolkit; Huntress also lists `10.0.19045.2006`, `10.0.19045.0` and `10.0.26100` for related activity |
| Hardware identifiers | None |
| Registration date | Shortly after a device code sign-in by the same user |

Version 10.0.19041.928 is Windows 10 version 2004, which Microsoft stopped servicing in 2021, so a patched company laptop would not report it. Other attackers can use other names, so also look for any device that its owner does not recognise.

## Step 3: Cut off access

For each rogue device:

1. **Disable the device first.** On the **All devices** page, select the device and choose **Disable** from the toolbar. Microsoft's documentation says: "Disabling a device revokes the Primary Refresh Token (PRT) and any refresh tokens on the device." That token is what keeps the attacker signed in after a password reset. You need the Intune Administrator or Cloud Device Administrator role.
2. **Delete it once you are sure.** Microsoft warns that deleting "is a nonrecoverable activity" and removes all details attached to the device, such as BitLocker keys, so confirm the device is not legitimate first. For devices that only look stale, Microsoft advises disabling them "for a grace period before deleting". Deleting needs the Cloud Device Administrator, Intune Administrator or Windows 365 Administrator role.
3. **Revoke the user's sessions.** Go to **Entra ID > Users > All users**, select the user and, on the **Overview** page, select **Revoke sessions**. In Microsoft Graph PowerShell, Microsoft's documented command is `Revoke-MgUserSignInSession -UserId $User.Id`.
4. **Reset the password, then check MFA methods and inbox rules.** Huntress recommends removing any authentication method or device the user does not recognise and looking for suspicious inbox rules.

Revoking sessions has limits. Microsoft notes that Entra ID "can't directly revoke a session token issued by an application", and that access tokens last one hour by default. Expect some access to linger for up to an hour.

## Step 4: Block device code flow with Conditional Access

Create the policy in report-only mode first, so you can see who it would affect. Microsoft's steps:

1. Sign in to the Microsoft Entra admin center as at least a **Conditional Access Administrator**.
2. Browse to **Entra ID > Conditional Access > Policies** and create a new policy.
3. Under **Assignments**, select **Users or workload identities**. Under **Include**, select the users in scope; Microsoft recommends all users.
4. Under **Exclude**, select **Users and groups** and choose your emergency access or break-glass accounts and any other necessary users. Microsoft says to "audit this exclusion list regularly."
5. Under **Target resources > Resources (formerly cloud apps) > Include**, select the apps in scope; Microsoft recommends **All resources**.
6. Under **Conditions > Authentication Flows**, set **Configure** to **Yes** and select **Device code flow**.
7. Under **Access controls > Grant**, select **Block access**.
8. Set **Enable policy** to **Report-only** and select **Create**.
9. After checking the policy's impact in the sign-in logs, change **Enable policy** from **Report-only** to **On**.

Two warnings from Microsoft. If your organization uses device code flow to register devices and the policy targets all resources, you must exclude the **Device Registration Service** from the policy (**Target resources > Exclude > Select excluded cloud apps > Device Registration Service**). And once the policy is on, sessions that earlier used device code flow are blocked too, with the error `AADSTS530036`; Microsoft says there is "no recommended remediation" for this, so test in report-only mode first.

If some devices genuinely need device code flow, Microsoft's advice is to "get as close as possible to a unilateral block" and to allow the flow "only where necessary".

## Step 5: Tighten device registration

In the device settings of the Microsoft Entra admin center (the Cloud Device Administrator role can change them), review:

- **Users may register their devices with Microsoft Entra ID**: who can register personal devices. If Intune or mobile device management for Microsoft 365 is configured, this is fixed to **All**.
- **Require multifactor authentication to register or join devices with Microsoft Entra ID**: the default is **No**. Microsoft recommends enforcing this with the **Register or join devices** user action in Conditional Access instead; if you do, this toggle must stay at **No**.
- **Maximum number of devices**: the default is 50 per user. A lower limit reduces how many devices one compromised account can add.

These settings limit the damage one account can do. Blocking device code flow in step 4 removes the way in that this campaign used.

## Step 6: On the free tier, turn on security defaults

Conditional Access needs Microsoft Entra ID P1 or higher. Organizations on the free tier can use security defaults instead: "After security defaults are enabled in your tenant, authentication requests that use device code flow are blocked." Microsoft adds that since July 1, 2026, all new Microsoft Entra tenants block device code flow as part of security defaults. Older tenants should check that security defaults are actually on.

## Checklist

- Sign-in logs filtered for device code sign-ins, and unexplained ones investigated.
- Device list exported and checked for `MH-` names, old Windows builds and devices nobody recognises.
- Rogue devices disabled, then deleted; user sessions revoked; passwords, MFA methods and inbox rules checked.
- Conditional Access policy blocking device code flow, tested in report-only mode and then turned on.
- Device registration settings reviewed.

## References

1. [Microsoft Learn: Authentication flows as a condition in Conditional Access policy](https://learn.microsoft.com/en-us/entra/identity/conditional-access/concept-authentication-flows) (Microsoft)
2. [Microsoft Learn: Block authentication flows with Conditional Access policy](https://learn.microsoft.com/en-us/entra/identity/conditional-access/policy-block-authentication-flows) (Microsoft)
3. [Microsoft Learn: Manage device identities using the Microsoft Entra admin center](https://learn.microsoft.com/en-us/entra/identity/devices/manage-device-identities) (Microsoft)
4. [Microsoft Learn: How to manage stale devices in Microsoft Entra ID](https://learn.microsoft.com/en-us/entra/identity/devices/manage-stale-devices) (Microsoft)
5. [Microsoft Learn: Revoke user access in Microsoft Entra ID](https://learn.microsoft.com/en-us/entra/identity/users/users-revoke-access) (Microsoft)
6. [Microsoft Learn: Security defaults in Microsoft Entra ID](https://learn.microsoft.com/en-us/entra/fundamentals/security-defaults) (Microsoft)
7. [Huntress: M365 Device Code Phishing Campaign Leads to Hundreds of Rogue Entra ID Registrations (Dec 3, 2026)](https://www.huntress.com/blog/device-code-phishing-m365-registrations) (Research)

Topics: [Identity](https://aisecuritytimes.com/topics/identity), [Phishing](https://aisecuritytimes.com/topics/phishing), [Hardening](https://aisecuritytimes.com/topics/hardening)
