Skip to content
SQL injection Write-up Beginner

Bypassing Login via NoSQL Operator Injection: A MongoDB Authentic

A MongoDB-backed login endpoint accepted JSON objects in the username and password fields, so injected query operators were evaluated as query logic instead of plain strings. By supplying a regex operator for the username and a not-equal operator for the password, the author logged in as an administrator without knowing the credentials.

Aditya Bhatt Follow

Published on infosecwriteups.com

In this lab, I exploit a classic NoSQL injection vulnerability in a MongoDB-powered login system by injecting operators like $ne (Not Equal) and $regex. These operators allow me to bypass both the username and password fields — eventually gaining unauthorized admin access.

Aditya Bhatt, on infosecwriteups.com

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

Likely the server parsed user-supplied JSON directly into the MongoDB query object, so operator keys such as $ne and $regex were interpreted as query logic rather than literal string values.

Impact

An attacker could bypass authentication and log in as an administrator, which the author says could lead to account takeover, access to internal dashboards and full database compromise.

What the attacker needed

Access to the login endpoint; ability to send JSON request bodies

The fix

The application should type-check and sanitise incoming JSON so user input is never parsed directly as a query object, and authentication logic should not rely on raw NoSQL query evaluation.

How it was found

  1. Log in with the provided test credentials and capture the login request in the proxy history.
  2. Send the captured login request to Repeater to use as a baseline.
  3. Replace the password string with an equality operator object and confirm the login still succeeds.
  4. Replace the password with a not-equal operator object and confirm login succeeds without the real password.
  5. Try the administrator username with the not-equal password operator, then a list of admin variants, both of which fail.
  6. Use a regex operator matching usernames starting with admin together with the not-equal password operator to obtain a redirect and admin session.

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.

The login form sent the username and password as a structured data object rather than plain text. The server passed that object straight into a database query, so a value like 'not equal to empty' was treated as a rule instead of a password. That let the author match the admin account without knowing its 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.

More by Aditya Bhatt

View all

25 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.