From Recon to Root: A MongoDB NoSQL Injection Bug Bounty Journey
A user lookup endpoint concatenated user input into a MongoDB query, allowing Boolean-based NoSQL injection. An attacker could enumerate the administrator's password character by character and log in as that user.
medium.com
Published on medium.com
In this walkthrough, I exploit a NoSQL injection vulnerability to extract the administrator’s password from a web app using MongoDB as its backend. The lab titled “Exploiting NoSQL injection to extract data” is a part of PortSwigger’s Web Security Academy, which mimics real-world vulnerabilities encountered during bug…
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 concatenated the user parameter into a MongoDB query string, so injected JavaScript operators were evaluated server-side.
Impact
An attacker could extract the administrator's password and take over the account.
What the attacker needed
A low-privilege account; access to the user lookup endpoint; Burp Suite or similar tool
The fix
The application should use parameterized queries or otherwise avoid concatenating user input into NoSQL queries, and add input validation and rate limiting.
How it was found
- Log in with the provided low-privilege account and monitor requests in Burp.
- Send the user lookup request to Repeater.
- Inject a single quote in the user parameter and observe the response still returns user details.
- Test Boolean false and true conditions to confirm injection.
- Use Intruder to brute-force the password length via this.password.length.
- Use Intruder to extract each password character via this.password[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 web app built a database query by gluing the user's input directly into it. By sending special characters that change the query's logic, an attacker could ask true/false questions about the admin's password and slowly guess it one character at a time. This is called NoSQL injection because it targets a non-SQL database like MongoDB.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.