Key Takeaways
- Server-side request forgery (SSRF) is dangerous in the cloud because the server can reach the instance metadata service and read the machine's IAM credentials.
- The chain was: SSRF, to IMDS, to stolen role credentials, to an over-privileged IAM role, to an IAM escalation path, to full account control.
- IMDSv1 hands out credentials to any process that can make an HTTP request to
169.254.169.254. IMDSv2 requires a session token and a hop limit, which breaks the SSRF path. - Over-privileged roles turn a foothold into a takeover. A role scoped to exactly what the app needs would have contained the damage even after the SSRF.
- Every step is visible in CloudTrail and GuardDuty: metadata credential use from a new location, unusual IAM calls, and new access keys.
A Feature That Fetches URLs
The target was a customer-facing web application hosted on EC2. During mapping we found an innocuous feature: paste a link to an image and the server would fetch it and show a preview. Useful, common, and exactly the kind of feature that becomes a doorway when the server will fetch any URL, including ones that point back inside the cloud.
This is server-side request forgery, and in a traditional data centre it is a medium-severity bug. In the cloud it is often critical, because the server has a neighbour it implicitly trusts: the instance metadata service, a special address every cloud VM can reach that hands out the machine's identity and credentials.
Link 1: SSRF Reaches the Metadata Service
We pointed the image-preview feature not at an image but at the cloud metadata endpoint, 169.254.169.254. The instance was running the older IMDSv1, which answers any HTTP request with no authentication. Through the app's own fetch, we read the metadata tree and, at the credentials path, the temporary access key, secret and session token belonging to the IAM role attached to the EC2 instance.
That is the whole first link: the app fetched an internal URL on our behalf and returned the response, and the response was a set of working AWS credentials. No exploit code, no memory corruption. Just a feature doing exactly what it was built to do, pointed somewhere it should never have been allowed to go.
- The credentials path under
/latest/meta-data/iam/security-credentials/returns short-lived keys for the instance role. - IMDSv1 requires no token, so any SSRF, or any process on the box, can read it. This is the single most important cloud-SSRF fact.
- The keys are temporary, but temporary is long enough: minutes are plenty to enumerate and escalate.
Want to Know Your Real Attack Chain?
Codesecure runs red team and internal penetration tests that start where a real attacker starts: an unauthenticated foothold, and chain the misconfigurations until something breaks. You get the full attack path, mapped to MITRE ATT&CK, with the exact fixes that break each link. ISO/IEC 27001:2022 certified delivery, named OSCP, CEH and CISSP consultants, across India, Singapore, UAE and Malaysia.
See Red Team and VAPT Services →Link 2: The Role Can Do Far Too Much
With the stolen credentials loaded into the AWS CLI, the first move is always the same quiet question: who am I, and what can I do? aws sts get-caller-identity confirmed the role, and careful enumeration of its permissions showed the real problem. The role existed to let the app read and write one S3 bucket, but it had been granted far more: broad S3 access, the ability to read other services, and, fatally, a couple of IAM permissions it never needed.
This is the step that decides whether an SSRF is an incident or a catastrophe. A role scoped to exactly one bucket would have let us read that bucket and nothing else. This role, over-provisioned "to save time", gave us the raw material to escalate out of the application entirely.
aws sts get-caller-identityand then enumerate attached policies; tooling likeenumerate-iambrute-checks what the key can actually call.- Look for the dangerous IAM permissions:
iam:CreatePolicyVersion,iam:AttachUserPolicy,iam:PassRole,sts:AssumeRoleand friends, each a known privilege-escalation primitive. - Over-privileged roles are the single most common serious cloud finding. Least privilege is not paperwork; it is the control that contains an SSRF.
Link 3: IAM Escalation to Admin
The role held an IAM permission that is a textbook escalation primitive. Using it, we attached a more permissive policy to an identity we controlled, promoting our access from "the app's role" to effectively administrative control of the account. There are several of these primitives, and offensive tooling maps them automatically; the point is that one unnecessary IAM action turned a contained foothold into account ownership.
From there it was over. With admin-equivalent rights we could read every S3 bucket (including the ones holding customer data), enumerate every service, create a new IAM user with its own access keys as a durable backdoor, and generally do anything the legitimate administrators could. An image-preview feature had become full control of the cloud account.
The Whole Chain
Four links, and only one of them was a classic vulnerability:
- 1. SSRF in a URL-fetch feature let the server make requests we controlled.
- 2. IMDSv1 handed the server's role credentials to that request.
- 3. An over-privileged role gave those credentials far more than the app needed.
- 4. An IAM escalation primitive turned the role into account admin.
Not Sure Where Your Chain Starts?
Most compromises begin with something small: an anonymous share, a reused password, a writable script. On a free 30-minute call our lead will map the most likely first links in your environment and how we would test them.
Book a Free Scoping Call →What the Defenders Could Have Seen
This chain is loud in the right logs. CloudTrail records the API calls made with the stolen credentials, and the giveaway is that an instance role's credentials are suddenly being used from an IP address that is not the instance, a pattern AWS GuardDuty raises as UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration. The IAM escalation calls (attaching policies, creating users) are high-signal events that should page someone. Even the SSRF itself leaves a trace: the app making an outbound request to a link-local address.
Detection assumes the first mistake will happen and tries to catch the attacker mid-chain. Feeding CloudTrail and GuardDuty findings into a SIEM, and alerting on instance-credential use from foreign IPs and on IAM changes, would have turned this from a silent takeover into an answered alert.
Frequently Asked Questions
What is SSRF and why is it worse in the cloud?
Server-side request forgery (SSRF) is a flaw where an attacker makes a server send HTTP requests to a destination the attacker chooses. On-premises it lets an attacker reach internal services. In the cloud it is often critical because the server can reach the instance metadata service at 169.254.169.254, which hands out the machine's IAM credentials. An SSRF that reaches IMDSv1 therefore turns into stolen cloud credentials, which is how a minor web bug becomes an account takeover.
What is the difference between IMDSv1 and IMDSv2?
IMDSv1 answers any HTTP request to the metadata endpoint with no authentication, so any SSRF or any process on the instance can read the role credentials. IMDSv2 requires a session token obtained with a PUT request and supports a hop limit, which means a simple SSRF cannot retrieve credentials. Enforcing IMDSv2 across your instances is a free, high-impact control that breaks the SSRF-to-credentials step of this attack chain.
How does an attacker escalate from an EC2 role to account admin?
By abusing IAM permissions the role should not have. Permissions such as iam:CreatePolicyVersion, iam:AttachUserPolicy, iam:PassRole and sts:AssumeRole are privilege-escalation primitives: they let a role grant itself or another identity more access. If a workload role includes one of these unnecessarily, a stolen credential can be escalated to administrative control. Removing IAM-modifying permissions from workload roles and adding SCP guardrails prevents it.
How do we prevent SSRF to AWS account takeover?
Break the chain at several points: validate and restrict outbound URLs so the app cannot fetch internal or link-local addresses, enforce IMDSv2 with a hop limit so an SSRF cannot reach credentials, scope every IAM role to least privilege so a stolen credential is contained, remove IAM-modifying permissions from workload roles, add service control policies, and monitor CloudTrail and GuardDuty for instance-credential use from foreign IPs and for IAM changes.
Would a vulnerability scanner find this?
Rarely as a chain. A scanner might flag the SSRF as a standalone issue and perhaps note IMDSv1, but it will not steal the credentials, enumerate the role, find the IAM escalation primitive, or connect them into account takeover. That requires an attacker's judgement, which is what a cloud penetration test provides: it walks the path to the real impact and tells you the single cheapest fix at each link.
Can Codesecure test our AWS environment for chains like this?
Yes. Codesecure runs cloud penetration tests and red team engagements against AWS and Azure that chain real misconfigurations, from application flaws like SSRF through metadata and IAM to account-level impact, and map the path to MITRE ATT&CK. You get the attack path and the cheapest fix at each link. ISO/IEC 27001:2022 certified delivery with named OSCP, CEH and CISSP consultants across India, Singapore, UAE and Malaysia.
Could an SSRF Own Your AWS Account?
Codesecure tests your cloud the way an attacker does, chaining application flaws through metadata and IAM to real account-level impact, then hands you the cheapest fix at every link. Cloud pentest and red team by named OSCP, CEH and CISSP consultants, ISO/IEC 27001:2022 certified, across India, Singapore, UAE and Malaysia.

