-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 api not functionnal for GDB 8.3+ #2458
Labels
Comments
Idea: we can probably switch to os.exit.
Email z środy 11 września 2024 od Jordana ERNSTa:
… I'm having an issue when I want to Use GDB api.
Using:
- OS: Manjaro X64
- GNU gdb (GDB) 15.1
- python 3.12.5
- Pwntools v4.13.0
- rpyc 6.0.0
## Issue
Sample script:
```python
from pwn import context, gdb
context.binary = "bin.elf"
context.terminal = "wezterm"
p = context.binary.process()
gdb.attach(p, api=True)
```
And the error:
```text
[x] Starting local process '/usr/bin/gdb' argv=[b'/usr/bin/gdb', b'--nx', b'-bat[◢] Starting local process '/usr/bin/gdb' argv=[b'/usr/bin/gdb', b'--nx', b'-bat[+] b'-ex', b'python import rpyc; import sys; sys.exit(123)'] : pid 49447
[*] Process '/usr/bin/gdb' stopped with exit code 1 (pid 49447)
[ERROR] Failed to connect to GDB: rpyc is not installed
Traceback (most recent call last):
File "/home/user/file.py", line 23, in <module>
gdb.attach(p, api=True)
File "/usr/lib/python3.12/site-packages/pwnlib/context/__init__.py", line 1582, in setter
return function(*a, **kw)
^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/pwnlib/gdb.py", line 1251, in attach
log.error('Failed to connect to GDB: rpyc is not installed')
File "/usr/lib/python3.12/site-packages/pwnlib/log.py", line 439, in error
raise PwnlibException(message % args)
pwnlib.exception.PwnlibException: Failed to connect to GDB: rpyc is not installed
[*] Stopped process '/home/user/bin.elf' (pid 49429)
```
## Analysis
Upon analyzing whats happening I can see how the check is done:
https://github.com/Gallopsled/pwntools/blob/d7817a7eaccb9baacb121131ec913cf0a14a1f05/pwnlib/gdb.py#L1277-L1281
I tried running the command in the terminal directly:
```bash
# Using bash shell
gdb --nx -batch -ex 'python import rpyc; import sys; sys.exit(123)'; echo $?
Python Exception <class 'SystemExit'>: 123
Error occurred in Python: 123
1
```
Gdb seems to exit with an error code of `1`.
And indeed in DGB 8.3 changelog we have `GDB in batch mode now exits with status 1 if the last command to be
executed failed.`
I wonder how come this has not been spotted since then ?
Am I really the only one wanting tu use theGDB api through pwnlib ?
--
Reply to this email directly or view it on GitHub:
#2458
You are receiving this because you are subscribed to this thread.
Message ID: ***@***.***
--
Wysłane z mojego urządzenia Sailfish
|
I confirm this would work: gdb --nx -batch -ex 'python import rpyc; import os; os._exit(123)'; echo $?
123 |
This isn't a problem with gdb 8.3 but with GDB 15.1 packaged in Ubuntu 24.04 now. Our tests run on Ubuntu 22.04 which is why this wasn't spotted yet. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm having an issue when I want to Use GDB api.
Using:
Issue
Sample script:
And the error:
Analysis
Upon analyzing whats happening I can see how the check is done:
pwntools/pwnlib/gdb.py
Lines 1277 to 1281 in d7817a7
I tried running the command in the terminal directly:
Gdb seems to exit with an error code of
1
.And indeed in the GDB 8.3 changelog we have
GDB in batch mode now exits with status 1 if the last command to be executed failed.
I wonder how come this has not been spotted since then ?
Am I really the only one wanting to use the GDB api through pwnlib ?
The text was updated successfully, but these errors were encountered: