I am a beginner at buffer overflows been studying this subject from a few days and i found this exercise (code from: here)
I think understand the basic concept i write more than 64 bytes characters and the gets function overflows the next address on the stack because it cannot determine the length of my chars and i overwrite the next address with a location of my choice which the esp executes am i right ?
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
void win()
{
printf("code flow successfully changed\n");
}
int main(int argc, char **argv)
{
volatile int (*fp)();
char buffer[64];
fp = 0;
gets(buffer);
if(fp) {
printf("calling function pointer, jumping to 0x%08x\n", fp);
fp();
}
}
Following the code i use the printf command in the terminal
printf "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqbqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\xca\x06" | ./ex3
i get the segfault which i am supposed to and the printf in the program shows me that i am overwriting with the proper address
(gdb) x win
0x6ca <win>: 0xe5894855
terminal:
calling function pointer, jumping to 0x000006ca
Segmentation fault