Blocking Device-Code Phishing in Microsoft Entra ID: Usage Audit, Report-Only Conditional Access, Enforcement and Hunting for Stolen Sessions

2026-11-09 · By H.A

Blocking Device-Code Phishing in Microsoft Entra ID: Usage Audit, Report-Only Conditional Access, Enforcement and Hunting for Stolen Sessions

Measure device code flow usage, block it with a Conditional Access authentication-flows policy, and hunt down tokens that device-code phishing kits already stole.

Device-code phishing has become one of the busiest ways to steal Microsoft 365 accounts this autumn. Kits like SkyW4lker send the victim to Microsoft's real sign-in page and ask them to type a short code. The victim completes MFA themselves, and the attacker's device receives the tokens. No password is stolen and no fake page appears, so the usual phishing advice doesn't help. The fix is to stop the flow everywhere it isn't needed. This tutorial shows how to measure device code usage in your tenant, roll out a Conditional Access block in report-only mode, enforce it with narrow exceptions, and hunt for sessions that were already stolen.

Prerequisites

Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Policy.Read.All","Policy.ReadWrite.ConditionalAccess","Application.Read.All"

Step 1: Find out who actually uses device code flow

Device code flow is meant for devices without a keyboard or browser, such as conference-room systems, digital signage and some CLI tools. In most tenants only a handful of accounts need it. Find out who they are before you block anything.

In the Entra admin center, go to Monitoring & health > Sign-in logs, select Add filters > Authentication Protocol and choose Device code. Check both the User sign-ins (interactive) and User sign-ins (non-interactive) tabs and look back as far as your retention allows.

If your logs go to Log Analytics, this query gives a quick inventory:

SigninLogs
| where TimeGenerated > ago(30d)
| where AuthenticationProtocol == "deviceCode"
| summarize Count = count(), Apps = make_set(AppDisplayName, 10),
            IPs = make_set(IPAddress, 10), LastSeen = max(TimeGenerated)
          by UserPrincipalName, ResultType
| order by Count desc

Write down every legitimate use you find, for example Teams Rooms accounts, a specific admin running Azure CLI with --use-device-code, or kiosk devices. These become your exclusions.

Step 2: Create the policy in report-only mode

Go to Entra ID > Conditional Access > Policies > New policy, then configure:

  1. Name: CA-BLOCK-DeviceCodeFlow
  2. Users: Include All users. Exclude your break-glass accounts and a group such as CA-Exclude-DeviceCode holding the accounts you found in Step 1.
  3. Target resources: All resources. Under Exclude, choose Select excluded cloud apps and add Device Registration Service if your organisation registers devices with device code flow. Microsoft enforces authentication flows policies on that service when a policy targets all resources.
  4. Conditions > Authentication flows: set Configure to Yes and tick Device code flow. Tick Authentication transfer too unless you rely on users scanning a QR code in desktop Outlook to sign in on mobile.
  5. Grant: Block access.
  6. Enable policy: Report-only.

To script it instead, the Graph property is conditions.authenticationFlows.transferMethods:

$params = @{
  displayName = "CA-BLOCK-DeviceCodeFlow"
  state       = "enabledForReportingButNotEnforced"
  conditions  = @{
    users = @{
      includeUsers  = @("All")
      excludeUsers  = @("<break-glass-object-id>")
      excludeGroups = @("<CA-Exclude-DeviceCode-group-id>")
    }
    applications = @{
      includeApplications = @("All")
      excludeApplications = @("01cb2876-7ebd-4aa4-9cc9-d28bd4d359a9")  # Device Registration Service
    }
    authenticationFlows = @{ transferMethods = "deviceCodeFlow,authenticationTransfer" }
  }
  grantControls = @{ operator = "OR"; builtInControls = @("block") }
}
New-MgIdentityConditionalAccessPolicy -BodyParameter $params

Step 3: Review report-only results

Leave the policy in report-only mode for one to two weeks. Then open Conditional Access > Insights and reporting, pick the policy, and look at the Failure results, which are sign-ins the policy would have blocked. You can also open any sign-in and check the Report-only tab.

With Log Analytics:

SigninLogs
| where TimeGenerated > ago(14d)
| mv-expand CAP = ConditionalAccessPolicies
| where CAP.displayName == "CA-BLOCK-DeviceCodeFlow"
| where CAP.result == "reportOnlyFailure"
| summarize Hits = count() by UserPrincipalName, AppDisplayName
| order by Hits desc

Every hit should be either a legitimate account that belongs in your exclusion group or something suspicious that needs looking into (see Step 5).

Step 4: Enforce the block and tighten the exceptions

When the report-only data looks clean, switch Enable policy to On. Make the exclusions as narrow as you can:

Step 5: Hunt for tokens that were already stolen

A block stops new device-code sign-ins, but it doesn't remove access an attacker already has. Look for device-code sign-ins that are new for the user, that come from unusual IPs or countries, or that are followed by mailbox access from unfamiliar infrastructure:

let lookback = 30d;
SigninLogs
| where TimeGenerated > ago(lookback)
| where AuthenticationProtocol == "deviceCode" and ResultType == 0
| project TimeGenerated, UserPrincipalName, IPAddress,
          Country = tostring(LocationDetails.countryOrRegion),
          AppDisplayName, UserAgent, CorrelationId
| join kind=leftanti (
    SigninLogs
    | where TimeGenerated between (ago(90d) .. ago(lookback))
    | where AuthenticationProtocol == "deviceCode"
    | distinct UserPrincipalName
  ) on UserPrincipalName
| order by TimeGenerated desc

This lists users whose first device-code sign-in happened in the last 30 days. Check each one with the user. If a sign-in was not theirs:

# Invalidate all refresh tokens and session cookies for the user
Revoke-MgUserSignInSession -UserId "user@contoso.com"

Then reset the password, check for new MFA methods and inbox rules, review OAuth consents, and look for devices registered in the account's name. With protocol tracking, Entra also marks sessions that began with device code flow, and later refreshes in those sessions are blocked once the policy is on.

Verification

Troubleshooting

Wrapping Up

Device code phishing works because nothing on the page looks fake, so training users to spot bad pages won't stop it. Removing the flow does. Measure first, run report-only, enforce with a small, reviewed exception list, then hunt back through the last month for tokens that were already taken. In most tenants this takes under an hour of work and leaves current device-code phishing kits with nothing to use.

COMPUTE NODE · · --:--:--

Fresh cybersecurity news,
daily threat intelligence.

Daily cyber news, live threat intel and exploited CVEs.

Everything in one place

Self-hosted, hardened, and yours.

RUN IT

Local AI console

Chat with a model on your own hardware via Ollama or any OpenAI-compatible server. No cloud, no key.

DEFEND

Cyber threat feed

Automatic daily intel from CISA KEV, NVD & GitHub advisories, a live cyber threat map, and your own notes.

NEWS

News & videos

Articles and updates on pentesting, AI, and cyber — with embedded video, including YouTube. Post your own.

DIRECTORY

Registry

Runtimes, models, MCP servers, agents, and a full security & pentest tooling section.

PUBLISH

Posts

Write, edit, publish, and share articles backed by a real database and your account.

COMMUNITY

Forum

Threads and replies across categories from Models to Hardware to Security.

CODE

Repos

Curated AI and security GitHub repos, plus a shelf for pinning your own.

DOWNLOAD

Skill packs

Agent starters, RAG scaffolds, and defensive security & VAPT report templates.

Registry

Runtimes, models, MCP servers, agent frameworks, and a security & pentest tooling section — all links out to the real projects.

Local AI console

Talk to a model running on your own machine through Ollama or an OpenAI-compatible server — your prompts and the model's replies always go straight from your browser to your local model, never through a Reef server. Attach files for context, and pick up saved chats where you left off.

Type /image a prompt in the box below to generate
Not connected

Local AI hardware benchmark

A spec-based compatibility advisor — tells you which local models your hardware can run well, which will be slow, and which to skip. Connect to Ollama below for a real, measured speed test instead of an estimate.

1. Your hardware

2. Live check against your local model server (optional)

If a local model server is running, this cross-references the table above with what you've actually got loaded — and runs a real, measured speed test instead of an estimate.

AI Database

A browsable catalog of AI models across providers — context windows, pricing, and capabilities.

Loading…

Cyber threat feed

Latest threats pulled automatically every day from CISA's Known-Exploited-Vulnerabilities catalog and NVD — plus threat intel you post yourself.

⇩ Export STIX
Loading threat feed…

Cyber threat map

Attacks happening right now, all over the world.

Connecting…
LIVE · MAURITIUS TIME--:--:--
attack route, country to country attack route into Mauritius attacker reported worldwide
Loading live data…
attackers reported per minute · click to rewindnow

Top attack routesweb

Attackers based inlast hour

Networkslast hour

Click any dot, feed row or table row to see that IP's profile.

Mauritius

Who attacks Mauritius

Loading…

Web attacks malicious requests to Mauritian websites that were blocked
Network DDoS floods meant to knock Mauritian servers offline

    Mauritius · last 24 h

    How Mauritius is attacked

    Network-level attacks (DDoS) aimed at Mauritius, by method. They try to knock servers and networks offline by sheer volume.

    • Loading…

    The ports or services these floods aimed at aren't published.

    Mauritius · last hour

    Attackers located in Mauritius

    0attackers located in Mauritius were reported in the last hour

    This counts attacks coming from Mauritius, not attacks on it: IPs in Mauritius that servers elsewhere reported for attacking them. Usually zero or one; when it rises, it's often a hacked local server or router.

    Worldwide today

    What attackers are knocking on

    Ports most targeted across a worldwide network of sensors .

    Worldwide today

    Most active attackers

    Ranked by how many separate sensors they hit. Click a row for its profile.

    IPCountryNetworkSensors hitReports
    What you're looking at
    Blue routes

    Share of attack traffic from one country to another. Thicker, faster streams carry more. Particles show volume, not one per attack.

    Every 15 min · published 1–2 h behind
    Amber flashes

    An attacking IP that servers around the world reported in the last minute, placed where the IP is. Its targets aren't published, so there's no line.

    Every minute · shown about 1 min behind
    Locations

    IP locations are approximate (city level at best) and show where the machine is hosted, not who controls it.

    Approximate · city level at best

    News

    Articles, guides and updates on pentesting, AI, and cybersecurity — with embedded video. Add your own, including YouTube.

    Loading…

    Posts

    Loading…

    Loading posts…

    Forum

    Questions, answers, and talk about running AI locally.

    Loading forum…

    GitHub repositories

    Curated AI and security repos, plus your own pinned shelf.

    Command board

    One-liners, configs, and advice worth keeping — shared by everyone here.

    ⚠ Commands are shared with all users. Never include credentials, tokens, or internal hostnames. Review anything before you run it.
    Loading commands…

    Skill packs

    Starter files served from the API — AI agent scaffolds plus defensive security & VAPT reporting templates. Click to download.

    Loading skills…

    Threat Library

    Threat actors, malware and tools — their attack techniques, Reef Sentinel coverage and indicators of compromise.

    Loading…

    Threat Intelligence

    Curated threat write-ups, advisories and analysis — with cover media.

    Loading…

    Tutorials

    Step-by-step guides for running local AI, using the console, and tracking threats. Admins can add their own.

    Loading…

    Downloads

    Direct links to the official homepage/download page for well-known cybersecurity, penetration-testing, and local-AI software. Always verify checksums/signatures from the vendor before running anything.

    Loading…

    Terms & Conditions

    Loading…

    Help & FAQ

    Answers to common questions about Reef Sentinel, plus a formatting guide for posts, articles, and comments.


    Formatting guide

    Commands you can type into the body of a post, comment, or reply — no HTML needed. Comments and short replies only support bold, italic, and inline code.

    Contact us

    Questions, feedback, or a security disclosure? Reach us directly, or send a message and we'll get back to you by email.

    Loading…

    Send a message

    VAPT Report Generator

    Build an engagement, add findings with a live CVSS calculator, and generate a branded, print-ready report.

    Recon Toolkit

    Passive OSINT lookups for the recon phase of an engagement, plus offline hash identification and a payload cheatsheet.

    Website Checker

    Reads a website's HTTP response headers to identify its framework and server, shows any known CVEs for the exposed versions with details, and recommends what to do.

    Control panel

    Manage everything shown on the site — news & videos, posts, homepage headlines, and subscribers. Admin only.

    Overview
    Content
    Site
    Account & Security

    Email settings

    SMTP on ports 25/465/587 is blocked outbound by some hosts (e.g. DigitalOcean droplets by default) — Resend and Brevo send over their HTTPS API instead, so they work even then. Only the selected provider is used to send; the others stay saved but idle, so you can switch back any time without losing settings.

    Get a key from resend.com/api-keys. Uses the "From address" below as the sender — it must be on a domain you've verified with Resend.

    Get an API key (not an SMTP key) from app.brevo.com/settings/keys/api. Uses the "From address" below as the sender — it must be a verified sender in your Brevo account.

    "From address" and "Site name/URL" are shared by SMTP, Resend, and Brevo — they control what recipients see, regardless of which provider is active.

    Send a test email

    Sends through whichever provider is currently active above. Save your settings first if you just changed them.