Here is a simple CTF challenge with BOF exploiting.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key){
char overflowme[32];
printf("overflow me : ");
gets(overflowme); // smash me!
if(key == 0xcafebabe){
system("/bin/sh");
}
else{
printf("Nah..\n");
}
}
int main(int argc, char* argv[]){
func(0xdeadbeef);
return 0;
}
Obviously gets is vulnerable here. But the target binary is compiled with canary code, so we cannot just overflow the buffer. We have to know canary beforehand. How it is possible without format string leak? The only way i see here is stupid brute force.