NetSPI Details Command Execution Methods for Azure VMs and VM Scale Sets

Summary
NetSPI demonstrates Entra ID-authenticated command execution methods for Azure VMs and VM scale sets, and describes Azure Activity Log opportunities and caveats for detecting their use.
Key points
- The examples cover Run Command, Run-Command objects, Custom Script Extension, and Desired State Configuration (DSC), using Azure CLI, PowerShell, and REST APIs.
- The demonstrated commands execute with SYSTEM-level privileges on Windows VMs.
- Custom Script Extension and DSC can use externally hosted payloads; extensions may remain on hosts if not removed, and DSC can also support persistence.
- VM scale set Run Command targets a specified instance, while Custom Script Extension can execute across all instances; output retrieval varies by method.
- Suggested Azure Activity Log detection opportunities include Run Command actions and writes, VM extension writes, and VM scale set writes.
- The article notes that legitimate administrative activity can trigger these detections, and VM scale set write events lack a distinctive indicator of script-extension use.
- NetSPI’s Detective Controls Testing platform includes plays to validate detection controls for the described execution methods.
Article Details
- Defense Focus
- Detect and validate Azure VM and VMSS command execution through Azure platform activity logging.
- Detection Methods
- Detect AzureActivity events whose OperationNameValue ends with /virtualMachines/runCommand/action; consider both Start and Success events.
- Detect AzureActivity events whose OperationNameValue ends with /virtualMachines/runCommand/Write; consider both Start and Success events.
- Detect Microsoft.Compute/virtualMachines/Extensions/Write events, including Start and Success activity values.
- Flag Microsoft.Compute/virtualMachinesScaleSet/write activity for review; correlating interactions by multiple users in the Caller field may reduce false positives.
- Data Sources
- Azure Activity Log (AzureActivity table), including OperationNameValue, ActivityStartValue, and Caller fields.
- Rule Types
- Behavior-based event matching
- Anomaly detection
- Platforms
- Azure Activity Log
- Defensive Actions
- Monitor RunCommand action and write events, as well as VM extension writes, and investigate activity inconsistent with expected administration.
- Correlate VM scale set write activity with the Caller field and expected user behavior; account for legitimate administrative activity that may trigger these detections.
- Remove Custom Script Extension and DSC configurations after authorized testing when they are no longer needed.
- Use the described VM and VMSS execution plays to validate detective controls.
MITRE ATT&CK
T1059.001 · PowerShellThe examples execute PowerShell commands on Azure VMs using RunCommand and extensions, including RunPowerShellScript and a PowerShell script launched by Custom Script Extension.T1078 · Valid AccountsThe article describes using legitimate Entra ID credentials to authenticate to Azure management APIs and invoke VM or VMSS code execution.
Vendors
Products
AzureNetSPI’s Detective Controls Testing (DCT) Team integrated Azure capabilities into their DCT product and demonstrated multiple methods to achieve code execution on Azure Virtual Machines (VMs) and Virtual Machine ScaleNetSPI PlatformIn this blog post, we will dive into the various execution methods we’ve integrated into the NetSPI Platform, providing examples of both Azure CLI and Azure PowerShell commands along with the underlying REST API calls
