2

Here is the program which gdb is attached to:

prog.c

#include <stdio.h>

void dummy(char* s) {

}

int main() { char buf[512]; scanf("%s", buf); printf("%s\n", buf); dummy(buf); return 0; }

It is compiled with:

gcc prog.c o prog

This is the script which drives the program:

from pwn import *

p = process("./prog") raw_input('>>') p.sendline('A')

Here's the sequence of operation I perform:

  1. Run the script in one bash tab. It launches prog
  2. In another bash tab: sudo gdb -p `pgrep prog` . gdb attaches itself to the running process
  3. Set a breakpoint on dummy call in gdb: b dummy
  4. Press c in gdb to continue
  5. Hit Enter in the script to continue
  6. gdb gives up by saying: 0x000056446a5af764 <dummy+4>: Cannot access memory at address 0x56446a5af764

enter image description here

If instead of feeding the input programmatically, I launch the program manually, attach gdb and feed the input myself, the breakpoint is correctly hit.

enter image description here

What is the problem in the script?

galoget
  • 117
  • 7
sherlock
  • 1,381
  • 3
  • 23
  • 40

1 Answers1

5

The process dies before/while gdb connects to it, as your python script finishes. Use the following line at the end of your script to keep it running.

p.interactive()
galoget
  • 117
  • 7
user23263
  • 66
  • 1
  • 2