GDB插件控制

论坛 期权论坛 脚本     
匿名网站用户   2020-12-19 13:27   31   0

GDB插件管理脚本

我们经常会用到的gdb三个插件:peda,gef,pwndbg,但是这三个插件不能同时使用,如果三个都安装了,那么每次启动只能选择其中的一个。如果要使用另一个插件,就要手动修改一个gdb的初始化文件。为了方便使用不同的插件,这里写一个脚本来控制插件的选择,使得我们能够随心所欲的使用任何一个插件。

0x0001

首先,要安装三个插件

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/gef.sh | sh
wget -q -O ~/.gdbinit-gef.py https://github.com/hugsy/gef/raw/master/gef.py
echo source ~/.gdbinit-gef.py >> ~/.gdbinit

Gdbinit——这个建议不装

还不知道具体怎么用,之后安装的时候出现过一些问题,把这个删掉就好了,可能和pwndbg的某些脚本不能兼容

wget https://raw.githubusercontent.com/gdbinit/Gdbinit/master/gdbinit
cp gbdinit ~/.gdbinit

Pwndbg

git clone https://github.com/pwndbg/pwndbg
cd pwndbg
./setup.sh

上面的几个都安装好之后,我们就可以开始配置选择了

0x0002

找到文件 .gdbinit (我的是在root目录下),一般安装好pwndbg之后,这个文件是这样的

反正有很多东西就是,在文件最后会找到这个

这个 source 就是控制我们的gdb使用的是哪个插件,由于安装顺序的缘故,最后这里被覆盖成最后一次安装的结果了,我是最后装的pwndbg,所以这里指向pwndbg插件

我们首先加一个可以识别的字符串,我添加的是:#this place is controled by user's shell

其实不管是什么,只要是注释就行,不要和别的位置重复就行

并且把原本的source注释掉,现在的状态是没有选择插件,运行的gdb应该是最初没有插件的状态

0x0003

我们写一个选择插件的脚本:

#!/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")     
           #此处上面的查找内容要和你自己的保持一致

 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 里面了

顺便可以看看权限,能不能执行,不能的话加上权限chmod 700 gdb.sh

0x0004

现在我们就可以检验一下我们脚本的效果:

Gef

Peda

Pwndbg

OK,现在想用哪个插件,就可以使用哪个了。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP