Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdb.debug() appends an extra line to the passed gdbscript, resulting in symbol resolution errors #1333

Closed
numin0us opened this issue Aug 10, 2019 · 3 comments

Comments

@numin0us
Copy link

numin0us commented Aug 10, 2019

Pwntools Issue Template

  • Version: Latest version of the dev3 branch
  • OS: Ubuntu 18.04/Kali 2019.3
  • GDB Version: 8.3
  • Python Version: 3.7.4

When using the gdb.debug() feature of pwntools an extra line is appended to the the passed gdbscript which in some cases can prevent proper symbol resolution.

root@kali:~/Downloads/crackmes# ptpython                                                                                                                                                                          
>>> from pwn import *                                                                                                                                                                                             
>>> context.log_level = "DEBUG"                                                                                                                                                                                   
>>> p = gdb.debug('./crackme01.64')                                                                      
...
[DEBUG] Wrote gdb script to '/tmp/pwnxnkmbope.gdb'
    file "./crackme01.64"
    target remote 127.0.0.1:38677
    file "./crackme01.64"

and on gdb..

Reading symbols from ./crackme01.64...(no debugging symbols found)...done.
Reading /lib64/ld-linux-x86-64.so.2 from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /lib64/ld-linux-x86-64.so.2 from remote target...
Reading /lib64/ld-2.27.so from remote target...
Reading /lib64/.debug/ld-2.27.so from remote target...
0x00007f16e2289090 in ?? () from target:/lib64/ld-linux-x86-64.so.2

(gdb) disass main
Dump of assembler code for function main:
   0x00000000000006aa <+0>:     Cannot access memory at address 0x6aa

The issue stems from the fact that in the new version of gdb, when you run file after attaching to a remote target, it replaces the symbols in the current context. I downloaded and edited a local version of pwntools to remove that final line of the gdbscript and it seems to work fine.

...
[DEBUG] Wrote gdb script to '/tmp/pwnva62cw6s.gdb'
    file "./crackme01.64"
    target remote 127.0.0.1:34373

on GDB

(gdb) disass main
Dump of assembler code for function main:
   0x0000557f59b586aa <+0>:     push   %rbx
   0x0000557f59b586ab <+1>:     cmp    $0x2,%edi
   0x0000557f59b586ae <+4>:     jne    0x557f59b586ec <main+66>

This issue does not appear to happen on the pwntools container from Dockerhub. I believe that may be due to it using an older version of GDB (7.x), but I have not performed enough testing to determine that. In my own pwntools module I hacked together a solution, I am not familiar enough with the codebase to submit a pull request.

@numin0us
Copy link
Author

numin0us commented Aug 16, 2019

Updated initial submission with more diagnostic information.

@numin0us numin0us changed the title GDB does not resolve symbols properly gdb.debug() appends an extra line to the passed gdbscript, resulting in symbol resolution errors Aug 16, 2019
@bet4it
Copy link
Contributor

bet4it commented Aug 16, 2019

I'm trying to fix it in #1323

@Arusekk
Copy link
Member

Arusekk commented Apr 23, 2020

Closed via #1323

@Arusekk Arusekk closed this as completed Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants