How to debug stripped binaries with GDB

Leave a Comment

references: https://reverseengineering.stackexchange.com/questions/1935/how-to-handle-stripped-binaries-with-gdb-no-source-no-symbols-and-gdb-only-sho

Tricks you should know

Press return/enter will run last command

Commands can be abbreviated as long as they are unambiguous.

eg:

b for break (despite bt and backtrace)
c or cont for continue (despite catch, call and so on)
n for next (despite ni and nexti)

You can call a function with “call”

You can toggle sources, registers and asm view using layout `src/regs/asm’

GDB debug processing

run the command

$ gdb commands_to_run

Look for entry point

> info file
        `.......', file type elf64-x86-64.h
        Entry point: 0x402350
        0x0000000000400200 - 0x000000000040021c is .interp) group(s) only
        0x000000000040021c - 0x000000000040023c is .note.ABI-tag
        0x000000000040023c - 0x0000000000400260 is .note.gnu.build-id
        0x0000000000400260 - 0x0000000000400294 is .gnu.hash
        0x0000000000400298 - 0x0000000000400a78 is .dynsym
        0x0000000000400a78 - 0x0000000000400d54 is .dynstr

set breakpoints and run

> b *0x402350
        Breakpoint 1 at 0x402350
> run
        Starting program: /home/lfs/sources/john-1.7.8/run/john
        
        Breakpoint 1, 0x0000000000402350 in ?? ()

assembly

> set disassembly-flavor intel/att
> layout asm
> layout regs

btw, if you prefer to save screen estate, starting with GDB 7.0 you can use:

> set disassemble-next-line on

debug

# Execute one machine instruction, but if it is a function call, proceed until the function returns. 
> nexti 
> ni
# Execute one machine instruction, then stop and return to the debugger. 
> stepi 
>si

0 comments:

Post a Comment