Microsoft Defender AI agent runtime protection, part 8: what Agent 365 can see on your endpoints

Part 8: what Agent 365 can see on your endpoints
Part 8: what Agent 365 can see on your endpoints

Part 8: what Agent 365 can see on your endpoints

In the previous part: Part 7 blocked a user who ran an unapproved local AI agent, using only Microsoft 365 E5 parts, and parked Microsoft’s own Agent 365 route because the lab had no licence.

Employees are installing AI agents on their laptops faster than most security teams can list them: desktop assistants, coding agents in the terminal, local model runners. Microsoft’s answer is Agent 365 and its new Shadow AI page in the Microsoft 365 admin center. This part adds an Agent 365 licence to the lab and asks a simple question: what does Agent 365 actually see on a Windows endpoint, and what does it miss? Part 9 covers what it can block.

Short version

The Shadow AI page (Frontier preview) checks for 20 desktop AI agent platforms. It detected Claude Desktop on the lab device less than an hour after a test user signed in to it, and it did that for a user with no Agent 365 licence.

Command-line agents, which run in a terminal, and IDE agents, which run inside a code editor such as VS Code or Cursor, sit on a different page: All agents > Local agents catalogues 40 more, and it picked up Claude Code, Gemini CLI and two VS Code extensions on the lab device. That is 60 agents with visibility, against six with runtime protection in Parts 1-4. Visibility is not protection.

The lab

ItemDetail
TenantContoso lab tenant with Microsoft 365 E5
DeviceWindows 11 VM, Entra joined, Intune enrolled, onboarded to Defender for Endpoint (the same device as Parts 2-7)
UsersTwo new test users, both Microsoft 365 E5. agent-approved also has an Agent 365 licence. agent-unapproved does not. Admin account excluded from every policy.
Licences added for this partOne Microsoft 365 Copilot licence (needed for the Frontier programme) and one Agent 365 licence
Preview programmeCopilot Frontier, scoped to the admin account only

Turn on Frontier for one admin, not the whole tenant

Shadow AI is a Frontier preview. Frontier needs at least one Microsoft 365 Copilot licence in the tenant, and it is switched on in the Microsoft 365 admin center under Copilot > Settings > Copilot Frontier. The pane is now titled Release preferences.

Lessons learned: Frontier defaults to All users

When you switch Turn on Frontier to On, the scope defaults to All users, who then receive Frontier features and agents automatically. Select Specific users and groups before you save. In a shared or production tenant that is the difference between one admin testing a preview and everyone getting it.

Copilot Frontier release preferences scoped to specific users and groups
Frontier on, scoped to one admin account

Within an hour, a new Shadow AI item appeared under Agents in the admin center navigation.

The Shadow AI page: 20 desktop agents, zero detected

Agents > Shadow AI lists the AI agent platforms Microsoft can detect on managed Windows devices, with a status, publisher, instance count and last-detected date for each. Before any test user touched an agent, all 20 showed Not detected.

Shadow AI page in the Microsoft 365 admin center showing 0 detected and 20 not detected agent platforms
The baseline: 20 platforms, none detected

The 20 platforms on the list in December 2026:

PublisherPlatforms
AnthropicClaude Desktop
OpenAIChatGPT Desktop, ChatGPT Classic, Codex Desktop
GoogleAntigravity Desktop
Local model runnersOllama Desktop, LM Studio, LM Studio Bionic
Agent frameworksOpenClaw, ZeroClaw, QClaw (Tencent), Nanobot, Goose Desktop, Hermes Agent
OtherDevin Desktop, Perplexity Desktop, Poe Desktop, Grok Bot, Qwen Studio, CoCo Desktop (Snowflake)

Compare that with Part 1. Runtime protection, the feature that inspects prompts and blocks injection, covers six agents. Shadow AI can see 20. Visibility has more than tripled. Protection has not changed.

A banner on the page reads “Unlock more control over shadow AI with Agent 365”. Detection works with Frontier alone. The banner disappeared once the Agent 365 licence was assigned.

What the Agent 365 licence adds

The standalone Agent 365 licence is assigned per user, like any other Microsoft 365 licence. Assigning it to one user unlocked the Agents at risk card on Agents > Overview straight away. No separate terms of service prompt appeared.

Agent 365 overview with the Agents at risk card unlocked
Agents at risk unlocked after one licence was assigned

The licence bundles 14 service plans. Three matter for this series:

  • Defender For AI
  • Entra Conditional Access for Agents
  • Entra ID Protection for Agents

The rest extend Purview (audit, communication compliance, Compliance Manager, data lifecycle management, data loss prevention, information protection, insider risk management, eDiscovery) and Entra (ID Governance and network controls for assistive agents) to agents. Part 9 tests the three above.

Agent 365 licence assignment showing the included apps and services
The 14 service plans in the Agent 365 licence

Run a desktop agent as an unlicensed user

The test user without an Agent 365 licence, agent-unapproved, signed in to the lab device and opened Claude Desktop. Within an hour Shadow AI showed Claude Desktop: Detected, 1 instance.

Shadow AI page showing Claude Desktop detected with one instance
Claude Desktop detected, under an hour after first use

Two things stand out. First, the user had no Agent 365 licence, so detection is a tenant and device capability, not a per-user one. Second, detection relies on Defender for Endpoint. Microsoft’s documentation describes the Last Seen field as the last time Defender detected the agent on the device, so a device that is not onboarded to Defender is invisible to Shadow AI.

Lessons learned: The count arrives before the detail

When the list first showed one instance, the agent’s Instances tab still said No instances found. The headline count and the per-device detail update separately. Give it time before concluding a detection has no device or user attached.

Selecting the agent opens a detail pane with four tabs: Details (first used, last detected), Instances (the user, agent and device combination), Access and Activity. The Access tab is where blocking lives, which is Part 9.

Command-line agents live on a different page

Every platform on the Shadow AI list is a desktop app or a local model runner. Claude Code, Gemini CLI and GitHub Copilot CLI are not on it. They are not missing, though. They sit under Agents > All agents > Local agents, a tab next to the registry that catalogues 40 command-line and IDE agents: Claude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI, Cursor, Windsurf, Kiro, Cline, Roo Code and the VS Code extensions for several of them.

In plain terms

An IDE (integrated development environment) is the code editor a developer works in, such as VS Code, Cursor or Windsurf. IDE agents are AI coding assistants built into those editors or added as extensions, such as GitHub Copilot or the Claude Code extension for VS Code. They read and change code in the project the developer has open, the same way a command-line agent does from a terminal.

Agent 365 All agents Local agents tab showing Gemini CLI, Claude Code and two VS Code extensions detected
Local agents: the CLI and IDE catalogue, with four detected on the lab device

Lessons learned: Two pages, two catalogues

Shadow AI covers 20 desktop platforms. Local agents covers 40 CLI and IDE agents. Neither page links to the other, and Claude Desktop appears only on the first while Claude Code appears only on the second. Check both before you tell anyone what Agent 365 found.

Defender saw the CLI agents too, and faster. When agent-unapproved launched Gemini CLI from PowerShell, the Part 7 near-real-time custom detection, which matches node.exe running a known agent CLI, raised a High alert within a minute and marked the user as compromised. Agent 365 reported the same agent later, as an inventory entry with no alert.

Defender advanced hunting AgentsInfo results showing command-line agents
Defender’s AgentsInfo table records the same CLI agents per user

In plain terms

Agent 365 gives you an inventory: which agents are on which devices. Defender gives you events and alerts: which processes ran, when, and what they did. A developer working entirely in the terminal shows up on the Local agents tab, not on the Shadow AI page, and only Defender raises an alert about it.

Sign-ins Microsoft never sees

Gemini CLI first offered a Google sign-in. Google authenticated the account, then refused it: personal accounts are “no longer supported for Gemini Code Assist for individuals”, and the message pointed to Google’s Antigravity suite instead. Antigravity Desktop is one of the 20 platforms on the Shadow AI list, so the vendor is moving users from a tool Shadow AI cannot see to one it can.

The alternative route is an API key from Google AI Studio, pasted into an environment variable.

Google AI Studio API keys page
An API key is all a CLI agent needs

Neither the Google sign-in nor the API key passes through Microsoft Entra. Claude Desktop and Claude Code sign in to Anthropic in the same way. That matters for Part 9: Conditional Access can only evaluate sign-ins it sees.

Licensed v unlicensed user

Both test users ran agents on the same device: agent-approved, with an Agent 365 licence, ran Claude Code; agent-unapproved, without one, ran Claude Desktop, Claude Code and Gemini CLI.

WhereLicensed userUnlicensed user
Shadow AI and Local agentsAgent countedAgents counted. The pages show agents and instance counts, not which user is licensed.
Agents at risk00
Defender AgentsInfo, EntraAgentID columnPopulated for Claude CodePopulated for Claude Desktop and Gemini CLI, empty for Claude Code

There is no consistent licence effect on what Agent 365 or Defender can see. Endpoint discovery is a tenant and device capability. The per-user licence matters for what you can do with an agent identity, which is Part 9.

Where the documentation is behind

Microsoft’s Shadow AI article was last updated on 23 October 2026. The lab tenant on 4 December 2026 already differs from it:

TopicLearn (23 Oct 2026)Lab (4 Dec 2026)
PlatformsSeven agents for detection, OpenClaw only for blocking20 desktop platforms on Shadow AI plus 40 CLI and IDE agents on Local agents; Claude Desktop and Claude Code both offer a block
BlockingCreates an Intune policy named A365 - Block OpenClaw for all managed Windows devicesApp Control for Business policy, scoped to Entra device groups, behind a readiness check (Part 9)
Licence to viewMicrosoft 365 E5Worked with E5 and Frontier; no Agent 365 licence needed for detection

This is a preview, and these differences will move. Check the tenant, not the article.

What worked, what didn’t

TestResult
Frontier scoped to one adminWorked. Shadow AI appeared within the hour.
Baseline Shadow AI20 platforms, 0 detected
Claude Desktop as an unlicensed userDetected in under an hour
Instance detailLagged behind the count
Licensed v unlicensed userNo difference in what was detected
Gemini CLI and Claude CodeNot on the Shadow AI page; detected under All agents > Local agents. Defender (Part 7 detection) alerted on Gemini CLI within a minute.
Agent 365 licenceUnlocked Agents at risk immediately; no terms prompt

Before you use this in production

  • Shadow AI is a Frontier preview. Behaviour, the platform list and blocking will change.
  • Scope Frontier to named admins first. The default is everyone.
  • Detection needs Defender for Endpoint on the device and Intune enrolment. Unmanaged and personal devices are out of scope.
  • Global Secure Access adds traffic metadata (endpoints, requests, data sent) to the detail pane. Without it several tiles stay empty.
  • Check both Shadow AI and All agents > Local agents. Neither alerts, so keep a Defender detection for CLI agents, such as the Part 7 rules, if you need to act quickly.
  • Knowing which employee runs which AI tool is personal data. Agree the purpose with HR and your data protection officer before you start acting on it.

Licensing

CapabilityWhat it needed in this lab
Copilot FrontierAt least one Microsoft 365 Copilot licence in the tenant
Shadow AI detectionFrontier, Microsoft 365 E5 (Defender for Endpoint, Intune)
Agents at risk, Agent 365 service plansAgent 365 licence (per user), or Microsoft 365 E7
Defender detection of CLI agentsDefender for Endpoint Plan 2 (in E5) and a custom detection

Next in the series

Part 9 asks the harder question: can Agent 365 actually stop the agent it just found? It tests the App Control block on the Shadow AI page, Conditional Access for agents, Entra Agent ID and agent risk, and compares Microsoft’s route with the E5 route from Part 7.

The detections used in this part are in the defender-ai-agent-runtime-protection repo on GitHub.

Microsoft documentation used

Microsoft Defender AI agent runtime protection, part 7: from Defender detection to a Conditional Access block

Part 7 - from Defender detection to a Conditional Access block
Part 7 - from Defender detection to a Conditional Access block

In the previous part: we moved AI agent governance from Defender into Agent 365 - one inventory of agents, their owners and the controls that come with agent identities.

Parts 1 to 6 were about seeing local AI agents, controlling what they connect to and governing them in Agent 365. Part 7 asks the next question: when someone runs an agent you have not approved, can you stop them signing in? At Ignite 2026 Microsoft announced a chain for exactly that - Entra Agent ID for local agents, an Intune compliance setting for unapproved agents, and a Conditional Access block. Most write-ups so far summarise the announcement. This post tests it in a lab and reports what actually happened.

Short version: the Microsoft-native route needs Agent 365, which this E5 lab does not have. So I built the chain from E5 parts. The device-compliance route stalled. The identity route worked end to end, from an unapproved agent launching to the user being blocked at sign-in.

The lab

  • One onboarded Windows 11 VM, purview, used throughout the series.
  • Test user edge: Microsoft 365 E5, no Entra roles, local admin on the VM.
  • The admin account is excluded from every policy in this post, so a noncompliant lab device can never lock out the admin.
  • Approved agents: Claude Code (CLI and VS Code), Claude Desktop and GitHub Copilot (CLI and VS Code). Anything else is unapproved - block-all by default, as in Part 5.
  • The unapproved test agent: Gemini CLI, installed by edge with npm.

Before testing, the VM carried 31 alerts from earlier parts of the series, which left it at High device risk. I closed those as Benign Positive - Security Testing and dismissed the user risk, so every result below starts from a clean baseline.

What Defender already knows

Advanced hunting against AgentsInfo shows six local agents discovered on purview: Claude Code, the Claude Code and GitHub Copilot VS Code extensions, GitHub Copilot CLI, Claude Desktop and Gemini CLI.

AgentsInfo
| where Timestamp > ago(30d)
| where Platform == "LocalAgents"
| summarize arg_max(Timestamp, *) by Name
| project Timestamp, Name, Version, AgentId
AgentsInfo - six local agents discovered on the lab VM
AgentsInfo - six local agents discovered on the lab VM

The table now has an EntraAgentID column, which was not there when Part 3 was written. That is where the Ignite preview records the Entra identity given to a discovered local agent. In this lab it is empty for every agent, and Entra ID > Agents > Overview agrees: no agent identities. Every action these agents take is still recorded against the signed-in user. Keep that in mind - it decides which Conditional Access policy can stop them.

Baseline - EntraAgentID is empty for every local agent
Baseline - EntraAgentID is empty for every local agent

Route A: Microsoft’s agent compliance setting

The announced Intune setting marks a device noncompliant when it runs an unapproved local agent. In an E5 tenant without Agent 365 it does not appear. Creating a Windows 10 and later compliance policy offers only the classic policy and an empty Templates list. The new Agents node in Intune is for Security Copilot agents, not local AI agents.

Intune compliance - no agent-specific profile type without Agent 365
Intune compliance - no agent-specific profile type without Agent 365

So Route A is out for most E5 customers today. The rest of this post is Route B: the same outcome built from parts you already own.

Route B, step 1: detect the unapproved agent

The scheduled rule

AgentsInfo has no DeviceId column. The device, user and vendor sit inside RawAgentInfo.localAgentMetadata, so the query pulls them out to give the detection the entities it needs.

// Detect-UnapprovedLocalAgent.kql
// cloud-secure.ai - Defender AI agent runtime protection, Part 7
// Raises an alert when Defender discovers a local AI agent that is not on the approved list.
// AgentsInfo has no DeviceId column - the device and user live in RawAgentInfo.localAgentMetadata.
// Block-all-by-default: anything not in ApprovedAgents alerts.
// Matches on name fragments: "Claude Code" also covers the VS Code Claude extension, "GitHub Copilot" covers CLI and VS Code.
let ApprovedAgents = dynamic(["Claude Code", "Claude Desktop", "GitHub Copilot"]);
AgentsInfo
| where Timestamp > ago(4h)
| where Platform == "LocalAgents"
| where not(Name has_any (ApprovedAgents))
| extend Meta = RawAgentInfo.localAgentMetadata
| extend DeviceId    = tostring(Meta.machineId),
         DeviceName  = tostring(Meta.deviceName),
         AccountUpn  = tostring(Meta.upn),
         AccountSid  = tostring(Meta.accountSid),
         Vendor      = tostring(Meta.vendor)
| summarize arg_max(Timestamp, *) by DeviceId, Name
| project Timestamp, DeviceId, DeviceName, AccountUpn, AccountSid,
          AgentName = Name, Vendor, Version, ReportId = tostring(AgentId)

Saved as a custom detection: every hour, High severity, entities mapped to Device (DeviceId) and User (AccountSid). Two gotchas from the rule wizard:

  • The alert description takes a maximum of three dynamic columns. Five were rejected with “Too many column names”.
  • A new rule queries 30 days on its first run. Without the ago(4h) filter inside the query, it would alert immediately on old discoveries.
The first-run warning - keep a time filter in the query
The first-run warning - keep a time filter in the query

Why one rule was not enough

AgentsInfo is a periodic inventory, not a live feed. In the lab its last report was hours old. And searching process events for “gemini” found nothing, because npm-installed agent CLIs run as node.exe - the agent name only appears in the command line. So I added a near-real-time (NRT) rule on DeviceProcessEvents:

DeviceProcessEvents
| where FileName =~ "node.exe"
| where ProcessCommandLine has "gemini-cli" or ProcessCommandLine has "@openai" or ProcessCommandLine has "qwen-code"
| project Timestamp, DeviceId, DeviceName, AccountName, AccountSid, InitiatingProcessAccountUpn, InitiatingProcessAccountObjectId, ProcessCommandLine, InitiatingProcessFileName, ReportId

The Continuous (NRT) option stayed greyed out until the query was this simple. NRT rules reject let, dynamic(), has_any, column renames and even comments, so the notes live in a README alongside the query in the repo.

The NRT rule - Continuous frequency
The NRT rule - Continuous frequency

Route B, step 2: the device route

The plan: a High alert raises the device risk, Intune marks the device noncompliant, and Conditional Access requires a compliant device.

The connector switch that is easy to miss

Intune only receives Defender’s device risk if, under Endpoint security > Microsoft Defender for Endpoint, Connect Windows devices version 10.0.15063 and above is switched on for compliance policy evaluation. In the lab it was off. With it off, a machine risk score setting silently does nothing. It is tenant-wide, so check the impact before switching it on.

Before - the Windows compliance connection switched off
Before - the Windows compliance connection switched off

Compliance policy and Conditional Access

A Windows compliance policy requiring a machine risk score at or under Low, marking the device noncompliant immediately. One lesson: I first assigned it to a user group containing edge, and it applied to zero devices. User-targeted compliance follows the device’s primary user, which on this VM is the admin. Compliance is a device state, so it now targets a device group containing only purview.

The Conditional Access policy targets the user: edge only, admin excluded, All resources, grant Require device to be marked as compliant, created in Report-only and then switched on. The Users pane now states that user policies apply when users access resources directly or through agents acting on their behalf - exactly the case for a local agent with no identity of its own. The new All agent resources option is for agent identities and needs Agent 365.

Conditional Access - user policies cover agents acting on the user's behalf
Conditional Access - user policies cover agents acting on the user’s behalf

Result: the device route stalled

edge installed Gemini CLI with npm and ran it. The NRT rule fired as High alerts within minutes, and Defender correlated them into one incident. The attack graph tells the story at a glance: the device, the user and the processes that triggered the alerts.

Attack graph - the lab device, the user and the agent processes, four High alerts
Attack graph - the lab device, the user and the agent processes, four High alerts

Drilling into the processes node shows why the NRT rule matches on the command line: both are node.exe, launched from edge’s npm folder. Nothing in the process name says Gemini.

Processes node - node.exe running from the user's npm folder
Processes node - node.exe running from the user’s npm folder

But the device risk level did not move: it was still None more than 30 minutes later.

Two High alerts, device risk still None
Two High alerts, device risk still None

Custom detection alerts did not feed device risk in this lab, so the device never became noncompliant and the compliant-device policy had nothing to act on. If you are planning this route, test it in your own tenant before relying on it.

Route B, step 3: the identity route

Since the agent acts as the user, the user is the better place to apply the control. Custom detections have a response action, Mark user as compromised, which sets the user’s Entra risk to High. Conditional Access can block on that.

The action stays greyed out until the query returns an Entra object ID. Adding InitiatingProcessAccountObjectId to the NRT query and mapping User > AadUserId to it unlocks it.

NRT rule - Mark user as compromised
NRT rule - Mark user as compromised

Then a second Conditional Access policy: edge, admin excluded, condition user risk High, grant Block access.

Conditional Access - user risk High
Conditional Access - user risk High

Result: blocked

edge ran Gemini CLI again. The NRT rule fired, ID Protection showed edge as Confirmed compromised with High risk, and the next sign-in was refused.

ID Protection - edge confirmed compromised, risk High
ID Protection - edge confirmed compromised, risk High
The end of the chain - sign-in blocked for an at-risk user
The end of the chain - sign-in blocked for an at-risk user

What worked, what didn’t

Link in the chainRoute A (Microsoft native)Route B (built from E5)
Detect the agentDefender local agent discoveryScheduled AgentsInfo rule plus NRT process rule - worked
Agent identityEntra Agent ID - needs Agent 365Not used; the agent acts as the user
Mark it riskyIntune agent compliance setting - not availableDevice risk: did not move. User risk via Mark user as compromised: worked
BlockAgent CA templates - need Agent 365CA user risk High → Block access - worked

Before you use this in production

  • It is a blunt instrument. Marking a user compromised blocks them everywhere, not just the agent. Running an unapproved CLI is a policy breach, not proof of compromise. Scope it to high-sensitivity groups, and have a fast path for an admin to dismiss the risk.
  • Keep the approved list current. Anything not on it is treated as unapproved, including a new version that reports a different name.
  • Exclude your admins from both policies, and start in Report-only.
  • Check the connector switch before trusting any machine risk compliance setting.

Licensing

  • Local agent discovery and custom detections: Defender for Endpoint P2.
  • Mark user as compromised and user risk in Conditional Access: Entra ID P2 (included in E5).
  • Compliance policy and compliant-device Conditional Access: Intune and Entra ID P1.
  • Entra Agent ID for local agents, the Intune agent compliance setting and the agent Conditional Access templates: Agent 365 or Microsoft 365 E7.

Next in the series

Next in the series: Part 8 looks at Route A properly - automatic Entra Agent IDs for local agents and the agent Conditional Access templates - and what changes when an agent gets an identity of its own.

The detection queries and the NRT README are in the GitHub repo for this series.

Contained isn’t clean, Part 1: why containment is only half the job

Contained isn't clean - Part 1 - The problem

Part 1 of 4 - The problem

Disclaimer and scope. The goal of this series is to demonstrate Microsoft Defender automatic attack disruption: how malicious activity in a Microsoft 365 tenant is detected and defended against automatically, and why containment must be followed by removing the footholds an attacker leaves behind. Everything shown was carried out in an isolated lab tenant built for the purpose. The techniques are well-documented adversary behaviours catalogued in MITRE ATT&CK, reproduced here only to show how a defender detects, disrupts and eradicates them. This process and the associated scripts are for simulation and defensive testing in a tenant you own and control. Do not use them against any environment you are not authorised to test. Planting these footholds requires privileged access in the first place - the controls described in this series are what stop a real attacker reaching that point, and what clean up if one does.

Introduction

Microsoft Defender can lock down a compromised account within minutes of an attack starting, with no analyst in the loop. That is a genuine step change. But stopping an attack and cleaning up after it are two different jobs, and the gap between them is where a lot of organisations get caught out.

Incident response has always separated the two: containment stops the attacker spreading, eradication removes everything they left behind, and recovery brings the business back online. Skip the middle step and the first person to re-enable the account quietly reopens the door.

This series builds that scenario end to end in a lab. The noisy endpoint route is blocked by Defender straight away, so the attacker does what a real adversary-in-the-middle attacker does - works entirely in the identity plane from a stolen session, leaves four footholds in Entra ID and Exchange Online, and gets contained. Then we prove the footholds survive containment, hunt them down, and remove them without touching anything the real user still needs. This first part sets up the problem and shows Defender’s automatic response doing its job.

How Defender responds on its own

Automatic attack disruption

Automatic attack disruption correlates signals across endpoints, identities, email and SaaS apps, identifies the assets the attacker controls, and contains them by disabling users, revoking sessions or containing devices. Microsoft states that containment actions run at a confidence level of 99% or higher, and every automatic action can be undone by the SOC.

Predictive shielding

Predictive shielding extends attack disruption by acting before the attacker uses stolen credentials. When Defender sees high-confidence signs of credential theft on a device, it can restrict the accounts likely exposed there. It is available to Defender for Endpoint P2 customers who meet the prerequisites, and Microsoft recommends the Defender for Identity sensor to enrich its data.

Gotcha: in the incident Activities tab, the Performed by column shows Attack Disruption for both attack disruption and predictive shielding actions. Filter incidents by the Predictive Shielding tag to tell them apart.

The gap: what containment leaves behind

Attackers who get in through a phished or stolen session move quickly to make sure they can get back in. These are the footholds the lab recreates, and none of them is removed by disabling the user or revoking their sessions:

Foothold MITRE ATT&CK Why containment does not remove it
Attacker-registered MFA methodT1098.005 Device RegistrationDisabling the account and revoking sessions leaves registered methods in place. Re-enable the user and the attacker can pass MFA again.
Directory role added to the userT1098.003 Additional Cloud RolesThe role assignment stays on the account and comes back into use the moment the account is enabled.
Client secret added to an appT1098.001 Additional Cloud CredentialsThe secret belongs to the app, not the user. Disabling the user does nothing to it, so the attacker keeps signing in as the app.
Hidden inbox ruleT1564.008 Email Hiding RulesThe rule lives in the mailbox and keeps running whether the user can sign in or not.

Stage 1 - The loud route is blocked

The lab first tried the obvious way in: endpoint tooling on the lab VM to dump credentials from memory. Microsoft Defender Antivirus quarantined it on sight. A Meterpreter variant, a hack-tool, a credential-injection trojan and a PowerShell offensive-tooling detection were all flagged Severe or High the moment they landed, before anything could touch LSASS.

Defender Antivirus - multiple threat families found and quarantined on the endpoint.
Defender Antivirus - multiple threat families found and quarantined on the endpoint.

That is defence in depth doing its job, and it is the point worth making: the malware-heavy route is the one your controls are best at catching. Defender correlated the detections into a single incident and drew the attack graph automatically.

The incident attack graph: the device linked to the quarantined tooling, with the threat families named.
The incident attack graph: the device linked to the quarantined tooling, with the threat families named.

It is not how a capable identity attacker operates today.

Impair Defenses (T1562)

Before the credential dump even ran, Controlled Folder Access blocked the tooling from writing to protected folders. That is the control doing its job: against unprivileged ransomware, the common case it is built for, it holds.

Getting past it is not free. Adding an allowed application or changing the mode needs local admin, and weakening or turning off a security control is itself an attack technique - T1562 Impair Defenses - and one of the behaviours Defender treats as high value. The action is loud: it writes to DeviceEvents, and tampering like this can feed attack disruption. So the first thing the attacker meets is a control that blocks them, and the only way past hands the defender more signal.

Gotcha: if you do allow an application through Controlled Folder Access, never allow an interpreter such as powershell.exe - anything that can invoke it inherits the pass. Allow specific signed binaries only.

Hunt Controlled Folder Access violations and Defender tampering:

DeviceEvents
| where Timestamp > ago(1d)
| where ActionType in ("ControlledFolderAccessViolationBlocked",
    "ControlledFolderAccessViolationAudited", "TamperingAttempt")
| project Timestamp, DeviceName, ActionType, InitiatingProcessFileName,
    FolderPath, AdditionalFields

Next in the series: Part 2 stages the attack in the lab and plants the four footholds in the identity plane.

Contained isn’t clean, Part 2: staging the attack

Contained isn't clean - Part 2 - Staging the attack

Part 2 of 4 - The lab and the footholds

In the previous part: Defender’s automatic attack disruption and predictive shielding contain a compromised account, but the footholds an attacker leaves behind are a separate problem. The obvious endpoint route was blocked by antivirus, so the attack moves to the identity plane.

The lab

Everything runs in a dedicated Contoso test tenant:

  • Victim user: a licensed Microsoft 365 E5 account (the compromised user) with its own Authenticator registered
  • Second compromised account: an over-privileged helpdesk account holding Privileged Role Administrator and Application Administrator - more privilege than a helpdesk needs, which is exactly what attackers look for
  • Victim device: an Entra joined Windows 11 VM onboarded to Defender for Endpoint, signed in as the victim user
  • Attacker: a separate browser on a different public IP, using the stolen session

Prerequisites

  • Microsoft 365 E5 or A5, or Defender for Office 365 Plan 2 plus Defender for Endpoint P2
  • Defender for Endpoint device discovery set to Standard
  • The VM’s device group set to an automation level that lets disruption act without approval
  • Mailbox auditing on, including UpdateInboxRules
  • The test user not excluded from automated response (Settings > Microsoft Defender XDR > Identity automated response)
  • Microsoft 365 app connector in Defender for Cloud Apps, with Entra ID management events, Entra ID sign-in events, Entra ID apps and Microsoft 365 activities all ticked

Gotcha: the Microsoft 365 connector can show as Connected while only Entra users and groups is ticked. In that state CloudAppEvents stays empty and the hunting queries in Part 4 return nothing. Open the connector’s Edit settings and tick the event sources before you need them - it takes a few hours for data to start flowing.

The attacker changes tack: the identity plane

An adversary-in-the-middle attack needs no endpoint malware at all. The attacker phishes the user through a proxy, captures the session token once the user has completed MFA, and replays it. From that point they are the user, in a browser, with nothing on the device for antivirus to see. Everything that follows happens in Entra ID and Exchange Online.

Where predictive shielding fits: predictive shielding acts when Defender sees high-confidence credential theft on a device, restricting the accounts likely exposed there. In this run the endpoint tooling never executed, so that signal is never raised. That is precisely why the identity-plane footholds matter - there was no noisy on-device event to trip it.

The four footholds

With the stolen session, the attacker plants persistence. Two are done as the victim, two through the compromised helpdesk account. The planting steps are described here so the lab can be reproduced; the public companion repository ships only the detection and removal tooling.

As the victim user

  • Register a second Microsoft Authenticator (or software OATH) method, so the attacker holds a valid MFA method of their own (T1098.005). In the lab this is done through the My Sign-ins page; it registers as a new method with its own id.
  • Create an inbox rule that moves mail containing “invoice” or “payment” to RSS Feeds and marks it read (T1564.008).

Gotcha: registering the method is not finished until the verification step completes. A half-finished enrolment - scanning the QR but not approving the test notification - leaves nothing recorded in Entra, even though the authenticator app shows the account.

Through the compromised helpdesk account

  • Add a directory role to the victim (T1098.003) - a role the helpdesk account can assign because it holds Privileged Role Administrator.
  • Add a client secret to an app registration (T1098.001), using its Application Administrator rights. The secret belongs to the app, so it survives anything done to the user.

Note: the privileged footholds can only be planted from the helpdesk account, not the victim. That split - a phished user plus an over-privileged second account - is what turns a single compromised mailbox into tenant-wide persistence.

Next in the series: Part 3 contains both accounts and proves the footholds survive.

Contained isn’t clean, Part 3: containment and the gap

Contained isn't clean - Part 3 - Containment and the gap

Part 3 of 4 - Containment, and what it leaves behind

In the previous part: The attacker has planted four footholds - a rogue MFA method and an inbox rule on the victim, and a directory role and an app secret through an over-privileged helpdesk account.

Stage 3 - Containment

Attack disruption may fire on the identity activity on its own; in a lab it often will not, because it needs a high-confidence correlated pattern. Either way the response is the same. If disruption fired, the user is already disabled with sessions revoked. If not, take the same actions by hand from the user page in the Defender or Entra portal: revoke sessions, then block sign-in. Do the same for the helpdesk account.

In this lab run, attack disruption did not fire on the identity activity and the DisruptionAndResponseEvents table stayed empty, which is the common lab outcome. The point stands either way, because the manual containment takes exactly the actions disruption would.

Both accounts showing Account status: Disabled after revoke-sessions and block-sign-in.
Both accounts showing Account status: Disabled after revoke-sessions and block-sign-in.

Stage 4 - The door left open

Here is the heart of it. With the accounts contained, look at the victim’s registered authentication methods. The account is disabled and its sessions are revoked, yet both methods are still there: the legitimate Microsoft Authenticator and the attacker’s own method, untouched.

The victim's authentication methods while the account is disabled - the attacker's method is still registered alongside the legitimate one.
The victim’s authentication methods while the account is disabled - the attacker’s method is still registered alongside the legitimate one.

Containment did exactly what it is meant to - it killed the sessions and blocked sign-in. And it did nothing to the footholds. The attacker’s MFA method is intact, the added role is still assigned, the app secret still works, and the inbox rule is still running. The moment the service desk re-enables the account to close the incident, the attacker walks straight back in.

Reinforcing the hunting approach: the Entra authentication methods page itself warns that hidden and temporary methods are not shown, and to use the Graph API to see them all. That is exactly why the hunt in Part 4 reads methods through Graph rather than trusting the portal view.

The lesson so far

  • Containment buys time. It does not make the account safe.
  • Every account in the incident matters, not just the first one. The helpdesk account did more damage than the phished user.
  • Re-enabling a contained account before removing the footholds hands the attacker their access back.

Next in the series: Part 4 hunts the footholds and eradicates them precisely, then restores the account safely.