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

Incompatible system python vs gdb python #483

Open
armax00 opened this issue Jul 26, 2024 · 5 comments
Open

Incompatible system python vs gdb python #483

armax00 opened this issue Jul 26, 2024 · 5 comments
Labels

Comments

@armax00
Copy link

armax00 commented Jul 26, 2024

While working on solving level 7.0 and 7.1 I noticed the following issue that worked earlier.

What I want to do is to get a value of a register out of a first run to then use it in a second run. That way, I should be able to fully automate at exploit independently of container restarts. However gdb is complaining.

Error:
[ERROR] Failed to connect to GDB: rpyc is not installed

Code example:
g = gdb.debug(CHALLENGE, '''
break main
continue
''')
value = (g.execute("print ($rbp))"))
g.close()

Looking at the pwntools docs this seems to be an issue with the different python interpreters used:
hacker@program-exploitationlevel7-0:/yellow/prog-exploitation/level07$ gdb -batch -ex 'python import sys; print(sys.version)'
3.11.9 (main, Apr 2 2024, 08:25:04) [GCC 13.2.0]
hacker@program-exploitationlevel7-0:/yellow/prog-exploitation/level07$ python3 --version
Python 3.8.10

Would it be possible to upgrade python to 3.11.9?

@ConnorNelson
Copy link
Member

Interesting, this definitely sounds like a new nix-related bug. Thanks for reporting.

@ConnorNelson
Copy link
Member

Ok so it looks like the gdb.debug starts up gdb correctly with your initial gdb script.

I am not seeing how g.execute works; it doesn't seem to be a method on the pwnlib.tubes.process.process which I get back from gdb.debug.

That being said, import rpyc definitely works inside /usr/bin/gdb, but does not work inside /run/current-system/sw/bin/gdb, which means I can reproduce the underlying issue.

@armax00
Copy link
Author

armax00 commented Jul 26, 2024 via email

@ConnorNelson
Copy link
Member

It looks like gef and pwndbg in their nixpkgs implementations setup a pythonPath.

In gef they use makeWrapper to make a gef program that calls gdb with a custom NIX_PYTHONPATH and PATH and -x gef.py.

In pwndbg they also use makeWrapper, with -x pwndbg/gdbinit.py, and patch that gdbinit to setup PYTHONPATH/PATH.

It looks like we'll need to also take an approach of wrapping gdb (probably we'll also make it be called gdb so everything works by default) and getting any dependencies we want gdb to have access to. I think I favor the gef approach a bit more.

Probably these dependencies will include:

  • Everything pwntools wants
  • Everything pwndbg wants
  • Everything gef wants

But maybe we should be even broader with this and make sure the full python environment that we setup's dependencies appear.

Any thoughts on this @Scoder12 @supercoolspy?

@supercoolspy
Copy link
Contributor

Sounds good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants