Compromising EC2 IMDSv2 with RCE to Access Sensitive S3 Data
Learn how IMDSv2 can be compromised through an RCE attack to access sensitive credentials. Then use those credentials to capture the flag stored in an Amazon S3 bucket. Note: this lab takes longer than average to load (approx. 4mins) due to the resources being created.
- 10 guided tasks
- Terminal in the browser

Scenario
A web application runs on an EC2 instance and returns the current time for different timezones. It builds its response by passing your input straight to a shell command, which makes it vulnerable to remote code execution (RCE). Your goal is to exploit that RCE, use it to steal the instance role's credentials from IMDSv2, and then use those credentials to read a sensitive flag stored in an Amazon S3 bucket.
Note: Even once the lab has launched, it can take another 2-3 minutes for the instance to finish initializing. If you try to access the IP address and it doesn't resolve, that's why. Give it a minute or two and try again!
What you will learn
- Identify a remote code execution (RCE) vulnerability in a web application
- Use the RCE to query the EC2 Instance Metadata Service (IMDS)
- Fetch an IMDSv2 token and read the instance role's temporary credentials
- Configure the AWS CLI with the stolen credentials
- Use the credentials to list an S3 bucket and read its sensitive flag
Compromising EC2 IMDSv2 with RCE to Access Sensitive S3 Data
Included in Cybr Premium.