Any cloud identity that can call AWS Systems Manager Run Command or Azure Run Command can execute code as root or SYSTEM on every virtual machine in scope, without a network path, a password or an endpoint exploit. MITRE ATT&CK T1651 Cloud Administration Command covers adversaries abusing cloud management services, such as AWS Systems Manager, Azure RunCommand and runbooks, to execute commands inside virtual machines through the installed VM agents. In ATT&CK v20 it sits in the Execution tactic (TA0002) on the IaaS platform. ATT&CK also notes that a compromised service provider or delegated administrator can do the same through a trusted relationship. This guide covers how defenders see the technique in control-plane and guest logs, which permissions to remove, and how to roll out restrictions without breaking operations. It is for cloud security engineers, detection engineers and platform owners. For Systems Manager configuration in depth see the AWS Systems Manager Security Guide.
Key takeaways
- The permission is the privilege.
ssm:SendCommandorMicrosoft.Compute/virtualMachines/runCommand/actionis effectively local administrator on every machine it can target. - Network controls do not help. Commands travel from the provider through the agent, so a VM with RDP and SSH closed is still reachable.
- Both planes leave evidence. The control-plane call is logged by default; the guest shows the agent spawning a shell, so correlate the two.
- Delegated access counts. APT29 used Azure Run Command together with Admin-on-Behalf-of, so partner and MSP permissions belong in scope.
- Scope by document, tag and role. Restrict which commands, on which machines, by which identities, and keep execution rights out of day-to-day accounts.
How the attack works
ATT&CK describes the condition simply: an adversary with administrative access to a cloud environment can use cloud management services to run commands in its virtual machines. The services in scope, from a defender's point of view:
| Service | Required permission | Runs as | Notes for defenders |
|---|---|---|---|
| AWS Systems Manager Run Command | ssm:SendCommand on the document and the target instance ARNs | The SSM Agent context, normally root on Linux and SYSTEM on Windows | Documents such as AWS-RunShellScript and AWS-RunPowerShellScript accept arbitrary commands; output can go to S3 or CloudWatch Logs |
| AWS Systems Manager Session Manager | ssm:StartSession | A session user on the node | Interactive shell without SSH; see the AWS Systems Manager Security Guide |
| Azure Action Run Command | Microsoft.Compute/virtualMachines/runCommand/action (Virtual Machine Contributor and higher) | System on Windows, root on Linux | Built-in commands include RunPowerShellScript, EnableRemotePS, EnableAdminAccount, SetRDPPort and DisableNLA |
| Azure Managed Run Command | Microsoft.Compute/virtualMachines/runCommands/write | A customer-specified user | Deployed as a resource, supports scale sets and parallel runs |
| Azure Automation runbooks and hybrid workers | Automation account contributor rights | The runbook identity or worker account | Scheduled or on-demand scripts with a managed identity attached |
| Google Cloud OS Config | OS Config policy permissions | The guest agent | Named by the ATT&CK analytic alongside the AWS and Azure services |
Device management platforms are a close cousin. ATT&CK records VOID MANTICORE abusing built-in remote wipe and factory reset commands in an organisation's cloud management solution to wipe laptops, servers and mobile devices under this technique.
Where it shows up
- Espionage through delegated access: ATT&CK records APT29 using Azure Run Command and Azure Admin-on-Behalf-of (AOBO) to execute code on virtual machines. See the APT29 (Midnight Blizzard) Threat Actor Profile and the GDAP and MSP Delegated Admin Access Guide.
- Destructive operations: VOID MANTICORE's use of management-plane wipe commands shows the same pattern with an impact objective.
- Post-compromise of cloud keys: once an attacker holds a role with Systems Manager or Contributor rights, Run Command is the quickest way from the control plane into workloads, often to read instance credentials or deploy tooling. See the ATT&CK Execution Tactic Guide.
Impact
Run Command gives the highest local privilege on the guest, at fleet scale, with a legitimate signed agent as the parent process. An adversary can read secrets and instance credentials, install persistence, disable security tools, enable remote access paths (Azure's own built-in commands include enabling remote PowerShell, the local Administrator account and disabling Network Level Authentication) or run destructive scripts across many machines at once. Because the activity uses an administration feature, it can be mistaken for routine operations unless the caller and timing are checked.
Detection
The ATT&CK v20 detection strategy for T1651 looks for commands run by unexpected users, outside maintenance windows or by service accounts not normally tied to administration, and correlates control-plane activity with process creation inside the guest.
| Plane | Source and event | Alert when |
|---|---|---|
| AWS control plane | CloudTrail SendCommand, StartSession, CreateAssociation; ECS ExecuteCommand | Caller has not used the API in the last 30 days; document is a generic shell document; many targets at once; source outside your automation accounts |
| Azure control plane | Activity log Microsoft.Compute/virtualMachines/runCommand/action and runCommands/write | Caller is a user or service principal outside the operations group, a guest or a partner tenant; run outside change windows |
| Azure Automation | Activity log job and runbook create and update operations | New runbooks or schedules, or runbooks edited by unusual principals |
| Windows guest | Process creation (Security 4688, Sysmon 1) with parent ssm-agent-worker.exe, ssm-document-worker.exe or the Azure guest agent; RunCommandExtension.log under C:\WindowsAzure\Logs\Plugins | PowerShell or cmd launched by the agent with network or credential access activity following |
| Linux guest | auditd execve, Sysmon for Linux; /var/log/azure/run-command/handler.log | Shells spawned by the agent that download files, touch credential stores or create users |
| Command output | Run Command output in S3 or CloudWatch Logs | Output logging disabled on a command, or output buckets changed |
- Baseline the callers: in most estates only a pipeline role, a patching service and a small operations group send commands. Anything else is high signal. See the Service Account Behavioural Baselining Guide.
- Join the planes: a control-plane call with no corresponding change ticket, followed within minutes by an agent-spawned shell, is the strongest correlation.
- Watch the role assignments too: a new Virtual Machine Contributor or Systems Manager policy attachment often precedes the first command.
Metrics
- Execution rights spread: number of principals able to send commands, per account or subscription, trending down.
- Unscoped grants: share of
ssm:SendCommandgrants with no document or tag restriction. - Change linkage: share of Run Command executions that map to a change record or pipeline run.
- Output logging coverage: share of executions with full output stored centrally.
- Delegated admin exposure: count of partner relationships with VM contributor or equivalent rights.
Prevention and hardening
- Limit who can execute (M1026): ATT&CK advises limiting the number of cloud accounts able to run commands on VMs and not using them for day-to-day operations. Move Run Command rights into just-in-time privileged roles. See the Cloud PAM and CIEM Guide.
- Restrict documents in AWS: grant
ssm:SendCommandonly on the ARNs of approved custom documents, notdocument/*or generic shell documents. AWS notes that if you use global condition keys such asaws:SourceVpcewith SendCommand, you must also allowaws:ViaAWSService. - Restrict targets by tag: use the
ssm:resourceTag/<key>condition on instance ARNs so a team can only reach its own machines; untagged targets return AccessDenied. Protect the tags themselves, or the restriction can be undone by retagging. - Use narrow Azure roles: Virtual Machine Contributor and higher include Run Command. Build custom roles for VM operators without
runCommand/actionandrunCommands/write, and grant them to an operations group through Privileged Identity Management. See the Azure RBAC and Service Principals Guide. - Do not rely on removing the extension: Microsoft documents that the Run Command extension is reinstalled automatically the next time a command is applied, so RBAC is the real control.
- Guardrails at organisation level: service control policies can deny
ssm:SendCommandexcept from named automation roles; Azure Policy and management group role assignments do the equivalent. See the AWS Organizations and SCPs Guide. - Review delegated access: remove partner and MSP roles that include VM execution unless contractually needed, and prefer time-bound access. See the Azure Lighthouse Security Guide.
- Require approval for destructive fleet actions: for device management, use multi-admin approval for wipe and similar commands where the platform offers it. See the Microsoft Intune Guide.
Choosing controls
| Situation | First steps | Trade-off |
|---|---|---|
| Run Command used daily by operations | Approved custom documents only, tag-scoped targets, output to central logs | Engineers lose ad hoc shell documents; provide reviewed alternatives |
| Rarely used, break-glass only | SCP or policy deny for all but one just-in-time role | Slower emergency response; rehearse the elevation path |
| Heavy MSP or partner management | Separate delegated roles without execution rights, time-bound elevation | Partner workflows need redesign |
| Small team, few VMs | Remove Contributor from humans, alert on every execution | Alert volume is low enough to review every event |
Phased rollout
- Inventory: list every principal with SendCommand, StartSession, runCommand or runbook rights, including partner tenants and pipeline roles.
- Observe: enable the detection rules above and record 30 days of legitimate executions by caller, document and target.
- Scope: rewrite grants to approved documents and tags, and custom Azure roles without execution, testing in one account or subscription first.
- Enforce: apply organisation-level denies for everything outside the approved callers. Rollback is removing the deny from one unit while grants are corrected.
- Exercise: run an authorised benign command from an unapproved test identity and confirm it is denied or alerted, and that the guest-side correlation fires.
Where identity fits
T1651 is an identity problem first. The callers are IAM roles, access keys, service principals and managed identities, many of them non-human and broadly scoped for convenience. A leaked CI role with Systems Manager rights, or an automation account managed identity with Contributor on a subscription, is a remote shell on every machine. Treat these identities as privileged, give each an owner, and remove execution rights they do not use. See the AWS IAM Policies and Roles Guide and the OWASP NHI Top 10 NHI5 Overprivileged NHI Guide.
Lessons from incidents
- Management-plane commands can be the whole attack: in the Stryker cyberattack, attackers with a hijacked administrator account issued the Intune remote wipe command; no wiper malware was needed on endpoints. Multi-admin approval and scoped roles are the lessons that carry over to VM run commands.
- Trusted partners extend the blast radius: APT29's use of AOBO with Run Command shows that delegated administration must be reviewed as carefully as your own roles.
Framework mapping
| Framework | References |
|---|---|
| ATT&CK | M1026 Privileged Account Management; related T1199 Trusted Relationship, T1078.004 Cloud Accounts |
| NIST SP 800-53 Rev. 5 | AC-6 Least Privilege, AC-2 Account Management, CM-7 Least Functionality, AU-6 Audit Record Review, Analysis, and Reporting, SI-4 System Monitoring |
| NIST CSF 2.0 | PR.AA-05 (least privilege and separation of duties), DE.CM-03 (technology usage monitored), PR.PS-04 (log records generated) |
| CIS Controls v8.1 | Control 5 Account Management, Control 6 Access Control Management, Control 8 Audit Log Management |
| MITRE D3FEND | D3-JFAPA Job Function Access Pattern Analysis, D3-RAPA Resource Access Pattern Analysis |
Practitioner checklist
- List every identity able to run commands on VMs, including partners, pipelines and managed identities.
- Restrict
ssm:SendCommandto approved documents and tag-scoped targets. - Replace Virtual Machine Contributor for operators with custom roles that exclude Run Command.
- Make execution rights just-in-time and remove them from day-to-day accounts.
- Alert on SendCommand, StartSession and Azure runCommand calls from unexpected principals or outside change windows.
- Collect guest process telemetry and correlate agent-spawned shells with control-plane calls.
- Send Run Command output to central storage and alert when it is disabled.
- Require multi-admin approval for destructive fleet commands where available.
Standards and references
- MITRE ATT&CK: Cloud Administration Command (T1651)
- AWS: AWS Systems Manager Run Command
- AWS: Restricting Run Command access based on tags and documents
- Microsoft Learn: Run scripts in your VM by using Run Command
- Microsoft Learn: Run scripts in your Windows VM by using action Run Command
- Microsoft Learn: Run scripts in your Linux VM by using action Run Command
- MITRE ATT&CK: Trusted Relationship (T1199)
Related NHI Mgmt Group resources: AWS Systems Manager Security Guide · AWS IAM Policies and Roles Guide · ATT&CK Execution Tactic Guide · Azure RBAC and Service Principals Guide · Cloud Incident Response Guide