I am trying to test this example from StackOverflow (how-can-i-invoke-buffer-overflow), but I am not having success.
I also asked for clarification two weeks ago, directly on the post (through a comment) but there was still no answer (perhaps too old, 2010).
I am asking for a parsimoniously way of make this work: compiler options, operating system configuration, if necessary changing the code to make it compliant with today's process/memory layout or able to surpass, by the least, today's security OS protections.
I tried my own guesses but nothing seems to work.
I would like to avoid continuing doing superstitious attempts (compiler options that have nothing to do, operating system tinkering that has nothing to do) and opted to ask here if an expert or a well informed person come up with a proposal or at least points to a promising path.
My result:
$ gcc overflow.c
$ ./a.out
now inside f()!
Result supposed to happen:
nils@doofnase:~$ gcc overflow.c
nils@doofnase:~$ ./a.out
now inside f()!
now inside g()!
now inside g()!
now inside g()!
now inside g()!
now inside g()!
now inside g()!
Segmentation fault
Code:
#include <stdio.h>
#include <stdlib.h>
void g()
{
printf("now inside g()!\n");
}
void f()
{
int i;
void * buffer[1];
printf("now inside f()!\n");
// can only modify this section
// cant call g(), maybe use g (pointer to function)
// place the address of g all over the stack:
for (i=0; i<10; i++)
buffer[i] = (void*) g;
// and goodbye...
}
int main (int argc, char *argv[])
{
f();
return 0;
}
My machine:
x86_64 GNU/Linux
6.10.9-amd64
f()next to each other in memory, e.g. as local variables inmain. Fill the array with pointers tog(), writing out-of-bounds by 1 (above or below, depending on the implementation), which should overwrite the pointer tof(). Calling the function that pointer points to should then callg().int i; void (*fpointers [2]) (); void (*pf) () = f; for (i=0; i<10; i++) { pf(); fpointers[i] = (void*) g;}Worked:$ ./a.out now inside f()! now inside f()! now inside f()! now inside g()!. I don't know if this was your exact idea. Although (correct me if I am wrong please), has nothing to do with the stack/overwritting-return-addreses. Is taking advantage in an elegant way of a BO but directly in .data segment? .bss segment? Your example was very simple but ultra clarifying although avoids the stackmain()has its own stack :) Mixing with static concepts like.dataor.bssthat are layouts in files (declarations for the compiler) but not in memory. Then, in memory, all starts withmain()stack. Local things tomain()reside there and function/routine stacks (like the ones forf(),g()), derive frommain()stack calls. Right?