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.

Contained isn’t clean, Part 4: hunt and eradicate

Contained isn't clean - Part 4 - Hunt and eradicate

Part 4 of 4 - Finding and removing the footholds

In the previous part: The accounts are contained, but the four footholds survived. Now we find them and remove them - the eradication step that makes re-enabling safe.

Stage 5 - Hunting the footholds

Three of the four footholds are visible in the CloudAppEvents table in Advanced hunting, each under a specific ActionType confirmed in the lab. Set the time window to match the incident.

Roles added (T1098.003)

CloudAppEvents
| where Timestamp > ago(1d)
| where ActionType == "Add member to role."
| project Timestamp, ActionType, AccountDisplayName, IPAddress, CountryCode, RawEventData
| order by Timestamp desc

App secrets added (T1098.001)

The ActionType Microsoft writes for this contains a dash, so match on the distinctive text rather than the whole string:

CloudAppEvents
| where Timestamp > ago(1d)
| where ActionType has "Certificates and secrets management"
| project Timestamp, ActionType, AccountDisplayName, IPAddress, RawEventData
| order by Timestamp desc

Inbox rules created (T1564.008)

CloudAppEvents
| where Timestamp > ago(1d)
| where ActionType in ("New-InboxRule", "Set-InboxRule", "UpdateInboxRules")
| project Timestamp, ActionType, AccountDisplayName, IPAddress, CountryCode, RawEventData
| order by Timestamp desc

All three in one query

CloudAppEvents
| where Timestamp > ago(1d)
| where ActionType in ("Add member to role.", "New-InboxRule")
    or ActionType has "Certificates and secrets management"
| project Timestamp, ActionType, AccountDisplayName, IPAddress, CountryCode
| order by Timestamp desc
The combined query returning the role, secret and inbox-rule events, with the attacker IP against the inbox rule.
The combined query returning the role, secret and inbox-rule events, with the attacker IP against the inbox rule.

Gotcha 1 - the MFA method is not here. The attacker-registered authentication method does not appear in CloudAppEvents at all; self-service registration through the My Sign-ins page is not written to that table. This is why the companion hunt reads authentication methods directly through Microsoft Graph - KQL alone would miss the MFA foothold.

Gotcha 2 - the IP is not always populated. In the lab the mailbox action (New-InboxRule) carried the attacker IP and country, but the Entra directory actions (the role and the secret) came through with an empty IPAddress. Do not rely on IP alone to scope these; correlate on the acting account and the timestamps instead.

The Graph hunt

Because the MFA method is invisible to KQL, the companion hunt script reads authentication methods, directory roles, app secrets and inbox rules straight from Microsoft Graph and Exchange Online. It surfaces the hidden and temporary methods the portal omits, and it is read-only - run it to find the footholds, then again after removal to confirm the account is clean.

Stage 6 - Removing the footholds

The aim is precision: remove what the attacker added and nothing else. Each foothold is removed by its own identifier - the authentication method id, the role assignment id, the secret key id, the inbox-rule name - so the user’s legitimate methods and settings are left untouched.

  • MFA method: delete only the method the attacker registered. Removing it by id leaves the user’s own Authenticator in place; a blanket “require re-register MFA” would wipe the legitimate method too.
  • Role: remove the added assignment, then review why the helpdesk account could assign it in the first place.
  • App secret: delete the secret by its key id, then review the app’s sign-in logs for anything it was used for.
  • Inbox rule: remove the rule, and check for forwarding set on the mailbox.

Gotcha - verify, do not trust the message. Some Graph removal cmdlets return an error that does not stop the script, so a naive script can report success when nothing was removed. The companion removal script checks the method’s real type, uses explicit error handling, and reports success only when the call actually succeeds. Always re-run the hunt afterwards.

After removal: only the user's own Authenticator remains, the attacker's method gone.
After removal: only the user’s own Authenticator remains, the attacker’s method gone.

Stage 7 - Verify and recover

  1. Re-run the hunt and confirm nothing remains - one legitimate method, no roles, no secrets, no inbox rules.
  2. Reset the password and revoke sessions once more, for the victim and the helpdesk account.
  3. Re-enable the accounts - now safe, because the footholds are gone.
  4. Confirm the attacker can no longer sign in.

Takeaways

  • Containment buys time; eradication makes the account safe. Build a post-containment checklist for MFA methods, role assignments, app credentials and mailbox rules, and run it before anyone re-enables an account.
  • Remove what the attacker added, not everything. Wiping a user’s own MFA creates a support call and a fresh social-engineering window.
  • Not every foothold is in one table. The role, secret and inbox rule are in CloudAppEvents; the MFA method is only visible through Graph.
  • Keep the hunt and removal ready as scripts, so the checklist takes minutes rather than hours.

Companion scripts

The read-only hunt and the precise removal script are on GitHub at cloud-secure-ai/attack-disruption-footholds-lab, with a README and the MITRE ATT&CK mapping. The repository is deliberately defensive: the script that plants the footholds is not included, because planting requires privileged access in any case and the published tooling is limited to detection and removal.

References