PIVTR-D
RAzure playbook · Compute and containers

Stolen managed identity tokens used off-host

An attacker runs code on a virtual machine (VM), or abuses a server-side request forgery flaw in an app on it. The attacker requests a managed identity token from http://169.254.169.254/metadata/identity/oauth2/token and replays it from their own machine. Remove the identity's role assignments first, because Azure caches its tokens for about 24 hours with no way to force a refresh, then hunt for the identity's calls from addresses the workload never uses.

Look here

LogSearch for
AADManagedIdentitySignInLogsTokens issued for new target resources: AADManagedIdentitySignInLogs | where ServicePrincipalId == "<principal-id>" | summarize count() by ResourceDisplayName, bin(TimeGenerated, 1h)
AzureActivityManagement calls by the identity from unexpected addresses: AzureActivity | where Caller == "<principal-id>" | summarize count() by CallerIpAddress, OperationNameValue
StorageBlobLogsBlob calls by the identity from unexpected addresses. The CallerIpAddress value includes the port: StorageBlobLogs | where RequesterObjectId == "<principal-id>" and AuthenticationType == "OAuth" | summarize count() by CallerIpAddress
MicrosoftGraphActivityLogsGraph calls by the identity, by address: MicrosoftGraphActivityLogs | where ServicePrincipalId == "<principal-id>" | summarize count() by IPAddress
AzureActivity, code executionHow the attacker got code execution, under Microsoft.Compute/virtualMachines: runCommand/action, runCommands/write (managed Run Command) and extensions/write
AzureActivity, persistenceFederated credentials added to the identity, logged as: Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/write

Contain

#Item
1Snapshot the VM's disks before any change, as in the first 15 minutes
2Record the identity's roles in each subscription: az role assignment list --assignee <principal-id> --all
3Record its roles at management group scope: az role assignment list --assignee <principal-id> --scope /providers/Microsoft.Management/managementGroups/<mg>
4Remove those role assignments: az role assignment delete --ids <assignment-id>
5Isolate the VM with a network security group that denies all traffic except the forensics subnet, per the cloud scenario
6Detach a user-assigned identity from the VM: az vm identity remove -g <rg> -n <vm> --identities <identity-id>
7List the identity's federated credentials: az identity federated-credential list --identity-name <identity> -g <rg>
8Delete federated credentials you did not create destructive: az identity federated-credential delete --name <fic> --identity-name <identity> -g <rg> --yes

Eradicate and recover

#Item
1Rebuild the VM from a known-good image and retire the compromised one after evidence release
2Fix the app flaw that reached the metadata endpoint, and check whether the app forwards a caller-supplied Metadata: true header
3Grant the rebuilt workload a user-assigned identity with the fewest roles it needs, assigned directly to the identity
4Keep watching the identity's calls for at least 24 hours after role removal
Watch out
  • Azure caches managed identity tokens for around 24 hours and offers no way to force a refresh. Group membership changes can take hours to apply, so remove direct role assignments.
  • Conditional Access for workload identities excludes managed identities.

Microsoft Learn: managed identities FAQ and best practice recommendations, including token caching; Conditional Access for workload identities; AADManagedIdentitySignInLogs, AzureActivity, StorageBlobLogs and MicrosoftGraphActivityLogs table references; resource provider operations for Compute and Managed Identity; Azure CLI reference for az role assignment, az vm identity and az identity federated-credential. Checked October 2026.

Adapts material from Dynamic Incident Response: A Framework for Security Teams by Joshua Wright, © 2026 The Escal Institute of Advanced Technologies, Inc. d/b/a SANS Institute, licensed under CC BY 4.0. Figures reproduced under that license. Changes were made. Not published by, endorsed by, or affiliated with the SANS Institute.