There is no doubt, GDB is an amazing tool that almost every single cyber security professional, trainee, hobbyist and researcher has used it before. It is the swiss army knife of process debugging however there is one problem.Vanilla GDB sucks in terms of user experience.
This is the reason behind the development of many plug-ins that can make the process of reversing and debugging so much easier. Namely, three of the most popular are:
Of course, all of them come with their pros and cons. Maybe for the task, maybe the features, or even the interface. We all have our preferences. Personally, I prefer Pwndbg’s interface more, but seriously Peda’s cyclic pattern creation and offset search functionality are extremely handy.
Still, I hate having to manually change or replace the.gdbinitfile every time I want to use a different plugin. It’s not about the time and effort, but more because it’s a distraction from my primary task, that I would like to avoid.
Therefore, the purpose of this blog post is to describe a very simple way of switching between plugins in a single command.
TL;DR;
I have created a bash script that executes the instructions below in one command so for a rapid setup clone the repository below and runinstall.sh.
Inherently, these plugins modify the.gdbinitfile and are launched along with gdb. Now, here is the trick, what if we had a.gdbinitfile that contains configurations for all plugins so that they are conditionally activated based on the gdb command? This is exactly what we will be doing.
Open your.gdbinitfile, delete any contents and paste the following configuration:
define init-peda
source ~/peda/peda.py
end
document init-peda
Initializes the PEDA (Python Exploit Development Assistant for GDB) framework
end
define init-pwndbg
source ~/.gdbinit_pwndbg
end
document init-pwndbg
Initializes PwnDBG
end
define init-gef
source ~/.gdbinit-gef.py
end
document init-gef
Initializes GEF (GDB Enhanced Features)
end
Additionally, create the following 3 files in your/usr/binfolder:
First create/usr/bin/gdb-pedaand paste the following:
#!/bin/sh
exec gdb -q -ex init-peda "$@"
Then/usr/bin/gdb-pwndbg
#!/bin/sh
exec gdb -q -ex init-pwndbg "$@"
And lastly,/usr/bin/gdb-gef
#!/bin/sh
exec gdb -q -ex init-gef "$@"
The last step is to give executable permissions to all three of the files created previously. For that, run:
chmod +x /usr/bin/gdb-*
That was all! You see? Simple.
Now you can test it by running either one of the three commands: