patchpwn - A shell script to replace libc of pwn binary in CTF
Abstract
This simple shell script is based patchelf and glibc-all-in-one . So , using patchpwn , you need to ensure that you have install them and they are in normal use .
Usage
Before specifying the libc version , you should download the libc via glibc-all-in-one, then edit this shell script and replace the LIBC_DIR variable to adapt your local environment.After patching the binary ,it will generate a new binary file with the _patched suffix and no change to the original binary file.
Unfortunately, only ubuntu16,ubuntu18,ubuntu20 are currently supported.
And also you change the default version of every supportive os in this shell script.
1 2 3 4 5 6 7 8
# the default is x86 glibc DEFAULT_ubuntu16_04="2.23-0ubuntu11.3_amd64" DEFAULT_ubuntu18_04="2.27-3ubuntu1.2_amd64" DEFAULT_ubuntu20_04="2.31-0ubuntu9.2_amd64"
The parameter --help help you inspect the available libc in the directory /dir/to/your/glibc-all-in-one/libs/. Also you can download more libc via glibc-all-in-one
Application scene
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
giles@ubuntu:~/Desktop/GreentownNote/attachment $ strings libc-2.27.so | grep "GNU" GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1) stable release version 2.27. Compiled by GNU CC version 7.3.0. giles@ubuntu:~/Desktop/GreentownNote/attachment $ patchpwn ... Your Libc: [+] 2.23-0ubuntu11.3_amd64 [+] 2.23-0ubuntu11.3_i386 [+] 2.23-0ubuntu3_amd64 [+] 2.23-0ubuntu3_i386 [+] 2.27-3ubuntu1.2_amd64 [+] 2.27-3ubuntu1.2_i386 [+] 2.27-3ubuntu1_amd64 [+] 2.27-3ubuntu1_i386 giles@ubuntu:~/Desktop/GreentownNote/attachment $ patchpwn 2.27-3ubuntu1_amd64 ./GreentownNote giles@ubuntu:~/Desktop/GreentownNote/attachment $ python exp.py
It can help to attack exit_hook(hook in ld),and crack remote libc.