Last updated: April 29, 2026
Why this module exists. Capital One. Capital One. Capital One. Every cloud security training references it because the chain is iconic: external SSRF → IMDS → IAM credentials → S3 dump. Six years later, IMDSv1 is still enabled on enough EC2 fleets to keep the attack practical. And Azure / GCP have their own metadata-service attack surfaces.
What metadata services do
Every cloud VM needs a way to know its identity, its instance type, its attached IAM role’s credentials, its launch configuration. The cloud provides this via a special HTTP endpoint accessible only from the VM itself:
| Cloud | Endpoint | Auth |
|---|---|---|
| AWS | http://169.254.169.254/latest/meta-data/ | IMDSv1: none. IMDSv2: PUT-derived token. |
| Azure | http://169.254.169.254/metadata/instance?api-version=… | Header: Metadata: true |
| GCP | http://metadata.google.internal/computeMetadata/v1/ | Header: Metadata-Flavor: Google |
The crucial detail: this endpoint is reachable from any process on the VM. Including any process the attacker controls — including a vulnerable web app that does SSRF.
Why this is dangerous
The metadata service exposes credentials for the VM’s IAM role/managed identity:
# AWS
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/
# Returns role name(s)
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/MyRole
# Returns AccessKeyId, SecretAccessKey, Token, Expiration
# Azure
curl -H "Metadata: true"
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"
# Returns OAuth token for Azure Resource Manager
# GCP
curl -H "Metadata-Flavor: Google"
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
# Returns access token for the service account
Possess any of these, you ARE the VM’s identity. Every IAM permission the role has, you have.
IMDSv1 vs IMDSv2 — what AWS actually fixed
IMDSv1: simple GET to 169.254.169.254. SSRF in any web app on the VM = credential theft. Capital One.
IMDSv2 (2019, default for new instances since 2024):
- Client must PUT to
/latest/api/tokenwith headerX-aws-ec2-metadata-token-ttl-seconds: 21600. Returns a session token. - Client uses the session token in subsequent GET requests.
Why this defeats SSRF: most SSRF primitives only do GET. They can’t PUT. They can’t supply custom headers (sometimes). The token requirement breaks the simple SSRF→IMDS chain.
Note: some HTTP libraries the SSRF tunnels through can be tricked into PUT; bypass research is ongoing. But for the typical “fetch URL preview” SSRF, IMDSv2 is a hard wall.
Azure and GCP equivalents
Both require a header to query metadata: Azure Metadata: true, GCP Metadata-Flavor: Google. Many SSRF primitives don’t allow custom headers, so these protections are similar in spirit to IMDSv2.
Azure’s X-Forwarded-For handling can sometimes bypass the Metadata header check in misconfigured proxies — research worth tracking.
The deeper defense — egress filtering
Even with IMDSv2, an attacker who fully controls a process on the VM can request the token themselves. The defence-in-depth answer: VM processes that don’t need metadata access shouldn’t be able to reach the metadata service.
On AWS, this means a network ACL or security group that blocks 169.254.169.254 from the application’s VPC subnet — except for the system services that need it. Operationally complex but the strongest layered defence.
Real-world cases
- Capital One 2019 — IMDSv1, WAF SSRF, 106M records.
- Many post-Capital-One incidents — same pattern, smaller scale, less press. Cloud-IR firms see this monthly.
- 2021 Microsoft Azure CosmosDB compromise (ChaosDB) — partly enabled by metadata-service-style trust assumptions, though the specifics differ.
Try this yourself
# Audit IMDSv2 enforcement on your AWS fleet
aws ec2 describe-instances --query
'Reservations[*].Instances[*].[InstanceId,MetadataOptions.HttpTokens]'
--output table
# Force IMDSv2 on every instance going forward (Org Policy)
aws ec2 modify-instance-metadata-options
--instance-id i-xxxxx
--http-tokens required
--http-put-response-hop-limit 1
# Reduce hop-limit to 1 — prevents containers/sidecars without --net=host from reaching IMDS
# Test from a vulnerable web app
# (your favorite SSRF primitive — see Module 18 for technique)
curl http://target.com/?url=http://169.254.169.254/latest/meta-data/
# IMDSv1 enabled? You'll get instance metadata
# IMDSv2 enforced? You'll get 401
Defender’s checklist
- IMDSv2 required on every EC2 instance.
HttpTokens=required. SCP at Org level:ec2:RunInstanceswith HttpTokens != required → deny. - Hop limit = 1 — prevents containers without host-network from reaching IMDS via the host.
- Egress filtering — Lambda VPC config, security groups blocking 169.254.169.254 from app subnets.
- Detection: VPC Flow Logs alerting on outbound to 169.254.169.254 from unexpected sources.
- Test SSRF on every web app — perimeter and internal. Module 18 (SSRF) for techniques.
- Same posture for Azure, GCP — header-based protection is similar but not bulletproof.
Module Quiz · 6 questions
Pass with 80%+ to mark this module complete. Unlimited retries. Each question shows an explanation.
Custom team training + practitioner advisory
Beyond the free academy — we run private workshops, vCISO advisory, and red-team exercises tailored to your stack. For Indian SMBs scaling past their first hire.