Cloud Metadata Credential Theft
SSRF to the instance metadata service
Every cloud virtual machine can ask a special internal address for information about itself, including temporary credentials for its IAM role. If a web app on that machine has an SSRF bug, an attacker can make the server fetch those credentials and then use them from anywhere. This is how several major cloud breaches happened.
Intermediate · 5 steps
| Metadata address | 169.254.169.254 |
|---|---|
| Technique | T1552.005 (Cloud Instance Metadata API) |
| Entry point | SSRF (CWE-918) |
| Key defense | IMDSv2 (session tokens) + hop limit |
| Detection | GuardDuty: credentials used outside AWS |
| Same idea on | Azure IMDS, GCP metadata server |
Step by step
An SSRF in the app The server fetches any URL
The app has a "preview image from URL" feature that downloads whatever address the user supplies. The attacker gives it an internal address instead of an image, and the server makes the request from inside the cloud network.
Find the role What credentials does this machine have?
The metadata service lists the IAM role attached to the instance. With the older IMDSv1, a plain GET request is all it takes, so the SSRF can walk the metadata tree like a website.
Steal temporary credentials Keys returned through the app
Requesting the role name returns a temporary access key, secret key and session token. The vulnerable preview feature passes the response straight back to the attacker.
Use them from outside The role's permissions are now the attacker's
From their own machine, the attacker uses the keys with the cloud CLI. The role was given broad S3 read access "to make things work", so they can list and download customer export buckets. GuardDuty notices the instance credentials being used from an IP address outside AWS and raises a high-severity finding.
Defend with IMDSv2 Tokens, hop limits and least privilege
IMDSv2 requires a session token obtained with a
PUTrequest and a special header before any metadata can be read. A typical SSRF can only make simpleGETrequests, so it fails. A hop limit of 1 also stops the token from passing through proxies or containers. Fixing the SSRF and narrowing the role close the remaining gaps.
How to defend
- Require IMDSv2 on every instance so a simple GET request can't read metadata
- Keep the metadata hop limit at 1 unless containers truly need more
- Fix SSRF: allow-list destinations and block internal and link-local addresses
- Give instance roles only the permissions the app needs
- Alert when instance credentials are used from outside your cloud account
More in Cloud Security.
Packets
| No. | Time | Source | Destination | Protocol | Info | Size |
|---|