> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/cybersecurity-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-ssrf-lab/lab-3.md).

# lab-3

## SSRF with Blacklist-Based Input Filter

**Difficulty:** Practitioner

### Lab Description

This lab has a stock check feature which fetches data from an internal system. The developer has deployed two weak anti-SSRF defences that must be bypassed.

**Objective:** Change the stock check URL to access the admin interface at `http://localhost/admin` and delete the user `carlos`.

### Root Cause

Some applications defend against SSRF by blacklisting known-bad values such as `127.0.0.1`, `localhost`, or `/admin`. However, these defences are fundamentally unreliable because the same destination can be represented in many valid forms that are not in the blacklist. For example, if `127.0.0.1` is blocked, alternatives such as `127.1` or `2130706433` (the decimal representation) may not be. Similarly, if the backend is case-insensitive, using `ADMIN` instead of `admin` may bypass a string-match filter, ultimately allowing access to the same internal infrastructure.

### Exploitation

1. Access any product page and find the **stock check** functionality. Click it and capture the request in Burp.
2. Find the `POST /product/stock` endpoint and send it to Repeater.
3. Change the `stockApi` parameter to `http://127.1/ADMIN` and send the request. This bypasses both the `localhost`/`127.0.0.1` block (using the shortened notation `127.1`) and the `/admin` block (using uppercase `ADMIN` on a case-insensitive server).
4. Open the response in the browser — the admin panel is accessible.
5. Click **Delete carlos** and note the URL path: `/admin/delete?username=carlos`.
6. Back in Repeater, set the `stockApi` parameter to:

   ```
   http://127.1/ADMIN/delete?username=carlos
   ```
7. Send the request — `carlos` is deleted and the lab is complete.

### Lesson Learned

* Blacklists are unreliable because the same destination can be represented in multiple valid ways — different IP notations, encoded inputs, hostnames, or redirects.
* Simply blocking strings like `127.0.0.1`, `localhost`, or `/admin` does not guarantee SSRF protection.
* Attackers can exploit differences in URL parsing, normalisation, DNS resolution, or redirect handling to reach blocked destinations.
* Allowlisting trusted destinations is far more effective than trying to enumerate every dangerous one.
* Applications should: normalise and validate the URL before applying security checks; resolve hostnames and verify the final IP is not loopback, private, or link-local; re-validate after following redirects or disable redirects where unnecessary; and restrict outbound network access at the infrastructure level so that even a successful SSRF cannot reach sensitive internal resources.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-ssrf-lab/lab-3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
