Server-Side Request Forgery (SSRF) attacks can steal AWS credentials by exploiting the EC2 instance metadata service (IMDS) at 169.254.169.254, which provides live credentials to any EC2 instance; switching from IMDSv1 (token optional) to IMDSv2 (token required) prevents this attack by requiring a cryptographic session token for metadata access, which SSRF attacks cannot obtain.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
SSRF: Stealing Cloud Credentials & How to Stop It (Free Labs)
Added:Think about everything you do to lock down a server in the cloud.
Private S3 bucket, public access blocked, no passwords sitting in the code, a load balancer out front, firewalls tight. You did it all by the book.
And in about 5 minutes, we're going to rob it blind. No malware, no password cracking, no breaking in, >> [music] >> just one line of curl typed from a machine that has no account, no key, and no business being there. And the server hands over the keys to its private storage.
Then we'll shut the whole attack down by changing a single setting.
So, let's build it, break it, [music] and fix it. Start with the thing every attack in the cloud is really after, credentials.
Our web server [music] needs to read files from private storage. The old bad way is to paste a permanent access key and [music] secret straight into the code, long-lived. And if that ever leaks, the account is wide open.
The better way, the recommended way, is an IAM role.
We create a role, [music] give it read-only access to storage and nothing else, least privilege, and attach it to the server.
Now, AWS hands the server short-lived, automatically rotating credentials on demand.
>> [music] >> No secrets in the code. This is good practice. Hold that thought. Next, the thing worth stealing.
We create an S3 bucket and leave block all public access [music] switched on, fully locked down.
Nobody reaches this bucket from the open internet. The only way in is with valid AWS credentials, the exact temporary credentials that role hands our server.
>> [music] >> Inside, we drop one secret file. That's the prize. Those servers need somewhere to live. So, we build a network, a VPC, our own private slice of the cloud with an internet gateway as its door to the outside.
We carve out two subnets in two different availability zones. Why two?
Because the load balancer we're about to add refuses to run in fewer than two zones. [music] Now, the front door.
We put an internet-facing application load balancer out front, [music] listening on port 80, open to the world.
Behind it, the web server's own firewall is deliberately tighter.
>> [music] >> It accepts web traffic only from the load balancer, not from the open internet.
So, every request has to come through the front door first.
>> [music] >> Textbook. Here's the target itself. A small EC2 instance in the first subnet running a tiny Python web app. The app has one feature, a link preview.
You give it a URL, it fetches that URL for you, and shows you what [music] came back. Useful. It's also the entire vulnerability, because the server will fetch any URL you hand it, no questions asked.
That's [music] server-side request forgery, SSRF.
We attach our read-only role to this server, and we leave one legacy setting in place, the instance [music] metadata service set to version one, token optional.
Every EC2 [music] instance can ask a special internal address, 169.254. [music] 169.254.
About itself, >> [music] >> including the live credentials of its attached role.
Version one of that service, [music] IMDS version one, hands them to anyone who simply asks.
Last piece, the attacker's machine.
A second small instance, [music] SSH open, and on purpose, no IAM role at all.
It carries [music] zero AWS privileges of its own.
A clean outsider, exactly like a real attacker's laptop.
Now, watch the heist. [music] We connect to the attacker box and fire one request at the load balancer's address.
But, we set that URL parameter to the internal metadata address.
The web server does its job.
>> [music] >> It reaches inside itself, queries 169.254.169.254.
[music] Grabs its own role's credentials, >> [music] >> and passes them right back out through the load balancer to us.
First, the role name, then the temporary access key, the secret, >> [music] >> and the session token.
We plug those stolen keys into the attacker [music] box. And now, as far as AWS is concerned, we are that web server.
We read the secret file clean out of that locked bucket.
The bucket [music] that blocks all public access robbed because the thief walked in holding valid credentials.
So, how do we stop it? We don't [music] touch the code.
We change one setting.
Flip the metadata [music] service to version two, required.
Now, every metadata request has to start with a cryptographic put request carrying a special [music] header to get a short-lived session token.
And only then can it read anything.
[music] Our SSRF trick can only make simple get requests through that URL parameter.
It can't send that put. It can't get a token.
We run the exact same attack again, and this time [music] it comes back empty.
Content length zero.
The credentials never leave the building.
That's the whole story on one diagram.
A read-only IAM role for clean [music] temporary credentials, a private bucket locked to authenticated access only, a VPC across two zones, an internet-facing load balancer, and a web [music] server firewalled to sit behind it.
Every one of those choices was correct.
The attack didn't [music] beat good architecture. It beat one legacy default. A single metadata setting was the entire difference between a heist [music] and a dead end.
A diagram shows you the shape of it.
What it can't show you is how fast this [music] happens. You don't really feel it until you type that one line yourself and watch someone else's credentials scroll up your screen.
So, we built two things for you to do exactly that, both free and hands-on.
[music] First, five mini labs, one per piece, IAM, S3, VPC, [music] ALB, and EC2, so you can drill each service on its own until it's second nature.
Then, [music] the capstone, the SSRF metadata heist, where you wire it all together and play both sides.
You start as the architect, create the read-only role and attach it to your server. Stand up the private bucket, keep public access blocked, and drop in the secret file that's the prize.
[music] Build the network, a VPC, two subnets across two zones, an internet gateway.
Put the load balancer out front on port 80, and lock the web server's firewall so it only takes traffic from the balancer.
Launch the target running that link preview [music] app, and here's the part that matters. Leave the metadata service on the old version, token [music] optional.
That one setting is the door you're about to walk through.
Then, add a second machine [music] as the attacker with no role at all.
Now, flip sides. Connect to that attacker box and aim a curl at the load balancer, pointed at the internal metadata address.
The server hands back its role name, then it's live access key, secret, and session [music] token.
Paste those stolen keys in and you are the server, reading the secret file clean out of a bucket that blocks the whole public internet.
Then, flip the metadata service to version two, >> [music] >> required, one setting, no code change.
Run the same attack again and it comes back empty, content length zero. A real credential theft shut down in about 30 seconds.
One line to rob it, one setting to shut it [music] down.
If that's your kind of thing, subscribe.
We take apart a real cloud attack like this every time, [music] the break and the fix, start to finish.
Got an exploit you want us to crack open next? Drop it in the comments. Then, go build it, break it, and fix it yourself.
See you in the next one.
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

WOW! Judge TURNS THE TABLES on Trump in His OWN $10B LAWSUIT!!!
MeidasTouch
197K views•2026-07-23

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23