I am currently trying to make a code more safe for a cybersecurity exercise. I was asked to make the flag contained in the secret_function() come out. The problem is that I can't modify the code and that I don't see how I can give the address of the secret_function() as the value of the function_ptr(). The only hint we were given is that a buffer_overflow might help, even though I don't understand how.
I tried multiple values, but the only thing I was able to achieve was a segfault when I exceeded 10 characters due to the buffer limit. Here is the code of the functions involved:
void secret_function ()
{
printf ("{The stone isn't in the pocket anymore ...}\n");
}
void monitor_radiation_levels ()
{
char buffer[10];
void (* function_ptr) () = NULL;
printf ("Enter radiation levels: ");
gets (buffer);
printf ("Radiation Levels: %s\n" ,buffer);
if (function_ptr){
function_ptr();
} else {
printf ("Function Pointer: %p\n",( void * ) function_ptr);
}
}
bufferandfunction_ptrfor starters. Maybe you can't do it this way because they are laid out in memory not as you are expecting.