NoSQL Injection
The application failed to validate that username and password fields were strings, allowing an attacker to supply MongoDB query operators such as $gt to bypass authentication. This could let an attacker log in as the first user in the database, likely an administrator.
Published on blog.websecurify.com
What I would like to show you is a simple technique that can be effectively used against modern web applications, such as those written on top of NodeJS and MongoDB. In essence, this technique is very similar to SQL Injection (SQLI) although much simpler because we do not have to complete any weird and complicated…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The application passed user-controlled input directly into a MongoDB query without validating that the input was a string, allowing query operators to be injected.
Impact
An attacker could bypass authentication and log in as the first user in the database, which is probably the administrator.
What the attacker needed
None
How it was found
- Send a POST request with a JSON body containing username and password fields set to an object with a $gt operator and an empty string value.
- The server deserialises the JSON and uses the objects directly in the MongoDB query.
- The query matches the first user in the database, bypassing authentication.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When a website checks your login, it compares what you typed with what is stored. Here, the website accepted not just text but also special instructions that change how the comparison works. By sending a special instruction instead of a password, the attacker made the check always succeed, so they could log in without knowing the real password.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.