Recently i was trying buffer overflow on a simple c code that has been shown in opensecuritytraining's exploit class 1. Here is the code
#include<stdio.h>
char *secret ="hello";
void go_shell()
{
printf("This is go_shell\n");
}
int authorize()
{
char password[64];
printf("Enter the password: ");
gets(password);
if(!strcmp(password,secret))
{
return 1;
}
else
return 0;
}
int main ()
{
if (authorize())
{
printf("Login ok!\n");
go_shell();
}
else
printf("Incorrect\n");
}
In this one when i enter more than 72 'A' then it starts to overwrite the rip part of the stack . This is the stack when i enter 73 'A' . In it the rip is saved at 0x7ffffffee308 and its being overwritten . This is the result on the overflow. But the problem is when i enter more than 78 'A' This is the stack when i give 78 'A' as input. This is Successfully overwritten rip This is when 79 'A' are given as input. Although stack is successfully overwritten but rip points to correct location . Why is this happening ? I am using ubuntu in wsl .