I am currently practicing for a CTF competition and one of the practice challenges is a buffer overflow exploit. Before this challenge I knew absolutely nothing about these exploits, but I've been reading into them and trying to understand the basics.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void win(void)
{
system("cat flag.txt");
return;
}
int main(int argc, char *argv[])
{
printf("Give me some data: \n");
fflush(stdout);
char buffer[32];
gets(buffer);
printf("You entered %s\n", buffer);
fflush(stdout);
return 0;
}
So what I know so far is that I need to redirect to the win()
function and that there is a buffer of 32 characters. I broke down the program into assembly and found that the win()
function's address is 0x080484fd
. After that, I connected to the program's server and typed 32 characters and the function's address. The program only returned my input, and did not redirect to the win()
function. I did some more reading and tried doing it from another shell with the command:
sudo python -c 'print "a"*32 + "\x08\x04\x84\xfd"' >& /dev/pts/2
Sadly, this did not get me to the win()
function. What am I doing wrong? I've hit a total block and not sure what else to try. Any advice and help would be greatly appreciated.