一直以来都在使用tmux作为终端复用的工具,非常喜欢它可以自由切换、分割当前终端的功能。现在自己每次都是通过ssh登录到调试机,然后使用tmux创建一个session在后台,这样就算因为网络原因ssh断掉,当前终端正在进行的工作也不会断掉。
最基础的流程就是:
更多操作可以参考这个教程:Tmux 使用教程 - 阮一峰的网络日志
最近在看pwndbg的FEATURES.md时,发现其支持一个特性:将其section重定向到任意的tty。那么通过这个功能就可以实现将pwndbg的各个section重定向到终端由tmux切割出来的不同pane上,从而最大化利用当前的屏幕(也更好看)。
也有人在pwndbg的基础上开发出了另外一个插件splitmind,其官方库中给出的一个实现效果如下,在一个由tmux分割的终端上,让pwndbg调试信息区域按照使用人员最喜欢的方式排列、输出。
如上的实现配置文件gdb.init如下,其大概原理就是:在tmux的一个window中,会默认打开一个名为main的gdb调试pane,然后基于该main的上、下、左、右可以自由进行窗口的切割和划分,并将pwndbg相应的section重定向到切割出来的pane中。
例如:.above(of="main", display="disasm", size="80%", banner="top")
,就是对main进行切割,展示pwndbg的disasm区域,并且控制所占据的大小为80%。
pwndbg所支持的section如下,在gdb中由context-sections
变量控制:
与之配合的还有一些其他的gdb调试环境变量,例如
等等,这些都可以在pwndbg/pwndbg/commands/context.py
去查询含义以及默认值。了解section和控制section大小的环境变量可以让我们更好自定义属于自己的gdb界面。
在如上的基础上,我定制了自己的一个gdb配置,能达到的效果就是,在gdb启动的时候选择模式,并按照自己的习惯展示gdb调试信息:
s:源码模式,如下
d:汇编模式,如下
m:混合模式,如下
那么直接给出我的gdb配置文件,也给出了相应的注释,更多的配置还可以参考我个人的GitHub配置文件库:
source
/
home
/
user
/
pwndbg
/
gdbinit.py
set
context
-
clear
-
screen on
set
follow
-
fork
-
mode parent
source
/
home
/
user
/
splitmind
/
gdbinit.py
python
import
splitmind
(splitmind.Mind()
.tell_splitter(show_titles
=
True
)
.tell_splitter(set_title
=
"Main"
)
.right(display
=
"backtrace"
, size
=
"25%"
)
.above(of
=
"main"
, display
=
"disasm"
, size
=
"80%"
, banner
=
"top"
)
.show(
"code"
, on
=
"disasm"
, banner
=
"none"
)
.right(cmd
=
'tty; tail -f /dev/null'
, size
=
"65%"
, clearing
=
False
)
.tell_splitter(set_title
=
'Input / Output'
)
.above(display
=
"stack"
, size
=
"75%"
)
.above(display
=
"legend"
, size
=
"25"
)
.show(
"regs"
, on
=
"legend"
)
.below(of
=
"backtrace"
, cmd
=
"ipython"
, size
=
"30%"
)
).build(nobanner
=
True
)
end
set
context
-
code
-
lines
30
set
context
-
source
-
code
-
lines
30
set
context
-
sections
"regs args code disasm stack backtrace"
source
/
home
/
user
/
pwndbg
/
gdbinit.py
set
context
-
clear
-
screen on
set
follow
-
fork
-
mode parent
source
/
home
/
user
/
splitmind
/
gdbinit.py
python
import
splitmind
(splitmind.Mind()
.tell_splitter(show_titles
=
True
)
.tell_splitter(set_title
=
"Main"
)
.right(display
=
"backtrace"
, size
=
"25%"
)
.above(of
=
"main"
, display
=
"disasm"
, size
=
"80%"
, banner
=
"top"
)
.show(
"code"
, on
=
"disasm"
, banner
=
"none"
)
.right(cmd
=
'tty; tail -f /dev/null'
, size
=
"65%"
, clearing
=
False
)
.tell_splitter(set_title
=
'Input / Output'
)
.above(display
=
"stack"
, size
=
"75%"
)
.above(display
=
"legend"
, size
=
"25"
)
.show(
"regs"
, on
=
"legend"
)
.below(of
=
"backtrace"
, cmd
=
"ipython"
, size
=
"30%"
)
).build(nobanner
=
True
)
end
set
context
-
code
-
lines
30
set
context
-
source
-
code
-
lines
30
set
context
-
sections
"regs args code disasm stack backtrace"
source
/
home
/
utest
/
app
/
pwndbg
/
gdbinit.py
source
/
home
/
utest
/
app
/
splitmind
/
gdbinit.py
set
context
-
clear
-
screen off
set
debug
-
events off
python
sections
=
"regs"
mode
=
input
(
"source/disasm/mixed mode:?(s/d/m)"
)
or
"d"
import
splitmind
spliter
=
splitmind.Mind()
spliter.select(
"main"
).right(display
=
"regs"
, size
=
"50%"
)
legend_on
=
"code"
if
mode
=
=
"d"
:
legend_on
=
"disasm"
sections
+
=
" disasm"
spliter.select(
"main"
).above(display
=
"disasm"
, size
=
"70%"
, banner
=
"none"
)
gdb.execute(
"set context-code-lines 30"
)
elif
mode
=
=
"s"
:
sections
+
=
" code"
spliter.select(
"main"
).above(display
=
"code"
, size
=
"70%"
, banner
=
"none"
)
gdb.execute(
"set context-source-code-lines 30"
)
else
:
sections
+
=
" disasm code"
spliter.select(
"main"
).above(display
=
"code"
, size
=
"70%"
)
spliter.select(
"code"
).below(display
=
"disasm"
, size
=
"40%"
)
gdb.execute(
"set context-code-lines 8"
)
gdb.execute(
"set context-source-code-lines 20"
)
sections
+
=
" args stack backtrace expressions"
spliter.show(
"legend"
, on
=
legend_on)
spliter.show(
"stack"
, on
=
"regs"
)
spliter.show(
"backtrace"
, on
=
"regs"
)
spliter.show(
"args"
, on
=
"regs"
)
spliter.show(
"expressions"
, on
=
"args"
)
gdb.execute(
"set context-stack-lines 10"
)
gdb.execute(
"set context-sections \"%s\""
%
sections)
spliter.build()
end
source
/
home
/
utest
/
app
/
pwndbg
/
gdbinit.py
source
/
home
/
utest
/
app
/
splitmind
/
gdbinit.py
set
context
-
clear
-
screen off
set
debug
-
events off
python
sections
=
"regs"
mode
=
input
(
"source/disasm/mixed mode:?(s/d/m)"
)
or
"d"
import
splitmind
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)