Skip to content
SQL injection Write-up Intermediate

Field Enumeration to Full Account Takeover with NoSQL Injection

A NoSQL injection flaw in a MongoDB-backed login allowed an attacker to inject operators like $ne and $where, bypass authentication checks, enumerate hidden user fields, and extract a password reset token. This led to full account takeover by resetting the victim's password.

medium.com

Published on medium.com

This lab demonstrates a NoSQL injection vulnerability in a MongoDB-backed login system. By abusing MongoDB operators like $ne and $where, we can bypass authentication checks, enumerate hidden user fields, and finally extract a password reset token to hijack an account.

Aditya Bhatt, on medium.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 application passed user-supplied JSON directly into a MongoDB query without sanitising operators like $ne and $where, allowing query manipulation.

Impact

An attacker could take over the victim's account by extracting a password reset token and resetting the password.

What the attacker needed

Access to the lab environment; Burp Suite or similar tool; victim account exists

How it was found

  1. Try to sign in with username carlos and a random password, intercept the login request.
  2. Send the intercepted POST /login request to Repeater with a JSON body containing username and password.
  3. Replace the password value with a MongoDB not-equal operator to test for injection.
  4. Add a $where parameter set to false (0) and observe the response.
  5. Change the $where parameter to true (1) and observe the response.
  6. Use Intruder with a $where payload to enumerate user document fields by index.

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 system built its database query directly from user input without proper checks. An attacker could send special database commands instead of a normal password, which let them ask the database questions and eventually steal a secret token used to reset the victim's 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.

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.