Skip to content
RCE Write-up Intermediate

Exploiting Aws ec2 imdsv2 Metadata Through Rce And Ssrf

A vulnerable web application allowed remote command execution on an EC2 instance, which let an attacker request an IMDSv2 token and retrieve temporary IAM role credentials. Those credentials were then used to access an S3 bucket.

Indranil Roy Follow

Published on systemweakness.com

Cloud incidents do not always start with a leaked access key or a misconfigured S3 bucket. Sometimes, they start with a small web application issue.

Indranil Roy, on systemweakness.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

Likely the application passed user-controlled input to shell commands without proper validation, enabling command execution on the EC2 instance.

Impact

The attacker could obtain temporary IAM credentials and use them to access an S3 bucket, with the impact depending on the permissions attached to the EC2 role.

What the attacker needed

Vulnerable web application with command execution; EC2 instance with IMDSv2 enabled; IAM role attached to the instance; role permissions allowing S3 access

How it was found

  1. Identify a web application parameter that accepts user input and processes it on the server side.
  2. Confirm command execution by running a basic system command and checking the output.
  3. Request an IMDSv2 session token from the metadata service through the vulnerable endpoint.
  4. Use the token to query EC2 metadata and discover the attached IAM role.
  5. Retrieve temporary IAM credentials for the role from the metadata service.
  6. Use the temporary credentials to list and download objects from an S3 bucket.

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 web app let users run system commands on its server. The attacker used that to ask the cloud provider's internal metadata service for temporary login keys. Those keys then gave access to a storage bucket.

What is RCE?

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

More by Indranil Roy

View all

3 more disclosed reports, best first.

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.