Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Web attacks

Lab · Medium · 1.5 hoursFree account

Server-Side Request Forgery & Attacks

SSRF filter bypass, stolen cloud-metadata credentials, blind OOB detection, and SSTI chained into one RCE.

  • ssrf
  • ssti
  • cloud-metadata
  • out-of-band
  • rce
On this page 17 sections
  1. ·Why this lab is different
  2. ·Prerequisites
  3. ·Lab setup
  4. ·Build the target
  5. 1Map the server-side request surface
  6. 2Confirm the SSRF with a safe internal probe
  7. Locked: Bypass the loopback filter to reach the admin API
  8. Locked: Pivot to cloud metadata and steal the instance role
  9. Locked: Use the stolen token against the secrets service
  10. Locked: Detect the blind SSRF on the import webhook
  11. Locked: Fingerprint and confirm SSTI in the preview field
  12. Locked: Escalate SSTI to command execution
  13. Locked: Chaining it together
  14. Locked: Detection and defence
  15. Locked: Check
  16. Locked: Clean-up
  17. Locked: Command reference

Modern web apps rarely fail on one flaw. Attackers chain weak server-side sinks to turn a single fetch field, a webhook or a template preview into the breach of a cloud instance role. You exploit three sinks in one Flask app, steal a metadata token, and prove a blind sink with an out-of-band probe.

What You'll Learn

  • Map a server-side request surface from source before you touch the target
  • Bypass a host filter to reach a loopback-bound internal API
  • Steal and reuse cloud instance-metadata credentials pulled through SSRF
  • Detect a blind SSRF that reflects no output, with an out-of-band listener
  • Fingerprint a template engine and confirm SSTI with a safe probe
  • Escalate SSTI to command execution and name the fix for each flaw in the chain

Why this lab is different

Most labs teach one server-side flaw on its own, such as Server-Side Template Injection (SSTI). Real applications rarely give you only one. This lab targets a single app with three server-side sinks: an image fetch, a report-import webhook, and a template preview. You chain them. SSRF reaches a credential one way; SSTI reaches the same credential a second way. You learn why fixing only one link still leaves the chain broken.

Prerequisites

Lab setup

ItemPurpose
curlSends every crafted request in this lab
interactsh-clientGives you an out-of-band domain for blind SSRF detection
jqReads nested JSON out of the responses

Build the target

KaliRange hosts no targets, no virtual machines and no lab files. You run this lab against a small service chain that you build yourself. The names and addresses below are the example addresses of this lab; use your own.

Your target must have four parts, all on one lab network (example 10.0.18.0/24):

HostExample addressRole
ReportForge10.0.18.25:8080A Python/Flask service with the three routes Step 1 shows: chart_image (fetches a URL, with no host check beyond blocking the literal strings 127.0.0.1 and localhost), import_report (fetches a URL, fire-and-forget, no body back), preview (renders title_template with Jinja2's render_template_string, no sandbox). No login is needed; none of the routes check a credential.
Admin API127.0.0.1:8081, the ReportForge host's own loopbackAnswers GET /health with {"service":"reportforge-admin","version":"2.4.1","debug":true}
Metadata emulator169.254.169.254, reachable only from 10.0.18.0/24Answers GET /latest/meta-data/iam/security-credentials/ with the role name reportforge-worker, and GET .../reportforge-worker with the credential JSON Step 4 shows (AccessKeyId, SecretAccessKey, Token, Expiration)
LabVault10.0.18.50:9100Answers GET /v1/secrets/storage-api-key with {"name":"storage-api-key","value":"..."} when given the metadata emulator's Token value, as a header or a token query parameter

No public training target reproduces this exact chain, so build these four services yourself: ReportForge is the Flask app from Step 1's source, run with the filter and the three routes exactly as shown; the other three are small stub HTTP services that answer the fixed JSON above. Put ReportForge's source at ~/reportforge-src on your own Kali machine; the commands in Step 1 and the troubleshooting read it from there. Take a snapshot of each virtual machine, or note the container state, before Step 1.

Legal note. Run every command in this lab only against a target that you own or have written permission to test, here 10.0.18.25, 169.254.169.254, and 10.0.18.50. Unauthorised SSRF and template injection can be criminal offences in many countries.

Step 1: Map the server-side request surface

1

Read the source before you send a single request

Three routes take attacker-controlled input and pass it, unchecked, into something the server does on your behalf. Find all three before you decide which to attack first.

python~/reportforge-src/app/reports.py (excerpt)
@app.route("/api/reports/chart-image", methods=["POST"])
def chart_image():
    url = request.json["image_url"]
    resp = requests.get(url, timeout=5)          # no host check
    if "image/" not in resp.headers.get("Content-Type", ""):
        return jsonify({
            "error": "unsupported content-type",
            "content_type": resp.headers.get("Content-Type"),
            "preview": resp.text[:300],
        }), 422
    return jsonify({"status": "ok", "bytes": len(resp.content)})

@app.route("/api/reports/import", methods=["POST"])
def import_report():
    source = request.json["source_url"]
    queue.enqueue(fetch_and_store, source)        # fire-and-forget, no body back
    return jsonify({"status": "queued"}), 202

@app.route("/api/reports/preview", methods=["POST"])
def preview():
    tpl = request.json["title_template"]
    return jsonify({"html": render_template_string(tpl)})  # renders raw user input
# Confirm the pattern yourself
grep -rn "requests.get(url\|queue.enqueue(fetch_and_store\|render_template_string(tpl" ~/reportforge-src

Example output:

reports.py:4:    resp = requests.get(url, timeout=5)
reports.py:13:    queue.enqueue(fetch_and_store, source)
reports.py:20:    return jsonify({"html": render_template_string(tpl)})

chart_image gives you a reflected oracle — its error message echoes the content type and the first 300 bytes of whatever it fetched. import_report gives you nothing back — a blind sink. preview renders your string as code. Each needs a different detection method, which is exactly why you attack all three.

Step 2: Confirm the SSRF with a safe internal probe

2

Prove the server fetches, not your browser

Point chart_image at an internal host that is not on any blocklist. If the JSON error reflects that host's real response, the fetch happened on the server.

curl -s -X POST http://10.0.18.25:8080/api/reports/chart-image \
  -H "Content-Type: application/json" \
  -d '{"image_url":"http://10.0.18.60:9090/health"}'

Example output:

{"error":"unsupported content-type","content_type":"application/json","preview":"{\"status\":\"up\",\"service\":\"metrics-collector\"}"}

10.0.18.60:9090 is not reachable from your Kali machine directly — only from inside the lab's 10.0.18.0/24 network. The preview field proves ReportForge, not you, made that request.

Sign in to continue

11 more sections are for signed-in members. It is free: sign in with Google.

Related