skills/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/stack-canaries/SKILL.md
How to understand, detect, and bypass stack canary protections in binary exploitation. Use this skill whenever the user mentions stack canaries, stack smashing, buffer overflow protections, __stack_chk_fail, or any CTF/pwn challenge involving stack-based mitigations. Also trigger when analyzing binaries with -fstack-protector, discussing canary leaks, or working on challenges where the stack protection is preventing exploitation.
npx skillsauth add abelrguezr/hacktricks-skills stack-canary-exploitationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill covers understanding and bypassing stack canary protections in binary exploitation challenges.
Stack canaries are a defense mechanism against buffer overflow attacks. A special random value (the "canary") is placed on the stack before the return address. Before a function returns, the program checks if the canary is still intact. If it's been modified, the program calls __stack_chk_fail() and terminates.
x64 binaries:
0x00)fs:0x28x86 binaries:
0x00)gs:0x14The null byte is least significant because it comes first on the stack (lower addresses). String functions stop at null bytes, so they won't read past the canary.
# Using checksec
checksec --file=binary
# Look for __stack_chk_fail in symbols
nm binary | grep stack_chk
objdump -t binary | grep stack_chk
# Check compilation flags
readelf -p .comment binary | grep -i stack
# Find functions with stack protector
objdump -d binary | grep -A 20 "<function_name>"
# Look for canary check patterns in disassembly
If you can read memory, leak the canary value and preserve it during your overflow.
Common leak sources:
Leak from TLS (x64):
# Canary is at fs:0x28
# Use a read primitive to read from this address
Leak from TLS (x86):
# Canary is at gs:0x14
If the binary uses fork() without execve(), child processes inherit the same canary. You can brute-force it byte-by-byte:
When this works:
fork()execve() after fork()__stack_chk_failIf the binary has Partial RELRO (not Full RELRO), you can overwrite the GOT entry:
__stack_chk_fail in GOTCheck RELRO status:
readelf -l binary | grep -i relro
# "RELRO" without "Full" means Partial RELRO
In multi-threaded programs, you might be able to modify the master canary in TLS:
This works because thread stacks and TLS are both allocated via mmap().
Instead of reaching the return address, overwrite pointers stored on the stack:
This bypasses the canary entirely by redirecting execution before the check.
# Check protections
checksec --file=binary
# Look for canary-related symbols
nm binary | grep -E "(stack_chk|__stack)"
# Check for format strings (potential leak)
grep -r "printf\|scanf\|gets" source.c 2>/dev/null
| Scenario | Best Bypass | |----------|-------------| | Format string vuln | Leak canary | | Arbitrary read | Leak from TLS | | Partial RELRO | Modify GOT | | Fork without exec (x86) | Brute-force | | Multi-threaded | Master canary forgery | | Stack pointers present | Pointer redirection |
Template for canary leak + overflow:
from pwn import *
context.binary = elf = ELF('./binary')
context.arch = 'x64' # or 'i386'
# Connect
p = process(elf.path)
# Leak canary (example via format string)
# Adjust based on actual vulnerability
leak = p.recvuntil(b'%p')
canary = u64(p.recv(8).ljust(8, b'\x00'))
print(f"Leaked canary: {hex(canary)}")
# Craft payload preserving canary
payload = b'A' * offset_to_canary
payload += p64(canary) # Preserve canary
payload += b'B' * padding
payload += p64(rop_chain) # Your actual payload
# Send exploit
p.sendline(payload)
p.interactive()
p64()/p32() for proper encodingfs:0x28 (x64), gs:0x14 (x86)fork() shares canary, execve() doesn'ttesting
How to perform a House of Lore (small bin attack) heap exploitation. Use this skill whenever the user mentions heap exploitation, small bin attacks, fake chunks, glibc heap vulnerabilities, or needs to insert fake chunks into small bins for arbitrary read/write. Trigger for CTF challenges involving heap corruption, glibc 2.31+ exploitation, or when the user needs to bypass malloc sanity checks using fake chunk linking.
testing
How to perform House of Force heap exploitation attacks. Use this skill whenever the user mentions heap exploitation, House of Force, top chunk manipulation, arbitrary memory allocation, malloc manipulation, or wants to allocate chunks at specific addresses. Also trigger for CTF challenges involving heap overflows, top chunk size overwrites, or when the user needs to calculate evil_size for heap attacks. Make sure to use this skill for any binary exploitation task involving glibc heap manipulation, even if they don't explicitly say "House of Force".
tools
How to perform House of Einherjar heap exploitation to allocate memory at arbitrary addresses. Use this skill whenever the user mentions heap exploitation, glibc heap attacks, arbitrary memory allocation, off-by-one overflow exploitation, tcache poisoning, fast bin attacks, or any CTF challenge involving heap manipulation. This is essential for binary exploitation tasks where you need to control malloc() return addresses.
testing
How to identify, analyze, and exploit heap overflow vulnerabilities in binary exploitation challenges and real-world scenarios. Use this skill whenever the user mentions heap overflows, memory corruption, heap grooming, tcache poisoning, fast-bin attacks, or any heap-related vulnerability in CTF challenges, binary analysis, or security research. This skill covers heap overflow fundamentals, exploitation techniques, heap grooming strategies, and real-world CVE analysis.