Juicy
Juicy

Reputation: 12500

Setting breakpoints remotely with gdb and gdbserver

I'm debugging a vulnerable app on a remote host. I've set up gbserver on the host with:

gdbserver host:1234 /my/target/app

On my local host I've connected with:

$ gdb /same/target/app
gdb$ target extended-remote 192.168.0.100:1234

I connect successfully and can proceed to set a breakpoint on a target instruction, ie:

$gdb disas vuln_function
....
   0x08048e6b <+116>:   ret
End of assembler dump.
gdb$ b *0x08048e6b
Breakpoint 1 at 0x8048e6b

Looking at the disassembled function code and having tested this on the host itself, I'm 100% sure I'm breaking on the right address and in any case I'm triggering a buffer overflow which should make gdb break by itself.

But instead of getting the usual breakpoint on my gdb client, nothing happens. gdbserver freezes on the BO (so I'm guessing it did break on the ret) without throwing the segfault. gdb doesn't seem to be crashing or behaving abnormally other than not giving me a prompt on the breakpoint.

Is there a special way to set breakpoints when debugging with gdbserver?

Upvotes: 4

Views: 5469

Answers (2)

Mohammad Azim
Mohammad Azim

Reputation: 2933

Is there a special way to set breakpoints when debugging with gdbserver?

Make sure you have compiled executable with debug symbols -g -O0 When debugging remote, gdb client does not know where to load symbols from. You have two options:

1. specify executable when starting gdb

gdb <executable>
(gdb) target remote <IP>:<port>
(gdb) load <executable>
 gdb should know symbols now
(gdb) b main
(gdb) mon reset
(gdb) contnue
 it should break at main
(gdb) bt

2. use file command to tell about the symbols.

gdb
(gdb) target remote <IP>:<port>
(gdb) load <executable>
(gdb) file <executable>
 gdb should know symbols now
(gdb) b main
(gdb) mon reset
(gdb) contnue
 it should break at main
(gdb) bt

Upvotes: 2

Employed Russian
Employed Russian

Reputation: 213375

Is there a special way to set breakpoints when debugging with gdbserver?

No, it's supposed to work just as with local debugging.

You should first convince yourself that your setup is sane by doing remote debugging on a local host (both gdb and gdbserver run on local host).

If that works, your problem is likely that local gdb and remote target process are using different application binary (or different libc.so).

Upvotes: 1

Related Questions