> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/cybersecurity-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-nosqli-labs/lab-1.md).

# lab-1

## Detecting NoSQL Injection

**Difficulty:** Apprentice

### Lab Description

The product category filter for this lab is powered by a MongoDB NoSQL database and is vulnerable to NoSQL injection.

**Objective:** Perform a NoSQL injection attack that causes the application to display unreleased products.

### Solution

**Step 1 — Identify the injection point**

Navigate to the lab and select a product category, for example **Gifts**. Only a few products are listed. According to the objective, there are unreleased products hidden by the query — the goal is to break out of the filter to expose them.

Capture the category filter request in Burp Suite.

**Step 2 — Confirm the vulnerability**

Test the input with special characters to see if the backend query can be broken:

```
'"`{;$Foo}$Foo \xYZ
```

Injecting a single quote `'` triggers a syntax error, confirming that the input is being passed directly into the query without sanitization. The backend query likely looks something like:

javascript

```javascript
db.filter.find({ "category": 'gifts' })
```

Injecting `gifts'` breaks this into:

javascript

```javascript
db.filter.find({ "category": 'gifts'' })
```

...which is invalid syntax, causing the error.

**Step 3 — Bypass the filter with a tautology**

To dump all products (including unreleased ones), inject a condition that is always true using the MongoDB `||` operator:

```
gifts' || '1'=='1
```

The resulting backend query becomes:

javascript

```javascript
db.filter.find({ "category": 'gifts' || '1'=='1' })
```

Since `'1'=='1'` is always true, the query returns all documents in the collection regardless of their category or release status.

### Conclusion

The application passed user-supplied input directly into a MongoDB query without sanitization, allowing a simple tautology injection to bypass the category filter and expose unreleased products.


---

# 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://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-nosqli-labs/lab-1.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.
