SSRF Lab: Make a Server Fetch Its Own Cloud Secrets

✨ AI Summary
AvatarFetcher lets you set a profile picture by pasting an image URL. The server downloads it for you. That sounds harmless, until you remember the server can reach places you cannot: internal services, admin panels, and the cloud metadata service that hands out credentials. Give it the right URL and it will fetch its own secrets and show them to you.
Lab at a glance: Intermediate · 90 XP · about 15 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

Server-side request forgery (SSRF) is when you make a server send a request on your behalf to somewhere you choose. The danger is not the request itself but where it comes from: inside the network, with the server’s own trust and access.

Cloud servers make SSRF especially serious, because each one can reach a metadata service at a fixed internal address that returns configuration and, often, temporary access keys.

How AvatarFetcher downloads images

The fetcher takes any URL, requests it from the server and returns what it gets. There is no allowlist and no check on where the URL points. The lab is solved when the response contains the secret token from the internal metadata service.

The attack approach

  • Fetch a normal public image URL first to see how responses are shown.
  • Ask what this server can reach that you cannot: loopback, private ranges and the cloud metadata address.
  • Major cloud providers expose metadata at a well-known link-local IP address. Point the fetcher there.
  • Explore the metadata paths until you find the credentials for the server’s role.

Full walkthrough (spoiler)

Stuck after a few attempts? Open the steps below. Solving it yourself first is worth more XP, and more learning.

Show the step-by-step solution
  1. Enter a normal image URL and confirm the fetcher downloads it.
  2. Replace it with the metadata service address used by AWS (the link-local 169.254.169.254 address) and its latest meta-data path.
  3. Follow the listing down to the IAM security credentials section and request the role name shown there.
  4. The response now contains the internal secret token. The lab detects it and marks you solved.

Why it works

The metadata service trusts any request that comes from the machine itself, because only the machine should be able to reach that address. The fetcher is the machine, so when it fetches your URL, the metadata service answers. You never touched the internal network; you persuaded something inside it to do it for you.

Core principleNever let users choose where your server sends requests without validating the destination after DNS resolution.

Where this happens in the real world

The 2019 Capital One breach, which exposed data on more than 100 million people, used an SSRF against a misconfigured web application firewall to reach the AWS metadata service and steal credentials. SSRF was added to the OWASP Top 10 as its own category in 2021, and AWS introduced IMDSv2, which requires a session token, largely to block this attack.

How to defend against it

  • Allowlist destinations by host name where you can, instead of trying to block bad ones.
  • Resolve, then check. Block loopback, private, link-local and metadata ranges after DNS resolution, and on every redirect.
  • Enforce IMDSv2 on AWS (or the equivalent on other clouds) so simple GET requests cannot read metadata.
  • Fetch from an isolated service with no access to internal networks or credentials.
  • Do not return raw responses to the user; validate that the result really is an image.
Mr Elite tip: Any feature that takes a URL is an SSRF candidate: avatars, link previews, webhooks, PDF generators and import-from-URL tools. Once you have the basic version, try the redirect lab, where an allowlist is bypassed by an external URL that redirects inside.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is SSRF?
Server-side request forgery is a vulnerability where an attacker makes a server send requests to a destination the attacker chooses, often reaching internal systems the attacker cannot access directly.
Why is the cloud metadata service a target?
It is reachable from inside every cloud server at a fixed address and can return configuration and temporary credentials, which can unlock further access to the cloud account.
Does IMDSv2 stop SSRF?
It stops simple SSRF from reading AWS metadata because a session token obtained with a PUT request is required. It does not fix SSRF against other internal services.
How do I prevent SSRF?
Allowlist destinations, block internal and link-local ranges after DNS resolution and redirects, and run URL fetching from an isolated service.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *