-
-
PWN题获取细分版本libc方案
-
2022-3-18 16:20
13381
-
源起
在平时做题的时候给的libc基本上都是去除了调试符号的ibc,而没有调试符号会使得pwngdb中heap bins等命令不可用,导致我这种新手调试起来碍手碍脚。
当然也有很多中方式获得带调试符号的libc,例如:
- 自己编译libc
- glibc_all_in_one下载调试符号分离的libc
自己编译libc是最麻烦的,在编译期间会因为系统环境问题出现各种错误,非常的耗时。
而glibc_all_in_one可以很方便的下载libc和对应的调试符号,但是使用如下命令跟换libc,因为自己太菜不会附加调试符号
1 2 | p = process([ "./ld-xxx.so" , "./file" ],
env = { "LD_PRELOAD" : "./libc-xxx.so " })
|
使用patchelf也不能很好的解决问题。虽然可以使用eu-unstrip将调试符号附加到文件中,但是最遗憾,虽然上面有各个libc的版本的最新和初始版本,却不曾见到每个libc的每个小版本。
获取libc以及调试符号
在这里可以找到libc版本的发行历史
Ubuntu glibc package
可以直接运行libc文件查看libc子版本
1 2 3 4 5 6 7 8 9 10 | . / libc - 2.27 .so
GNU C Library (Ubuntu GLIBC 2.27 - 3ubuntu1 . 4 ) stable release version 2.27 .
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 7.5 . 0.
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<https: / / bugs.launchpad.net / ubuntu / + source / glibc / + bugs>.
|
或者使用strings命令查找
1 2 | strings . / libc.so | grep "Ubuntu GLIBC"
GNU C Library (Ubuntu GLIBC 2.29 - 0ubuntu2 ) stable release version 2.29 .
|
已经由大佬写了自动下载脚本
zeyugao / glibc-launchpad
也可以点进list中手动下载需要版本的libc以及调试符号deb文件
1 | wget http: / / launchpadlibrarian.net / 497108893 / libc6_2. 27 - 3ubuntu1 . 3_amd64 .deb $ wget http: / / launchpadlibrarian.net / 497108885 / libc6 - dbg_2. 27 - 3ubuntu1 . 3_amd64 .deb
|
释放deb得到libc和调试符号
1 2 | dpkg - deb - x libc6_2. 27 - 3ubuntu1 . 3_amd64 .deb . / libc
dpkg - deb - x libc6 - dbg_2. 27 - 3ubuntu1 . 3_amd64 .deb . / sym
|
可执行文件libc
调试符号libc:(虽然看起来可以执行,但是里面只有符号表)
将libc与调试符号结合
有关调试符号和strip的基本概念可以看一下这篇文章:
深入理解debuginfo
将libc和调试符号放到同一个目录下方便操作
安装elfutils
eu-strip和eu-unstrip都在elfutils这个包中,所以要先安装elfutils
1 | sudo aptitude install elfutils
|
结合两个文件:
1 | sudo eu - unstrip libc - 2.27 .so libc - 2.27_sym .so
|
可以看到,符号文件的大小变大了,说明是将不带符号的libc给直接附加到了符号上面,因为都是elf文件,所以能这么操作。
给libc-2.27_sym.so和ld-2.27.so加一下执行权限:
1 | sudo chmod + x libc - 2.27_sym .so ld - 2.27 .so
|
可以看到现在的libc-2.27_sym.so既能够运行查看版本,有带有调试符号了
[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界