Lesson 6 of 13 · 20m
SSRF and the metadata endpoint: how Capital One happened
169.254.169.254 serves live role credentials to anything that asks — IMDSv2, hop limits, and the 2019 breach that proved it.
Every EC2 instance carries a web server that only the instance can reach. curl http://169.254.169.254/latest/meta-data/ returns metadata about the host, and http://169.254.169.254/latest/meta-data/iam/security-credentials/<role-name> returns something far more interesting: live temporary credentials for the instance profile — AccessKeyId, SecretAccessKey, SessionToken — delivered over plaintext HTTP to any process that opens a socket. No authentication. That endpoint is why SSRF on AWS is not a web bug; it is credential theft.
The wrong mental model
People assume "metadata" means descriptive trivia — instance ID, AMI, hostname. Some of it is. But the iam/security-credentials/ path returns working AWS credentials, and the mental firewall people imagine — "the app can only reach out to the internet" — does not apply: 169.254.169.254 is link-local, answered by the hypervisor, and reachable from inside the instance regardless of your security groups, NACLs, or route tables. You cannot firewall it away. Any process on the box can ask for it, including the one that just fetched an attacker-supplied URL.
The canonical case: Capital One, 2019
Paige Thompson found that a web application firewall appliance Capital One ran on EC2 would fetch attacker-controlled URLs — a server-side request forgery. She pointed it at 169.254.169.254, harvested the ISRM-WAF-Role credentials, and used them to list roughly seven hundred S3 buckets and sync out around 30 GB — data for about 100 million credit card applications. AWS shipped IMDSv2 four months later, in November 2019. The breach ended in an $80 million OCC fine and a $190 million class settlement, and it is still the cleanest illustration that one SSRF plus one over-privileged instance role equals a bulk data breach.
IMDSv2: a session, not an open socket
IMDSv1 answered any GET. IMDSv2 is session-oriented:
# 1. Get a token (a PUT, not a GET)
TOKEN=$(curl -X PUT http://169.254.169.254/latest/api/token \
-H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
# 2. Use it on every subsequent request
curl -H "X-aws-ec2-metadata-token: $TOKEN" \
http://169.254.169.254/latest/meta-data/iam/security-credentials/Two properties of that design break the classic SSRF. First, most SSRF gadgets can only GET — the vulnerable feature fetches a URL, it does not issue PUTs with custom headers, so the token request fails. Second, IMDSv2 refuses requests carrying an X-Forwarded-For header — which is exactly what the request looks like after being proxied through the vulnerable application. The easy path dies.
What IMDSv2 does not do: stop code execution on the host, stop an SSRF gadget that can PUT, or fix an over-privileged role. It raises the bar on one specific kill chain. The Capital One role could still have listed those buckets if the attacker had gotten a shell — IMDSv2 would not have saved an s3:* role.
Two operational footnotes. Containers add a network hop, so set --http-put-response-hop-limit 2 on nodes running pods or the token PUT dies on the docker bridge. And the MetadataNoToken CloudWatch metric counts IMDSv1-style (tokenless) usage per instance — watch it to find stragglers before you enforce v2.
Enforce it
aws ec2 modify-instance-metadata-options \
--instance-id i-0123 \
--http-tokens required \
--http-endpoint enabled \
--http-put-response-hop-limit 2Do it at the standard layer: MetadataOptions in launch templates, aws ec2 modify-instance-metadata-defaults for AMI defaults, and an SCP on ec2:RunInstances conditioned on ec2:MetadataHttpTokens = required so nobody launches a v1 instance.
Exercise
Launch two instances, one with HttpTokens=optional, one required. From an app that fetches a URL you control (a webhook tester, a "fetch this image" endpoint — or just a shell simulating it), retrieve the instance role credentials from the v1 box. Then attempt the same against the v2 box and watch the GET fail with 401. Check MetadataNoToken on both.
Field notes
- The metadata endpoint is not the only link-local credential service: ECS tasks have
169.254.170.2(task role creds) and Lambda exposes creds via environment — same attack shape, different path. - Application-side defenses still matter: allowlist outbound destinations, resolve-and-pin DNS for user-supplied URLs, and strip redirects that bounce internal. IMDSv2 is the backstop, not the fix.
- GuardDuty's
UnauthorizedAccess:IAMUser/InstanceCredentialExfiltrationfindings exist precisely for this pattern — credentials used off-instance are the observable.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
AWS Emulator Puts AWS on Your Laptop. Keep Your IAM Tests Off It.
AWS released AWS Emulator on November 11, a free local server that answers AWS API calls on 127.0.0.1 with per-run keys and fresh certificates.
Big Tech Plans to Work with the Public Sector for Cybersecurity
Both Microsoft, Inc. and Alphabet, Inc. will put a combined $30 billion dollars into cybersecurity over the next five years and work with the public sector on several initiatives to help improve cybersecurity.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.
What is SSRF? Server-Side Request Forgery and the Attack That Breached Capital One
SSRF tricks your server into making requests to internal systems — cloud metadata services, internal APIs, AWS credentials endpoints. It turned a WAF misconfiguration into 100 million stolen Capital One records