> 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/fr/web/file-upload/web-shell-by-race-condition.md).

# Web shell via une condition de concurrence

### Téléversement d'un web shell via une condition de concurrence

**Objectif du labo**

Ce labo propose une fonctionnalité de téléversement d’image avec une validation apparemment robuste. / Cependant, il est possible de contourner cette validation en utilisant une **condition de concurrence** pendant le traitement du fichier.

L’objectif est de téléverser un web shell PHP, puis de l’utiliser pour lire le fichier sensible :/ `/home/carlos/secret`.

**Contexte**

* Authentification possible avec : `wiener:peter`
* Seuls **JPG** et **PNG** les fichiers sont autorisés
* La réponse du serveur prend environ **1 à 2 secondes**, ce qui suggère un traitement asynchrone exploitable

**Première tentative**

Essayez de téléverser un fichier PHP classique :

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

Résultat :

* Refus du serveur
* Message indiquant que seuls les fichiers JPG et PNG sont acceptés

{% hint style="danger" %}
Désolé, seuls les fichiers JPG et PNG sont autorisés. Désolé, une erreur s'est produite lors du téléversement de votre fichier.
{% endhint %}

**Observation clé**

Un **période de temps perceptible** existe entre :

1. Quand le fichier est écrit sur le disque
2. Quand la validation est terminée et que le fichier est éventuellement supprimé

Cette période ouvre la voie à une condition de concurrence.

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

**Fonctionnement de la condition de concurrence**

Lancez une attaque avec **Intruder** (ou un outil équivalent)

* Envoi répétitif et rapide de la requête de téléchargement
* Charge utile nulle ou répétitive, exécution en boucle

<figure><img src="/files/635753e6601981fd39296846b76bcb69c39f3a51" alt=""><figcaption></figcaption></figure>

Pendant que le serveur traite les téléversements :

* Actualisez en continu l’URL du fichier supposé

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

À un moment donné, le fichier est accessible **avant** la validation l’invalide

* Le code PHP est alors interprété par le serveur

<figure><img src="/files/66f76c69e7286adb62ca5673a7e6d870c5776dc6" alt=""><figcaption></figcaption></figure>

**Exploitation du web shell**

Une fois exécuté, vous pouvez lire le fichier secret :

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

<figure><img src="/files/fd08a08ec8c9af1c7c11ec7a653ac9126c0e8d25" 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/fr/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.
