I've been trying for some time to write an exploit to a very simple program which has a format string and a buffer overflow vulnerability. This program has NX, SSP and ASLR.
#include <stdio.h>
int main(int argc, char *argv[]){
char buff[64];
printf(argv[1]);
printf("\n");
gets(buff);
return 0;
}
I successfully bypassed this 2 first one's, but I can't beat ASLR.
NOTE: Bruteforce isn't an option
My idea is to leak a libc function and subtract the offset, but I don't know how to do it with a format string vulnerability. Also, I must say that null-bytes can't be written, as input is got from the arguments.
Questions:
Is this even exploitable?
If it is, how can I leak a GOT/PLT entry for calculating the libc base address?
I'm on the right track?
mainreturn to?__libc_start_mainis in libc, and you can readmain's retaddr via format string (same way as I presume you leak the stack canary). Now you have a libc addr, subtract the offset to get the base.