Here is a method that require 2 files, the LibC and the associated linker (ld
). Here is an example with a 2.23 LibC.
You might be interested by pwninit to download the linker(ld
) associated to your LibC.
Run in command line :
Then, run the linker with the challenge binary as an argument and use the LD_PRELOAD
environment variable to specify the LibC that should be loaded.
$ LD_PRELOAD=/path/to/libc-2.23.so ./ld-2.23.so ./chall
Pwntools
With pwntools you can do the following:
#!/usr/bin/env python3
from pwn import *
context.binary = bin = ELF("./chall")
libc = ELF("./libc-2.23.so")
ld = ELF("./ld-2.23.so")
io = process([ld.path, bin.path], env={"LD_PRELOAD": libc.path})
Pwntools template
If you use the pwn template
command to generate an exploit skeleton. You can do these change to the start
function to use a custom LibC.
ld = ELF('./ld-2.23.so')
libc = ELF('./libc-2.23.so')
def start(argv=[], *a, **kw):
'''Start the exploit against the target.'''
if args.GDB:
return gdb.debug([ld.path, exe.path] + argv, gdbscript=gdbscript, *a, **kw, env={"LD_PRELOAD":libc.path})
else:
return process([ld.path, exe.path] + argv, *a, **kw, env={"LD_PRELOAD":libc.path})