Gallopsled / Gallopsled/pwntools
dont send SIGTERM to already exiting gdb
- Dominant language
- Python
- Stars
- 13.7k
- Forks
- 1.9k
- Avg merge
- 6d 23h
- Merged PRs (30d)
- 3
Description
If I use pwntools to spawn gdb in another window. Then `exit` in that gdb window, pwntools will still send SIGTERM to it.
### Reproducer
`thingy.py:`
```python
from pwn import *
exe = context.binary = ELF("/usr/bin/sh", checksec=False)
context.terminal = "kitten @ launch --location=before --cwd=current --bias=65".split()
p = gdb.debug([exe.path])
p.interactive()
```
Add a print here to see it happen:
`pwnlib/util.misc.py:508`
```python
if kill_at_exit and pid:
def kill():
try:
if terminal == 'qdbus':
os.kill(pid, signal.SIGHUP)
else:
print("killing!") # <---------- add this line
os.kill(pid, signal.SIGTERM)
except OSError:
pass
atexit.register(kill)
```
1. `python thingy.py`
2. `exit` in the spawned gdb window
3. See the `killing!` text printed in the pwntools window (might need to press enter to allow the IO to happen)
### Context
I was making a kitty port of https://github.com/joaogodinho/pwnmux and so I `atexit.register(...)` in my python script the code which closes the extra windows that were spawned. The problem is that this cleanup is slow and before all windows are closed, pwntools sends gdb a SIGTERM while gdb is inside of my registered atexit handler, the gdb process forcefully exits, and some windows are left unclosed.
I tried playing around with workaround by registering my own SIGTERM handler from inside the script, but I couldn't get this to work. The workaround I settled on was closing the windows with a signal instead of `kitten @ close-window` since it is faster and wins the race against pwntools.
Note that I cannot simply set `kill_at_exit` to false, because I **do** want pwntools to send SIGTERM to gdb if I Ctrl-C on the pwntools process.
Contributor guide
Assessment
This issue has not been assessed yet.