SQL Injection Fundamentalsf
MySQL
Intro to MySQL
Preguntas
Connect to the database using the MySQL client from the command line. Use the 'show databases;' command to list databases in the DBMS. What is the name of the first database?
mysql --skip-ssl -h 94.237.50.221 -P 33445 -u root -p
SQL Statements
What is the department number for the 'Development' department?

Query Results
What is the last name of the employee whose first name starts with "Bar" AND who was hired on 1990-01-01?

SQL Operators
In the 'titles' table, what is the number of records WHERE the employee number is greater than 10000 OR their title does NOT contain 'engineer'?

SQL Injections

Subverting Query Logic
'
%27
"
%22
#
%23
;
%3B
)
%29
Preguntas
Try to log in as the user 'tom'. What is the flag value shown after you successfully log in?

Using Comments
Preguntas
Login as the user with the id 5 to get the flag.

Union clauses
Preguntas
Connect to the above MySQL server with the 'mysql' tool, and find the number of records returned when doing a 'Union' of all records in the 'employees' table and all records in the 'departments' table.

Union Injection
Preguntas
Use a Union injection to get the result of 'user()'
Primero vemos cuántas columnas son.
Ahora hacemos que nos imprima en una columna el resultado.

Exploitation
Database Enumeration
Preguntas
What is the password hash for 'newuser' stored in the 'users' table in the 'ilfreight' database?
Primero vemos cuántas columnas.
Como ya sabes que la consulta tiene 4 columnas y la página imprime las columnas 2, 3 y 4, usamos este UNION.

Reading Files
Preguntas
We see in the above PHP code that '$conn' is not defined, so it must be imported using the PHP include command. Check the imported page to obtain the database password.
Primero vemos cuántas columnas.
Como ya sabes que la consulta tiene 4 columnas y la página imprime las columnas 2, 3 y 4, usamos esto.

Al decodificarlo en base64 sale el siguiente código.
Vamos a leer /var/www/html/config.php con LOAD_FILE() vía UNION y, para que no se renderice HTML/PHP raro, lo envolvemos en Base64.

Ahora lo decodificamos y nos sale lo siguiente.
Writing Files
Preguntas
Find the flag by using a webshell.
Primero subimos la webshell en Base64.

Buscamos en el navegador.

Buscamos entonces dónde se encuentra la flag.

Mostramos contenido.

Skills Assessment
Assess the web application and use a variety of techniques to gain remote code execution and find a flag in the / root directory of the file system. Submit the contents of the flag as your answer.
Nos encontramos un panel de login y lo bypasseamos con una inyección básica.
Estamos dentro.

Vamos a ver cuántas columnas tiene.

Sabiendo el número de columnas (5) vamos a enumerar los usuarios.

Ya sabemos el usuario por lo que hay que ver que privilegios tiene.

Vemos que tenemos permiso en FILE y eso indica que puede tanto escribir y leer en el backend. Comprobamos secure_file_priv si podemos escribir datos.

Eso significa que podemos escribir datos por lo que hacemos una web shell.

Nos salta un error pero de las tres condiciones necesarias, el usuario ya cuenta con el privilegio FILE habilitado y además la variable global secure_file_priv de MySQL no está activa, por lo que el problema debe encontrarse en la tercera condición, es decir, en la falta de permisos de escritura en la ubicación del servidor donde se pretende guardar el archivo.

Accedemos a la web shell.

Listamos los archivos.

Mostramos el contenido de la flag.

Last updated
Was this helpful?