Monday, April 9, 2012

Vulnerability analysis with gdbserver

Here's my workflow when I'm doing vulnerability analysis under debugger. Thanks to gdbserver I can debug on target machine (OS image launched in Virtualbox) and use gvim and pyclewn just by dropping statically compiled gdbserver into target machine.

ON WORKING MACHINE:

# in case you don't already have it
apt-get install dpkg-dev

# get source of your gdb (includes gdbserver)
apt-get source gdb

# compile gdbserver
cd gdb-x.y/gdb/gdbserver/
LDFLAGS=-static ./configure
make

# sent it to target machine (for example:)
scp ./gdbserver root@192.168.x.y:

ON TARGET MACHINE:

# compile your binary (exim4 for me)
cd exim-4.69/
cp src/EDITME Local/Makefile
vi Local/Makefile
set/modify BIN_DIRECTORY
set/modify CONFIGURE_FILE
set EXIM_USER
set EXIM_GROUP
comment out EXIM_MONITOR
add: CFLAGS += -g somewhere in the file
make
make install

ON WORKING MACHINE:

# copy binary from target machine to your working machine:
cd exim-4.69/src
scp 192.168.x.y:/usr/local/exim/bin/exim-4.69-2 ./

ON TARGET MACHINE:

# start gdbserver:
./gdbserver :3332 /usr/local/exim/bin/exim-4.69-2 -d -bd -oX 3333

OR attach to existing process:

./gdbserver :3332 --attach

ON WORKING MACHINE:

cd exim-4.69/src
gdb exim-4.69-2
target remote 192.168.x.y:3332
break main
continue

OR you could do it from gvim + pyclewn:

cd exim-4.69/src
pyclewn
e exim.c
Cmapkeys
Cfile exim-4.69-2
Ctarget remote 192.168.x.y:3332
Cbreak main
Ccontinue