How it works
AWS Systems Manager manages servers through an agent. SSM Agent runs on the instance, connects out to the service and executes what the service hands it. An instance with a working agent and a role that lets it register is a managed node. Two API operations turn an IAM permission into code execution there:
- Run Command (
SendCommand) runs a Systems Manager document on one node, a list of nodes, or every node that matches a tag. With the AWS documentsAWS-RunShellScriptandAWS-RunPowerShellScript, the document's parameters are the commands, so the caller runs its own script. - Session Manager (
StartSession) opens an interactive shell or a port forwarding tunnel to a node.
Neither needs an inbound port, an SSH key or a password on the host. AWS is explicit about the consequence: the agent runs with root permissions on Linux and SYSTEM permissions on Windows Server, and any principal that may send commands to the agent has those permissions.
Three identities are involved, and it helps to keep them apart:
- The caller is the IAM principal that calls
SendCommand. This is the identity the attacker has compromised. - The local identity is the operating system account the document's plugin runs as, which is root or SYSTEM.
- The node's AWS identity is the IAM role of the instance, delivered through its instance profile or through Default Host Management Configuration. Any process the command starts can use it.
The third is what makes this an AWS privilege escalation path and not only remote execution. The instance role is a workload identity, and a command on the node acts with it. If that role is an over-permissioned IAM role, the attacker inherits those permissions. With a tag target, one call reaches a fleet, which makes Run Command a fast lateral movement tool as well.
Run Command is asynchronous. The API returns a command id as soon as the request is accepted. Delivery and execution then happen per node, and each node has its own invocation with its own status: one node can succeed while another times out before delivery or during execution.
Prerequisites
- Valid credentials for a principal allowed
ssm:SendCommandon the target nodes and on a document that runs commands, orssm:StartSessionon the target nodes. - Targets that are managed nodes: the agent is running and the instance has a role that lets it register with Systems Manager.
- For an interactive session from the AWS CLI: the Session Manager plugin on the attacker's machine.
- To read command output:
ssm:ListCommandInvocationsorssm:GetCommandInvocation. Without them the attacker has the command send its results elsewhere. - Useful:
ssm:DescribeInstanceInformationto list managed nodes.
Attack steps
For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.
1. List the managed nodes
aws ssm describe-instance-information
The response lists each managed node with its id, platform, agent version and address. Instances that do not appear are not reachable through Systems Manager.
2. Run a command on one node
aws ssm send-command \
--document-name "AWS-RunShellScript" \
--targets "Key=instanceids,Values=i-1234567890abcdef0" \
--parameters 'commands=["id", "aws sts get-caller-identity"]' \
--comment "inventory check"
The response contains Command.CommandId. On a Windows node, use AWS-RunPowerShellScript. The second command in the example asks AWS which identity the node acts as, which works when the AWS CLI is installed on the node.
3. Read the result per node
# Status and output of every invocation of the command
aws ssm list-command-invocations --command-id <command-id> --details
# One node
aws ssm get-command-invocation --command-id <command-id> --instance-id i-1234567890abcdef0
Check each node separately. An accepted command is not an executed one, and an overall success can sit next to a node that never received its invocation.
4. Target a fleet by tag
aws ssm send-command \
--document-name "AWS-RunShellScript" \
--targets "Key=tag:Environment,Values=production" \
--parameters 'commands=["id"]'
5. Open an interactive session
aws ssm start-session --target i-1234567890abcdef0
6. Use the instance role
From the shell or the command, the attacker calls AWS with the node's role, or reads the role's temporary credentials from the instance metadata service to use them elsewhere. See EC2 instance metadata credential theft.
Pacu wraps the whole sequence in one module, which tries to execute code as root or SYSTEM on EC2 instances through Systems Manager:
Pacu > run systemsmanager__rce_ec2
Impact
The attacker has root or SYSTEM on every node it can target: application data, configuration files, credentials on disk, and the processes' memory. A port forwarding session gives a tunnel into the VPC to services that are not exposed.
In the AWS account, the attacker gains the union of the instance roles on those nodes. Instance roles often read from S3, Secrets Manager and Parameter Store, or hold deployment rights, so a principal with only Systems Manager permissions can end up with far more. Where the attacker can also change an instance's profile, it can first give the node a stronger role through iam:PassRole and then use it this way.
OPSEC and artifacts
- Looking like operations. Patch runs, inventory and maintenance windows send commands all day. An operator picks a document name, a comment and a time that resemble them. The SendCommand event still records the caller, and scheduled automation uses its own service roles, not a person's or a workload's identity.
- One node, not a fleet. A single target avoids the fan-out that tag-based rules look for. The request's targets are in the event either way.
- Session instead of command. An interactive session leaves one StartSession event and no list of commands in CloudTrail. What was typed is recorded only when session logging to S3 or CloudWatch Logs is configured.
- A custom document. Running the script through a document the attacker created, instead of
AWS-RunShellScript, defeats rules that match the AWS document names. Creating the document is an API call of its own, and the document's content stays readable in the account until it is deleted. - Acting from the node. API calls made on the instance come from the instance's own address under the role's session and look like the workload. Exporting the credentials and using them from outside changes the source address of the role's calls, which is the signal that credential exfiltration rules use.
- What always remains: the management event under
ssm.amazonaws.comwith the caller, source address, user agent, document name and targets; the command record in Systems Manager with its command id, per-node invocations, plugin status, response code and execution times; agent and plugin logs on the node, keyed by command id; and separate CloudTrail events for anything the command did through the AWS API, including Parameter Store and Secrets Manager reads, under the instance role. - What is easy to misread: a returned command id means the request was accepted. A node that timed out during delivery ran nothing; one that timed out during execution may have run part of the script.
Detection
- Shell documents sent by unexpected principals. Alert on
SendCommandwithrequestParameters.documentNameequal toAWS-RunShellScriptorAWS-RunPowerShellScriptwhen the caller is not an operator role or a known automation role. The Systems Manager detection rules cover commands, sessions and sessions started on many instances by one principal. - First use. A principal that calls
SendCommandorStartSessionfor the first time, especially a workload role, an application user or a newly created identity. - Fan-out. One command with a tag target that covers many nodes, or sessions on many instances by one principal in a short time.
- Instance role activity after the command. In the hours after a command or session, calls by the node's role session that the workload never made before, or that arrive from an address that is not the instance or its NAT gateway.
- Role change before the command. An instance profile attached or replaced shortly before a command on the same instance. See the instance profile rules.
- Per-node outcome. Read the invocations before concluding what ran. Delivery failure, execution timeout and confirmed completion support different findings.
-- Athena, CloudTrail table: Run Command and Session Manager activity by caller
SELECT eventtime, eventname, useridentity.arn AS caller,
useridentity.sessioncontext.sessionissuer.arn AS issuer,
json_extract_scalar(requestparameters, '$.documentName') AS document,
json_extract(requestparameters, '$.instanceIds') AS instance_ids,
json_extract(requestparameters, '$.targets') AS targets,
json_extract_scalar(requestparameters, '$.target') AS session_target,
json_extract_scalar(responseelements, '$.command.commandId') AS command_id,
sourceipaddress, errorcode
FROM cloudtrail_logs
WHERE eventsource = 'ssm.amazonaws.com'
AND eventname IN ('SendCommand', 'StartSession')
AND eventtime >= '2026-11-28T00:00:00Z'
ORDER BY eventtime
AWS publishes no example record for these two calls, so the request paths above follow the API parameter names; check them against a record from your own trail. Do not rely on CloudTrail for the script text. Read it from the command record in Systems Manager, and from the output location if one is configured.
Mitigation
- Grant
ssm:SendCommandandssm:StartSessiononly to the principals that operate instances, and limit them to nodes with specific tags using thessm:resourceTagcondition, as AWS recommends for these two actions. - Limit the documents. Scope
ssm:SendCommandto the document ARNs a role needs. Do not allow the shell documents to principals that only need patching or inventory. - Keep instance roles narrow. Every command on a node can use its role, so the role decides what the attack is worth in the account. Apply least privilege to each instance role and do not share one broad role across a fleet.
- Remove Systems Manager permissions from workload and CI roles that do not manage instances. A wildcard
ssm:*on an application role is the usual way this path opens. - Log what was executed. Configure Session Manager to log session activity to Amazon S3 or CloudWatch Logs, and send Run Command output there, so that the content of a session or command can be reviewed later.
- Protect who can change tags and instance profiles. Tag-based restrictions are only as strong as the control over tagging, and a replaceable instance profile lets an attacker choose the role it will use.
- Respond to a confirmed abuse as host compromise. Cancel the command, terminate open sessions, treat every targeted node as accessed with root or SYSTEM rights, and revoke the sessions of the affected instance roles.
Detection rules for this attack
Log events to collect
FAQ
Why is ssm:SendCommand equivalent to administrator access on the instance?
AWS states that SSM Agent runs with root permissions on Linux and SYSTEM permissions on Windows Server, and that any principal allowed to send commands to the agent therefore has root or SYSTEM permissions. With the AWS-RunShellScript and AWS-RunPowerShellScript documents the caller supplies the script, so the IAM permission is arbitrary code execution on the node.
Does the attacker need network access or an SSH key?
No. The agent on the instance connects out to the Systems Manager service and fetches its commands. The attacker only talks to the AWS API. Security groups, private subnets and the absence of SSH keys or RDP passwords do not stop Run Command or Session Manager.
Does CloudTrail show what was executed?
CloudTrail records that SendCommand or StartSession was called, by whom, with which document and against which targets. What is typed inside a session is not in CloudTrail; it is kept only when session logging to Amazon S3 or CloudWatch Logs is configured. For Run Command, the per-node status and output are read through Systems Manager, for example with ListCommandInvocations.
How does this lead to privilege escalation in the AWS account?
Every command on the node can use the instance's IAM role, because the role's temporary credentials are available to software on the instance. If the role has more permissions than the principal that sent the command, the attacker has escalated. One call with a tag target can do this on a whole fleet.
References
- Cloud Administration Command, T1651 (MITRE ATT&CK)
- Restricting access to root-level commands through SSM Agent (AWS Systems Manager User Guide)
- SendCommand (AWS Systems Manager API Reference)
- Understanding command statuses (AWS Systems Manager User Guide)
- Logging session activity (AWS Systems Manager User Guide)
- Logging AWS Systems Manager API calls with AWS CloudTrail (AWS Systems Manager User Guide)
- Pacu module details: systemsmanager__rce_ec2 (Rhino Security Labs)
Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.