Labs / Cloud Security / Stealing a workload's keys

Lab 1 of 2 · Stealing a workload's keys

The address only the app could reach

An SSRF in a link-preview app reads the instance role's keys from the metadata service, and then the path is cut.

Start this lab 5 steps

The idea

Agnes watches the cloud estate at Corvid Freight. One of its instances runs a small "link preview" app, and it runs under a role, a set of permissions the cloud grants to a machine instead of a person. So the instance holds no keys on disk. It reads short-term credentials from the instance metadata service at 169.254.169.254, an address only the instance itself can reach. That is safe, until an app on the instance can be told to fetch a URL.

You are on operator with aws and curl and no credentials. Confirm the metadata address is closed to you, turn the preview app inward to read the role's keys through it, use those keys to read a bucket you never had access to. Then cut the instance's path to the metadata address and prove the theft no longer works.

No route for you, a route for the app
No route for you, a route for the app
The SSRF borrows the instance's position
The SSRF borrows the instance's position
Stolen role keys work from anywhere
Stolen role keys work from anywhere
The path is cut, not the app
The path is cut, not the app
Three fixes, three different places
Three fixes, three different places

Steps

  1. The link-preview tool

    The app on appserver (10.0.1.30) takes a URL and fetches it for you: a link preview. It looks harmless. The danger is what else it can be pointed at. Every cloud instance can read its own role's short-term keys from the metadata service at 169.254.169.254, and that address is link-local: reachable only from the instance. Prove the second half first: try to reach it straight from operator.

    operator:~# curl -s -m3 http://169.254.169.254/latest/meta-data/
  2. Point it at the metadata service

    Hand the preview app the metadata URL for the role's credentials instead of a web page. The app fetches it from the instance, where the address answers, and echoes back whatever it read. This is server-side request forgery (SSRF): the server makes a request you chose, from a position you do not have.

    operator:~# curl -s "http://10.0.1.30/preview?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/app-server-role"
  3. Walk out with the role's keys

    Those are working credentials, and the role they belong to can read Corvid's shipping manifests. Put the three values in the environment (the key id, the secret, and the session token a short-term key must carry) and read a manifest from corvid-manifests.

    One honest line: this is lawful here only because the estate is Corvid's own and Agnes's to inspect. Reading a bucket with keys obtained this way, on a system whose owner has not authorised you in writing, is a crime.

    operator:~# AWS_ACCESS_KEY_ID=ASIACORVIDAPPROLE000 AWS_SECRET_ACCESS_KEY=corvidAppRoleSecretForTheLabOnly00000000 AWS_SESSION_TOKEN=IQoJb3JpZ2luX2VjECORVIDsessiontokenLabOnlyNotRealA= aws --endpoint-url http://10.0.1.20 s3 cp s3://corvid-manifests/shipment-2026-11-03.txt -
  4. Cut the path to the metadata service

    The deepest fix is to stop the app fetching attacker-chosen URLs, and to require IMDSv2 (which needs a token the SSRF cannot get). Both take a deploy.

    There is also an immediate, independent control a defender owns outright. An instance's application has no business talking to the metadata service, so block that path. Add a firewall rule on appserver that drops anything leaving it for 169.254.169.254. Even if the SSRF stays, the request now goes nowhere.

    appserver:~# iptables -A OUTPUT -d 169.254.169.254 -j DROP
  5. Prove the theft now fails

    Run the exact SSRF from before, the same URL that handed you the role's keys a moment ago. Nothing about the app changed: it still accepts any URL and still tries to fetch it, so the hole in the code is untouched. What changed is the path out. When the app reaches toward 169.254.169.254, the firewall rule on the instance drops the packet, the fetch fails, and the app has no credentials to echo back.

    This is the test that proves a defence: the same attack, run the same way, no longer returns anything. A control you have not re-run the original attack against is a hope, not a result. So run it, and read what comes back.

    operator:~# curl -s "http://10.0.1.30/preview?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/app-server-role"

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab