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

dont send SIGTERM to already exiting gdb #2523

Open
k4lizen opened this issue Jan 17, 2025 · 0 comments
Open

dont send SIGTERM to already exiting gdb #2523

k4lizen opened this issue Jan 17, 2025 · 0 comments

Comments

@k4lizen
Copy link
Contributor

k4lizen commented Jan 17, 2025

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:

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

    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.

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

1 participant