Quizploit writeup

Descripción
Solve the quiz.
Download the source code to answer questions here.
Download the binary to answer questions here.
Quizploit solución
Descargamos ambos archivos y lanzamos la instancia:
nc lonely-island.picoctf.net 54753
Al conectarnos al servidor encontraremos el siguiente banner junto con unas preguntas:

Para responderlas, deberemos de examinar los archivos descargados:
1.- Is this a ’32-bit’ or ’64-bit’ ELF? (e.g. 100-bit)
file vunl
Este comando nos mostrará que el ejecutable es de 64 bits.
2.- What’s the linking of the binary? (e.g. static, dynamic)
codium vuln.c
Con este comando, veremos el código fuente. Dentro de él, podremos ver dos librerías enlazadas, stdio.h y stdlib.h, por lo que la respuesta es dynamic.
3.- Is the binary ‘stripped’ or ‘not stripped’?
gdb vuln
Al ejecutar este comando se nos mostrará ‘(No debugging symbols found in vuln)’, por lo que la respuesta es ‘not stripped’.
4.- Looking at the vuln() function, what is the size of the buffer in bytes? (e.g. 0x10)
codium vuln.c
Dentro del código del programa, tendremos la respuesta en la línea 17:
char buffer[0x15] = {0};
0x15.
5.- How many bytes are read into the buffer? (e.g. 0x10)
codium vuln.c
Dentro del código del programa, tendremos la respuesta en la línea 19:
fgets(buffer, 0x90, stdin);
0x90.
6.- Is there a buffer overflow vulnerability? (yes/no)
Como 0x90 es mayor que 0x10, la respuesta es yes.
7.- Name a standard C function that could cause a buffer overflow in the provided C code.
La respuesta es fgets, dado que introduce en la variable buffer, de tamaño 0x10 0x90 bytes de información.
8.- What is the name of function which is not called any where in the program?
La respuesta es win, dado que en ninguna parte de main se llama a esta función.
9.- What type of attack could exploit this vulnerability? (e.g. format string, buffer overflow, etc.)
La respuesta, como se respondió anteriormente, es buffer overflow.
10.- How many bytes of overflow are possible? (e.g. 0x10)
Para realizar esto, usaremos Cyberchef, con la receta ‘From Hex’ y ‘To Decimal’. Obtendremos que 0x90 es 144 y que 0x15 es 21 en decimal. Al restar ambos números obtendremos los bytes de overflow:
123.
11.- What protection is enabled in this binary?
Para ver las protecciones de este ejecutable usaremos checksec como indica la pista:
checksec --file=vuln

La única protección que está habilitada es ‘Not eXecutable’, NX.
12.- What exploitation technique could bypass NX? (e.g. shellcode, ROP, format string)
De todos los ejemplos que nos han proporcionado:
- Shellcode: Es código máquina que el atacante introduce en memoria después de ejecutar el archivo, por lo que no nos aplica.
- ROP (Return-Oriented Programming): Reutiliza pequeños trozos de instrucciones que ya existen en memoria ejecutable, encadenándolas con direcciones de retorno, podría realizar un bypass de NX.
- Format string: Permite leer memoria o modificar valores en memoria, pero no realizaría un bypass de NX.
En este caso, la respuesta es ROP.
13.- What is the address of ‘win()’ in hex? (e.g. 0x4011eb)
Para responder a esta pregunta, lanzaremos ghidra:
ghidra
Una vez que la interfaz haya cargado, crearemos un proyecto, importaremos el archivo ‘vuln’ y dejaremos que ghidra lo analice. Cuando termine, con Ctrl + F buscaremos ‘win’, obteniendo su dirección de memoria:

0x401176.
Con esto, habremos resuelto el CTF:

Consultor de ciberseguridad especializado en continuidad de negocio y respuesta ante incidentes. Interesado en analizar tecnologías desde una perspectiva de seguridad y descubrir su comportamiento real.
