If you're using the example code from the book (below), at some point you should reach the "AAAAAAAA" pattern (0x41). Note that, since you're running it on a 64-bit machine that stores elements in the stack with 8 bytes each, you should run it with $ ./fmtstr "AAAAAAAA %016x %016x %016x %016x %016x %016x %016x %016x %016x %016x %016x %016x %016x"
instead, or you will miss part of each element on the stack.
#include <stdlib.h>
int main(int argc, char *argv[]){
static int canary=0; // stores the canary value in .data section
char temp[2048]; // string to hold large temp string
strcpy(temp, argv[1]); // take argv1 input and jam into temp
printf(temp); // print value of temp
printf("\n"); // print carriage return
printf("Canary at 0x%08x = 0x%08x\n", &canary, canary); //print canary
}
You should pay attention to the quote in the book that states:
The fact that the fourth item shown (from the stack) was our format string depends on the nature of the format function used and the location of the vulnerable call in the vulnerable program. To find this value, simply use brute force and keep increasing the number of %08x tokens until the beginning of the format string is found. For our simple example (fmtstr), the distance, called the offset, is defined as 4.
Remember that the parameter being parsed to printf
isn't the string itself, but the address of the string. So it's position on the memory layout of the program in relation to the printf
stack is what will define how further you'll have to search to find it.