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 address169.254.169.254
TechniqueT1552.005 (Cloud Instance Metadata API)
Entry pointSSRF (CWE-918)
Key defenseIMDSv2 (session tokens) + hop limit
DetectionGuardDuty: credentials used outside AWS
Same idea onAzure IMDS, GCP metadata server

Step by step

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. Defend with IMDSv2 Tokens, hop limits and least privilege

    IMDSv2 requires a session token obtained with a PUT request and a special header before any metadata can be read. A typical SSRF can only make simple GET requests, 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

More in Cloud Security.