PIVTR-D
RAzure playbook · Compute and containers

Compromised virtual machine

An attacker gets code execution on a virtual machine (VM) through an exposed service, stolen credentials, or an Azure role that allows Run Command or VM extensions. From the VM, the attacker requests managed identity tokens, reads secrets from disk, and moves to other hosts. Preserve memory and disks first, then cut the VM off from the network and from its identity's token endpoint.

Look here

LogSearch for
AzureActivityRun Command, extension and disk export operations on the VM. The operations sit under Microsoft.Compute: virtualMachines/runCommand/action, virtualMachines/runCommands/write, virtualMachines/extensions/write, disks/beginGetAccess/action and snapshots/beginGetAccess/action. Query the VM: AzureActivity | where _ResourceId has "<vm>" | project TimeGenerated, Caller, CallerIpAddress, OperationNameValue, ActivityStatusValue
AzureDiagnostics, ApplicationGatewayFirewallLogThe exploit request that gave the attacker the VM, when the app sits behind an Application Gateway web application firewall (WAF). A WAF in detection mode logs the match and lets the request through: AzureDiagnostics | where ResourceProvider == "MICROSOFT.NETWORK" and Category == "ApplicationGatewayFirewallLog" | summarize count() by clientIp_s, requestUri_s, ruleId_s, action_s
Defender for Cloud vulnerability findingsMissing updates and known vulnerabilities on the VM. Needs Defender for Servers Plan 1 or 2, or Defender CSPM for agentless scanning: az graph query -q "securityresources | where type == 'microsoft.security/assessments' | where properties.metadata.recommendationCategory in ('SoftwareUpdate', 'ServiceUpgrade') | where id has '<vm>' | project properties.displayName, properties.additionalData.CvesDetails"
VM extensionsExtensions you did not install: az vm extension list -g <rg> --vm-name <vm>
VM Run CommandManaged Run Command resources on the VM: az vm run-command list -g <rg> --vm-name <vm>
VM disk, WindowsOutput of action Run Command on a Windows VM, kept in the folder: C:\WindowsAzure\Logs\Plugins\Microsoft.CPlat.Core.RunCommandWindows\
VM identityThe managed identities attached to the VM: az vm identity show -g <rg> -n <vm>
MicrosoftAzureBastionAuditLogsBastion sessions to the VM. Needs a diagnostic setting with category BastionAuditLogs. Search TargetResourceId for the VM and review UserName, ClientIpAddress, Protocol and SessionStartTime
Boot diagnostics logsSerial console sessions, which are logged here. The console needs boot diagnostics, a local password user, and Virtual Machine Contributor or higher
AADManagedIdentitySignInLogsTokens issued to the VM's identity, then its calls, as in the managed identity playbook
SecurityAlertDefender for Servers Plan 2 alerts VM_VMAccessUnusualPasswordReset, VM_VMAccessUnusualSSHReset, VM_VMAccessUnusualConfigReset and VM_GPUDriverExtensionUnusualExecution, and Resource Manager alerts ARM_MicroBurst.AzVMBulkCMD and ARM_AnomalousOperation.Execution

Contain

#Item
1Capture memory with your endpoint tool if the case needs it, before any network or power change
2Snapshot every disk: az snapshot create -g <rg> -n <case-id>-<disk> --source <disk-id> --tags case=<case-id>
3Record the VM's disk encryption: az vm encryption show -g <rg> -n <vm>
4Create a quarantine network security group (NSG): az network nsg create -g <rg> -n <quarantine-nsg>
5Add inbound and outbound Deny rules for * to it, and an Allow from the forensics subnet at a lower priority number
6Add an outbound Deny to the Instance Metadata Service (IMDS) service tag: az network nsg rule create -g <rg> --nsg-name <quarantine-nsg> -n deny-imds --priority 100 --direction Outbound --access Deny --protocol "*" --destination-address-prefixes AzurePlatformIMDS
7Attach the quarantine NSG to the VM's network interface: az network nic update -g <rg> -n <nic> --network-security-group <quarantine-nsg>
8Create a WAF custom rule that blocks the exploit path while the patch is prepared. Without a WAF, deny the port in the NSG of every VM built from the same image: az network application-gateway waf-policy custom-rule create --policy-name <policy> --resource-group <rg> --name BlockExploit --priority 10 --rule-type MatchRule --action Block
9Add the exploit path to the rule as its match condition: az network application-gateway waf-policy custom-rule match-condition add --policy-name <policy> --resource-group <rg> --name BlockExploit --match-variables RequestUri --operator Contains --values <path>
10Record the managed identity's role assignments: az role assignment list --assignee <principal-id> --all
11Remove those role assignments: az role assignment delete --ids <assignment-id>
12Remove the Azure roles that let the attacker run commands or write extensions on the VM
13Delete extensions the attacker added destructive, after recording: az vm extension delete -g <rg> --vm-name <vm> -n <extension>

Eradicate and recover

#Item
1Share a snapshot with the forensics team through a short-lived read shared access signature (SAS): az snapshot grant-access -g <rg> -n <snapshot> --duration-in-seconds 3600
2Rebuild the VM from a known-good image and keep the compromised disks until evidence release
3Patch or rebuild every VM built from the same image. Find them by image ID, or for Marketplace images by publisher, offer, sku and version: az vm list --query "[?storageProfile.imageReference.id=='<image-id>'].{name:name, rg:resourceGroup}" -o table
4Rotate every secret the VM stored: local accounts, SSH keys, connection strings and key vault secrets its identity could read
5Limit Run Command and extension rights to named operators, and disable the serial console where no one needs it
6Turn on Bastion diagnostic logs and boot diagnostics before you return the VM to service
Watch out
  • NSG rules apply to new connections only. An established reverse shell keeps working after you attach the quarantine NSG, until the connection ends.
  • NSGs leave IMDS at 169.254.169.254 open by default, so a quarantined VM keeps getting managed identity tokens without the AzurePlatformIMDS deny rule.
  • Azure Disk Encryption encrypts inside the guest with BitLocker or DM-Crypt, so a snapshot copy stays encrypted. Keep the key vault that stores its keys, and your access to it, until analysis ends. Azure Disk Encryption retires on September 15, 2028, and Microsoft points new VMs to encryption at host.
  • Server-side encryption with a customer-managed key also needs that key enabled for the snapshot to be readable.

Microsoft Learn: Azure permissions for Compute and Networking; action Run Command for Windows and Linux; create a snapshot of a virtual hard disk; overview of managed disk encryption options, including the Azure Disk Encryption retirement; network security groups overview; Bastion monitoring data reference; MicrosoftAzureBastionAuditLogs table; Application Gateway WAF log analytics; Azure CLI reference for az network application-gateway waf-policy custom-rule. Checked October 2026. Defender for Cloud alerts for Windows, Linux and Resource Manager: checked October 2026. Azure Serial Console for Linux and Defender for Servers vulnerability scanning: checked September 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.