Belajar
← All lessons

How SSRF works

A link preview fetches the cloud's keys

You
App server
news.test

preview.js

app.post("/preview", async (req, res) => {  const url = req.body.url;  const page = await fetch(url); // any URL at all, fetched from inside  const html = await page.text();  res.json({    title: titleOf(html),    text: html.slice(0, 300),  });});

metadata.http

// no password, no token: being on the machine is enoughGET http://169.254.169.254/latest/meta-data/    iam/security-credentials/app-role200 { "AccessKeyId": "ASIA…",      "SecretAccessKey": "…", "Token": "…" }

Sneak past the filter four defenses, eight tricks

Link to preview
Try
The server checks withNothingBlocklistPrivate IPsAllowlist
What the server does
    The preview card

    Check the IP you actually connect to. Resolve twice, and DNS can answer a public IP first and 169.254.169.254 the second time

    guard.js

    // blocklist: checks the text, not the addressif (input.includes("169.254.169.254")) throw blocked; // private ranges: check the resolved IP, then connect to that same IPconst ip = await dns.lookup(url.hostname);if (isPrivate(ip)) throw blocked;const res = await fetchAt(ip, url, { redirect: "manual" });// and again on every redirectif (res.status >= 300 && res.status < 400) recheck(res.headers.location); // allowlist: only hosts you choseif (url.protocol !== "https:" ||    !["news.test", "blog.test"].includes(url.hostname))  throw blocked;

    Topics

    Next: How a browser renders a page

    Open lesson