强行修改 ELF 文件后使用 GDB 进行源码级调试的方法

发布时间 2023-08-10 16:28:24作者: imtaieee
  1. 使用patchelf命令修改目标文件ldlibc
patchelf --set-interpreter /mnt/hgfs/Share/ld.so --replace-needed libc.so.6 /mnt/hgfs/Share/libc.so pwn.elf
  1. GDB直接载入文件。
gdb pwn.elf
  1. GDB中设置debug-file-directorydirectories,其中debug-file-directory.build-id文件夹所在的文件夹,directories为想要调试的函数源码文件所在的文件夹。
  2. 注意,程序所使用的ldlibc必须要与GDB中指定的debug-file-directorydirectories是同一版本,否则无法进行源码级调试。
  3. 可在网站:[https://codebrowser.dev/glibc/](https://codebrowser.dev/glibc/)中查找想要调试的函数的源码的具体位置。