> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/offensive-security-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/offensive-security-writeups/port-swigger-file-upload-labs/lab-1.md).

# lab-1

## Remote Code Execution via Web Shell Upload

**Difficulty:** Apprentice

### Lab Description

This lab contains a vulnerable image upload function. It performs no validation on uploaded files before storing them on the server's filesystem.

**Objective:** Upload a basic PHP web shell and use it to exfiltrate the contents of `/home/carlos/secret`. Submit the secret using the button in the lab banner.

**Credentials:** `wiener:peter`

### Root Cause

The developers added no defence against malicious file uploads. With no validation of the filename, extension, or content type, an attacker can upload any file — including a PHP script — and have it stored and served by the server, leading to remote code execution and arbitrary command execution.

### Exploitation

1. Log in as `wiener:peter` and navigate to the account page.
2. Create a file named `php.php` with the following content:

   ```php
   <?php echo file_get_contents('/home/carlos/secret'); ?>
   ```
3. Upload `php.php` as the avatar.
4. Right-click the avatar and select **Open image in new tab** — the server executes the PHP file and the secret is returned in the response.
5. Submit the secret to complete the lab.

### Lesson Learned

Never leave a file upload feature without defences. Accepting files with no validation of filename, extension, or content type allows an attacker to upload and execute arbitrary server-side scripts, leading to remote code execution.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ganesha-hk.gitbook.io/offensive-security-writeups/port-swigger-file-upload-labs/lab-1.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
