> 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-by-race-condition.md).

# Web shell por condición de carrera

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

**Objetivo del laboratorio**

Este laboratorio presenta una función de carga de imágenes con una validación aparentemente robusta. / Sin embargo, es posible eludir esta validación usando una **condición de carrera** durante el procesamiento del archivo.

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

**Contexto**

* Autenticación posible con: `wiener:peter`
* Solo **JPG** y **PNG** se permiten archivos
* La respuesta del servidor tarda aproximadamente **de 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 sentimos, solo se permiten archivos JPG y PNG. Lo sentimos, se produjo un error al subir su 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="/files/d01e84bfef434f54a2aa80524acd6ba072f4b8dd" alt=""><figcaption></figcaption></figure>

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

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

* Envío repetitivo y rápido de la solicitud de descarga
* Carga útil nula o repetitiva, ejecución en bucle

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

Mientras el servidor procesa las cargas:

* Refresca continuamente la URL del archivo supuesto

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

En algún momento, el archivo es accesible **antes** la validación invalida

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

<figure><img src="/files/4c42f4d23c541ef563e48e6d3840d0cfc160cf3b" alt=""><figcaption></figcaption></figure>

**Explotación de web shell**

Una vez ejecutado, puedes leer el archivo secreto:

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

<figure><img src="/files/510198a6803dd6d968612e2abecfd5db0d348f07" 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 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://hacking-notes.jord4n.pro/es/web/file-upload/web-shell-by-race-condition.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.
