peda/pwngdb/gef
这是常见的gdb的三个插件,配合gdb使用可以提升调试效率。
安装pwndbg:
git clone https://github.com/pwndbg/pwndbg
cd pwndbg
./setup.sh
安装peda:
git clone https://github.com/longld/peda.git~/peda
echo "source ~/peda/peda.py" >> ~/.gdbinit
安装gef:
wget -q -O- https://github.com/hugsy/gef/raw/master/scripts/gef.sh| sh
wget -q -O ~/.gdbinit-gef.py https://github.com/hugsy/gef/raw/master/gef.py
echo source ~/.gdbinit-gef.py >> ~/.gdbinit
因为在同一时刻只能使用一种插件,而且在解决不同类型的题目时使用不同的插件,因此需要配置三种插件的快捷切换。
首先,gdb使用哪种插件是在.gdbinit文件(一般在root目录下)中使用source进行控制的,我们可以在使用插件时注释掉其他的source命令,即可单独使用某一插件。但是每次都编辑该文件实在是麻烦,因此可以使用脚本进行选择。巧合之下,之前看到一位师傅写了个自动选择插件的脚本,很是好用。
#!/bin/bash
function Mode_change {
name=$1
gdbinitfile=~/.gdbinit #这个路径按照你的实际情况修改
# gdbinitfile=/root/Desktop/mode
peda="source ~/peda/peda.py" #这个路径按照你的实际情况修改
gef="source ~/.gdbinit-gef.py" #这个路径按照你的实际情况修改
pwndbg="source /opt/pwndbg/gdbinit.py" #这个路径按照你的实际情况修改
sign=$(cat $gdbinitfile | grep -n "#this place is controled by user's shell")
#这是一个定位flag,此处上面的查找内容要和你自己的保持一致
pattern=":#this place is controled by user's shell"
number=${sign%$pattern}
location=$[number+2]
parameter_add=${location}i
parameter_del=${location}d
message="TEST"
if [ $name -eq "1" ];then
sed -i "$parameter_del" $gdbinitfile
sed -i "$parameter_add $peda" $gdbinitfile
echo -e "Please enjoy the peda!\n"
elif [ $name -eq "2" ];then
sed -i "$parameter_del" $gdbinitfile
sed -i "$parameter_add $gef" $gdbinitfile
echo -e "Please enjoy the gef!\n"
else
sed -i "$parameter_del" $gdbinitfile
sed -i "$parameter_add $pwndbg" $gdbinitfile
echo -e "Please enjoy the pwndbg!\n"
fi
}
echo -e "Please choose one mode of GDB?\n1.peda 2.gef 3.pwndbg"
read -p "Input your choice:" num
if [ $num -eq "1" ];then
Mode_change $num
elif [ $num -eq "2" ];then
Mode_change $num
elif [ $num -eq "3" ];then
Mode_change $num
else
echo -e "Error!\nPleasse input right number!"
fi
gdb $1 $2 $3 $4 $5 $6 $7 $8 $9
现在我们把这个shell脚本放到一个环境变量指向的路径里面,查看一下自己的路径,shell脚本放进去。我放在了/usr/local/sbin目录下,这样就可以执行 gdb.sh,输入对应插件的数字就可以选择使用哪个插件,无需手动更改.gdbinit文件。
实在不会可以参考这位师傅的教程:自动选择gdb插件