0

When running gdb cmd I can manually stop cmd via Ctrl-C. This invokes the debugger and lets me inspect memory.

In pwntools, I can attach gdb, and can manually stop the process by hitting Ctrl-C in the gdb window. I'd like to be able to do this programatically from pwntools script: something like:

if output != expected:
    io.gdb.ctrlc() # break, let me use gdb

This doesn't necessarily require a pwntools answer. GDB has a powerful Python API, but I can't find in it the equivalent of a "Interrupt the process, as if someone hit Ctrl-C". Is there a way to do that, either via the GDB Python API or via a pwntools method?

SRobertJames
  • 8,210
  • 14
  • 60
  • 107

2 Answers2

1

We can send a signal to gdb to simulate hitting Ctrl-C in the gdb window

prepare a file gdb_run3s:

#let shell send a signal to the parent process, which is the gdb, after 3 seconds
shell sleep 3 && kill -SIGINT $PPID &  
#continue, should break by signal SIGINT 3 seconds later
c  
#now can read/write register/memory 
set $pc=xxx

then source it in gdb

(gdb) source gdb_run3s
zqb-all
  • 126
  • 3
0

Is there a way to do that, either via the GDB Python API or via a pwntools method?

I don't know about pwntools, but using the GDB Python API in all-stop mode this would not be possible: when the inferior is running, GDB is blocked (waiting for something to happen to the inferior with waitpid).

It might work in non-stop mode though.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362