> 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-path-traversal-labs/lab-4.md).

# lab-4

## File Path Traversal, Traversal Sequences Stripped with Superfluous URL-Decode

**Difficulty:** Practitioner

### Lab Description

This lab contains a path traversal vulnerability in the display of product images. The application blocks input containing path traversal sequences, then performs a URL-decode of the input before using it.

**Objective:** Retrieve the contents of the `/etc/passwd` file.

### Root Cause

The application (or a proxy layer in front of it) blocks path traversal sequences such as `../` and `....//`. However, the blocking check is performed on the raw, encoded input, and the application then URL-decodes the input before passing it to the filesystem.

By double URL-encoding the traversal sequence, the encoded form passes the filter unrecognised. The application then decodes one layer, and if a second decode occurs before the file is opened, the traversal sequence is fully reconstructed and the attack succeeds.

For example:

* `../` → single-encoded: `%2e%2e%2f` → double-encoded: `%252e%252e%252f`

The filter sees `%252e%252e%252f` and finds no traversal sequence. The application decodes it to `%2e%2e%2f`, then to `../` before opening the file.

### Exploitation

1. Access the lab, open any product page, and open the image in a new tab.
2. Capture the request in Burp Suite.
3. Find the URL endpoint: `GET /image?filename=43.jpg`
4. Replace the filename value with the double URL-encoded traversal payload:

   ```
   ..%252f..%252f..%252f..%252fetc%252fpasswd
   ```
5. Send the request — the contents of `/etc/passwd` are returned in the response.

### Lesson Learned

Security checks must be applied to the fully decoded, normalised input — not to the raw encoded form. Any input that will be decoded before use must first be fully decoded, then validated. A proxy or WAF that inspects the encoded request but forwards a decoded version to the application creates exactly this gap.


---

# 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-path-traversal-labs/lab-4.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.
