> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/es/web/file-upload/web-shell-via-race-condition.md).

# Web shell mediante condición de carrera

Notas sobre Web shell mediante condición de carrera para los laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payload, validación en Burp Suite y contexto de mitigación.

### Carga de web shell mediante condición de carrera

**Objetivo del laboratorio**

Esta práctica cuenta con una función de subida de imágenes con una validación aparentemente robusta. / Sin embargo, es posible eludir esta validación utilizando una **condición de carrera** durante el procesamiento del archivo.

El objetivo es subir una web shell en PHP y luego usarla para leer el archivo sensible:/ `/home/carlos/secret`.

**Contexto**

* Autenticación posible con: `wiener:peter`
* Solo **JPG** y **PNG** están permitidos
* La respuesta del servidor tarda unos **1 a 2 segundos**, lo que sugiere un procesamiento asíncrono explotable

**Intento inicial**

Intenta subir un archivo PHP clásico:

```php
?php
system($_GET['cmd']);
?>
```

Resultado:

* Rechazo del servidor
* Mensaje que indica que solo se aceptan archivos JPG y PNG

{% hint style="danger" %}
Lo siento, solo se permiten archivos JPG y PNG. Lo siento, hubo un error al cargar tu archivo.
{% endhint %}

**Observación clave**

Un **período de tiempo perceptible** existe entre:

1. Cuando el archivo se escribe en el disco
2. Cuando la validación se completa y el archivo posiblemente se elimina

Este período de tiempo abre la puerta a una condición de carrera.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-58f5153a5954da48382a53905ff8121a9cff4f83%2F%7BBCD59826-AE27-4A5D-9DA9-58B8B364B135%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Funcionamiento de la condición de carrera**

Lanza un ataque con **Intruder** (o una herramienta equivalente)

* Entrega repetitiva y rápida de la solicitud de descarga
* Carga útil nula o repetitiva, ejecución en bucle

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b4619012c7761f24510d9e07d5c0c33026feda5f%2F%7B4B4B4B94-EF40-47BB-8775-257EFA76076D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Mientras el servidor procesa las cargas:

* Actualiza continuamente la URL del supuesto archivo

```bash
/files/avatars/cmd.php?cmd=whoami
```

En algún momento, el archivo es accesible **antes de** que la validación lo invalide

* El código PHP es entonces interpretado por el servidor

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7bf4a5ebd209db51eaaf076f6b14b8b020e5c72f%2F%7B3062563A-C86B-48E3-8D98-A81862460BB1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Explotación de la web shell**

Una vez ejecutado, puedes leer el archivo secreto:

```bash
/files/avatars/cmd.php?cmd=cat /home/carlos/secret
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-77274839a5eb86f41ea797d0d40b0ddb7c71c106%2F%7BD67F309F-B210-4E8D-9911-620183C6F16A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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://hacking-notes.jord4n.pro/es/web/file-upload/web-shell-via-race-condition.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.
