I'm currently studying binary heap exploitation (mainly the glibc (ptmalloc2) implementation), for CTF competitions. The problem I'm facing is debugging challenges designed for a certain glibc version. I know there are some differences between (for example) libc 2.27 and libc 2.31 that can make the exploitation of certain vulnerabilities harder (or impossible) to exploit on newer versions.
This is a template script I usually like to use (with pwntools):
#!/usr/bin/env python3
from pwn import *
BINARY = ""
LIBC = ""
HOST = ""
PORT = 9999
exe = ELF(BINARY)
if LIBC != "":
libc = ELF(LIBC, checksec=False)
rop = ROP(exe)
context.binary = exe
context.log_level = "debug"
if "remote" in sys.argv:
io = remote(HOST, PORT)
else:
io = gdb.debug([BINARY], gdbscript="""
b main
"""
)
io.interactive()
This makes debugging locally extremely easy and fast IMO.
I'd like to have a method to easily be able to debug programs using the same (or kind of the same) script as above and using the right glibc (and ld as both are required to be the same version) version without messing with my system's library.
How do I do that?