☁️ From SSRF to Full AWS Takeover: A Hands-On Cloud Security
A Flask application had an SSRF vulnerability that let an attacker reach the EC2 metadata service and steal temporary IAM credentials. The attacker then used those credentials to access an S3 bucket and, because of an over-permissive IAM role, escalate to full admin and create a persistent backdoor user.
Published on ashutoshhacks.medium.com
Cloud environments are often assumed to be secure by default. But in reality, misconfigurations and application vulnerabilities can quickly lead to full cloud compromise.
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 application accepted arbitrary URLs without validation, allowing access to the internal EC2 metadata endpoint, and the attached IAM role was over-permissive.
Impact
The attacker could access AWS resources, exfiltrate data from S3, escalate to admin, and maintain persistent access.
What the attacker needed
Vulnerable Flask app with SSRF; EC2 instance with IAM role; S3 bucket with misconfigured policy; over-permissive IAM role
The fix
The text recommends enforcing IMDSv2, fixing SSRF with input validation and allowlists, applying least privilege IAM, securing S3 buckets, and enabling monitoring.
How it was found
- Send a request to the /fetch endpoint with a URL pointing to the EC2 metadata service to confirm internal access.
- Enumerate IAM roles via the metadata service.
- Retrieve temporary IAM credentials for the role.
- Configure AWS CLI with the stolen credentials and verify identity.
- Use the credentials to list and download files from an S3 bucket.
- Create a new IAM user, attach an admin policy, and generate access keys for persistence.
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.
The web app had a feature that fetched any URL a user gave it, without checking where it pointed. An attacker could make the server fetch a special internal address that only cloud servers can see, which handed back temporary passwords for the cloud account. With those, the attacker could read files and even give themselves permanent admin rights.
What is SSRF?
The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.