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?

4

The process dies before/while gdb connects to it, as your python script finishes. Use

p.interactive()

at the end of your script to keep it running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.