Skip to content
RCE Write-up Advanced

Zero-Day to SYSTEM (RCE): Escaping AWS ECS Containers via OS Comm

The amazon-ecs-agent built a PowerShell command to mount an FSx Windows file server, inserting the user-supplied username without escaping. An attacker could inject PowerShell commands that ran as NT AUTHORITY\SYSTEM on the underlying EC2 host, escaping the container.

Sachin Patil Follow

Published on medium.com

Cloud infrastructure is built on the fundamental promise of strict isolation. When you deploy a container on Amazon Elastic Container Service (ECS), you trust that the container's boundaries will hold.

Sachin Patil, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The username field from the task definition was interpolated into a PowerShell command string without escaping, unlike the password field.

Impact

An attacker could run commands as SYSTEM on the Windows EC2 host, potentially pivoting into the VPC, reading instance profile credentials from IMDS, compromising other containers on the node, and establishing persistence.

What the attacker needed

Ability to register an ECS task definition; Task uses an FSx Windows file server volume; Windows EC2 host running the ECS agent

The fix

AWS fixed the issue in amazon-ecs-agent and released new Optimized AMIs with the patched agent; customers need to upgrade their ECS worker instances to use the new AMIs.

How it was found

  1. Create a task definition that includes an FSx Windows file server volume configuration.
  2. Set the username in that configuration to a value that closes the PowerShell string and adds commands.
  3. Register the task definition through the ECS API so the control plane sends it to the agent.
  4. The agent builds and runs the PowerShell command on the Windows host, executing the injected commands as SYSTEM.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A container is meant to be a sealed box on a shared computer. The ECS agent is a helper program on that computer that sets things up for containers. It took a username from a task definition and pasted it into a PowerShell command without cleaning it, so someone could add extra commands that ran on the host itself, outside the box.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.