📕 FIELD MANUAL 15.1: SQL TRUNCATION (THE DOPPELGÄNGER ATTACK)
Objective: We will hijack privileged accounts (Admin) by exploiting database column length limits, without using quotes or...
Classification: RED TEAM EYES ONLY
Objective: We will hijack privileged accounts (Admin) by exploiting database column length limits, without using quotes or classic SQL syntax.
MITRE ATT&CK: T1078 (Valid Accounts).
1. INTEL & RECON: THE PHYSICS OF SPACE
Sección titulada «1. INTEL & RECON: LA FÍSICA DEL ESPACIO»Databases define limits. E.g.: username VARCHAR(20).
MySQL (in default configurations) has a critical peculiarity: It will truncate excess characters without throwing an error.
The Attack Logic:
Sección titulada «La Lógica del Ataque:»- There is a user
admin. - We want to log in as them, but we do not have their password.
- We will create a new user that, for MySQL, is identical to the admin.
The Space Trick:
For MySQL, the string "admin" is equal to "admin " (ignores trailing spaces in comparisons).
2. WEAPONIZATION: CREATING THE IMPOSTOR
Sección titulada «2. WEAPONIZATION: CREANDO AL IMPOSTOR»STEP 1: Identifying the Limit
Sección titulada «PASO 1: Reconocimiento del Límite»We will try to register with a very long username to see if it gets truncated or throws an error. Let's assume we discover that the limit is 20 characters.
STEP 2: The Registration Payload
Sección titulada «PASO 2: El Payload de Registro»We will register with the following username:
admin x(Note: “admin” + 14 spaces + “x” = 20 characters).
STEP 3: Truncation (Server-Side)
Sección titulada «PASO 3: El Truncado (Server-Side)»- The App will receive:
admin x(Length 20). - The App will check: “Does this user exist?” -> No. (Because
admin...xis not equal toadmin). - The App will insert:
INSERT INTO users (user, pass) VALUES ('admin...x', 'pass123'). - MySQL Truncates: Since the field is
VARCHAR(20), it will cut off the finalxif it exceeds the limit (or if we adjust the spaces perfectly to the limit).- What will actually be saved:
admin
- What will actually be saved:
STEP 4: Access (Login)
Sección titulada «PASO 4: El Acceso (Login)»- We will go to the Login.
- Username:
admin x(Our long username). - Password:
pass123(Our password). - The App will look for:
SELECT * FROM users WHERE user = 'admin...x'. - Match: MySQL will compare our input with the stored value (
admin...). They will match! - The App will log us in as a user.
- Impact: Since the system will see that the user is named
admin(spaces will be ignored), it will grant us the privileges of the original Administrator.
3. PURPLE TEAM VIEW (DEFENSE)
Sección titulada «3. PURPLE TEAM VIEW (DEFENSA)»- Defense: We will enable
STRICT_TRANS_TABLESin MySQL (strict mode) so that it throws an error instead of silently truncating. - Validation: We will verify the input length in the code (Backend) before sending it to the database.

