I'm currently trying out a simple format string vuln exploit. The target program looks like this:
int main(int argc, char *argv[])
{
char buffer[1024];
strncpy(buffer, argv[1], sizeof(buffer));
printf(buffer);
}
My goal is to use the format string to overwrite the return address and make it point to a shellcode which is placed on the buffer itself. There's no DEP nor ASLR, and I can run the binary as many times as I need.
However, I'm having an issue with the placement of the shellcode itself. If the buffer has the shellcode placed before the %Nu%n
sequence, I won't know how many characters have been printed before I get to the first %n
, since the shellcode will contain non-printable characters. If it's placed after it, I won't know the address of the shellcode itself, since the amount of digits for each N may vary. It's kind of a Catch-22.
How can I solve this without placing the shellcode somewhere other than the buffer itself?