Question: Stack canaries and non - executable stacks make stack exploitation difficult. Such techniques, however, do not protect against return - oriented programming where only the

Stack canaries and non-executable stacks make stack exploitation difficult. Such techniques, however, do not protect against return-oriented programming where only the return addresses on the stack are targeted. In this level, you control a single write into a vulnerable buffer in the function prompt_user. Overflow the buffer to modify the return address beyond the stack canary so that it points to a function of your choice. The level will prompt you with an offset (in decimal) from the beginning of the buffer that will be written into followed by a hexadecimal value that will be written there (e.g. scanf("%d %x");). The program will then write the hexadecimal value to a location computed using the offset. To determine how close you are, examine the pointer being used to write into the stack and how far away it is from the value of $rsp when the retq instruction at the end of prompt_user is reached.
The .c file:
#include
#include
#include
#include
#define USERDEF 44
char msg[]=
"Stack canaries and non-executable stacks make stack exploitation difficult. Such
"
"techniques, however, do not protect against return-oriented programming where
"
"only the return addresses on the stack are targeted. In this level, you control
"
"a single write into a vulnerable buffer in the function prompt_user. Overflow
"
"the buffer to modify the return address beyond the stack canary so that it
"
"points to a function of your choice. The level will prompt you with an offset
"
"(in decimal) from the beginning of the buffer that will be written into followed
"
"by a hexadecimal value that will be written there (e.g. scanf(\"%d %x\");).
"
"The program will then write the hexadecimal value to a location computed
"
"using the offset. To determine how close you are, examine the pointer
"
"being used to write into the stack and how far away it is from the value
"
"of $rsp when the retq instruction at the end of prompt_user is reached.
";
void print_good(){
printf("Good Job.
");
exit(0);
}
void segv_handler(int sig){
printf("Segmentation fault. Try again.
");
exit(0);
}
void print_msg(){
printf("%s",msg);
}
void prompt_user(){
char buffer[44];
int offset;
char *user_addr;
char **over_addr;
printf("Enter the password: ");
scanf("%d %lx", &offset, (unsigned long *) &user_addr);
over_addr =(char **)(buffer + offset);
*over_addr = user_addr;
}
int main(int argc, char *argv[]){
signal(SIGSEGV, segv_handler);
print_msg();
prompt_user();
printf("Try again.
");
return 0;
}
I've tried "440x0000000000401176" and "440x401176" and "450x0000000000401176" and "450x401176".
Stack canaries and non - executable stacks make

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!