Jan 1, 1

In Linux operating systems, the function prologue is the one in charge of creating the canary and adding it to the stack. The epilogue is the one in charge of comparing the canary.

Let’s see the stack layout:

1
2
3
4
5
[...] -> 0xffffffff
RET ADDRESS 
BASE EBP
CANARY
VALUE -> 0x00000000

Canary is after base EBP and return address, in order to guard them both. Note: Canary first byte is always null byte -> The printf function cannot be exploited to leak the canary. Libc stores canary info in its own libc memory space, unless threads are created. In that case, the canary is independent per thread and each thread has its own stack canary.

Ideas to bypass stack canary:

How to leak libc base address to bypass ASLR

Note: libc calls our “main” function, so the return address from libc (which will be exit most of the time) will be in the stack if we go deep enough. With the “exit” return address or any function return address from libc, we can get libc base address (Use this tool for that purpose).