Learn to exploit MongoDB operator injection in a login form to authenticate as an admin without valid credentials.
This lab demonstrates a real-world NoSQL injection vulnerability in a Flask-based e-commerce application. The ShoppingNow platform uses a vulnerable MongoDB query structure that allows attackers to bypass authentication using MongoDB operators like $ne
and $regex
.
- Identify NoSQL injection vectors in authentication endpoints
- Craft payloads using MongoDB operators ($ne and $regex)
- Bypass authentication to gain admin access
Beginner
20-30 minutes
- Basic web application penetration testing
- Familiarity with MongoDB query syntax
- Burp Suite or similar proxy tool
- Finding and exploiting NoSQL injection vulnerabilities
- Crafting JSON injection payloads
- Authentication bypass strategies
├── build/
│ ├── web/ # Flask application
│ │ ├── app.py # Main Flask application
│ │ ├── requirements.txt # Python dependencies
│ │ ├── templates/ # HTML templates
│ │ ├── static/ # Static assets
│ │ └── Dockerfile # Web container definition
│ └── db/
│ └── init/ # MongoDB initialization scripts
├── deploy/
│ ├── docker-compose.yaml # Production Docker configuration
│ └── metadata.json # Application metadata
├── docs/
│ └── WRITEUP.md # Detailed exploitation guide
├── test/
│ ├── test_lab.py # Automated tests
│ └── requirements.txt # Test dependencies
├── docker-compose.yml # Production with Docker Hub image
├── docker-compose.dev.yml # Development environment
└── README.md # This file
# Start development environment with local build
docker-compose -f docker-compose.dev.yml up --build
# Access the application
# Web: http://localhost:3206
# MongoDB: localhost:27017
# Start production environment with pre-built image
docker-compose up
# Access the application
# Web: http://localhost:3206
# Start MongoDB only
docker-compose -f docker-compose.dev.yml up mongodb -d
# Start web application
docker-compose -f docker-compose.dev.yml up web --build
- Customer: john_doe / password123
- Customer: jane_smith / jane123
- Admin: admin / admin_secret_2024 (hidden account)
The application uses a vulnerable MongoDB query structure in the login endpoint:
# Vulnerable query - directly uses user input without sanitization
query = {"username": username, "password": password}
user = db.users.find_one(query)
The find_one
method processes MongoDB operators directly, allowing injection attacks.
Run the automated tests to verify the vulnerability:
cd test
pip install -r requirements.txt
python test_lab.py
Or run with pytest:
pytest test_lab.py -v
The flag is displayed in the admin dashboard after successful exploitation:
FLAG{NoSQL_1nj3ct10n_4dm1n_byp4ss_2024}
This lab is compatible with ARM architectures (Apple Silicon, ARM64) using MongoDB 4.4 which doesn't require AVX support.
- Development: Built locally from
build/web/Dockerfile
- Production: Available on Docker Hub as
cyberctf/nosql-injection-lab-login:latest
Report issues at: https://github.com/your-org/shoppingnow-lab/issues
This is a deliberately vulnerable lab designed solely for educational purposes.