[ERROR] Could not find a terminal binary to use. Set context.terminal to your terminal报错的解决办法(亲测有效!)

一、问题描述

在通过ssh连接服务器,在命令行界面进行pwntools的实验中,在调用gdb进行debug时会报这样一个错

[ERROR] Could not find a terminal binary to use. Set context.terminal to your terminal,如下图所示

 其中部分实验代码如下:

from pwn import *

sh = process('./leakmemory')

...

gdb.attach(sh)

...

经过对源码的分析,我们知道是脚本在第9行调用gdb对sh进程进行debug时,需要新开一个终端,也就是说在前面对新开终端的参数进行设置(即context.terminal=[])。

一开始我到/usr/bin下找类似terminal、gnome-terminal的指令,因为我本能的就将context.terminal=['gnome-terminal','sh',-x]进行设置,然后运行脚本的时候发现程序卡在waiting for debugger的进度,最后发现这个服务器并没有安装gnome...都ssh连接了...

二、解决办法

使用tmux。

1、在gdb.attach()命令行之前加一句:

context.terminal = ['tmux','splitw','-h']

(后面俩参数代表分割窗口和方向)

2、并将gdb.attach(sh)改为:

gdb.attach(proc.pidof(sh)[0],gdbscript="b main")

注意这里proc.pidof()中的参数对应为前面开了的进程对应的变量sh,是因为sh = process('./leakmemory')

如果是ssh连接,用vi或vim编辑的话,记得保存修改后的脚本(先按Esc退出编辑模式,然后输入冒号“:”,输入wq再按回车,保存并退出编辑)

2、运行脚本的时候,先输入tmux,再输入python exploit.py,然后就可以发现使用gdb进行debug了,整个命令行界面分为一左一右两部分,右边是gdb进行debug,非常酷炫

发布了49 篇原创文章 · 获赞 26 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/weixin_36711901/article/details/103737735