gdb可以使用python來進行配置,為自動化調試與格式化顯示提供非常方便的功能,具體可以自行搜索。加載了以下介紹的界面程序,還是可以在gdb運行的時候繼續加載自己定義的python插件腳本,只要自己的腳本不設計到界面定義就行,不然界面會亂。因此,用下面的插件,就不能用gdbtui了,不然界面就變了,雖然gdbtui也非常好用。其實,用了gdb-dashboard就基本可以不用tui了,因為tui就只有一個自動顯示source的功能,這個功能gdb-dashboard也有。
對於 lldb,可以參考 https://github.com/snare/voltron , Voltron is an extensible debugger UI toolkit written in Python. It aims to improve the user experience of various debuggers (LLDB, GDB, VDB and WinDbg) by enabling the attachment of utility views that can retrieve and display data from the debugger host.
gdb還有一些開源的配置插件,都是在 ~/.gdbinit 里直接寫代碼,或間接加載代碼 ( 如 source /home/hzh/disk2/github/pwndbg/gdbinit.py 或 sourc /home/hzh/disk2/github/gdb-dashboard/.gdbinit)。這些開源插件如下,按我最喜歡的優先級進行排序:
1、gdb-dashboard
https://github.com/cyrus-and/gdb-dashboard
它主要是能自動顯示很多彩色的窗口,支持簡單的代碼語法高亮,我最喜歡的功能就是它可以設置在不同的tty里顯示不同的窗口(后來發現gef也可以,即gef config context.redirect,所以gef應該排第一了),這個功能讓我把它排第一。
請注意,它的源代碼窗口最大只能顯示10行代碼(就算在全新的窗口顯示也是這樣),我們可以通過修改它的配置文件來讓它滿屏顯示:
dashboard source -style height 40
其中40就是終端的最大行數,可以用:
tput lines
得到,但是我們一般將得到的數值減去2,避免屏幕溢出。
附加:
其實gdb-dashboard配置代碼里的:
try: width, height = Dashboard.get_term_size(fd) except: width, height = Dashboard.get_term_size()
是可以得到終端的長寬的。
2、gef
https://github.com/hugsy/gef
它需要本機安裝有 pyenv (一個管理python版本的軟件)。但是可以手動將其改掉,就是將它的 gef.py 里的 site_packages_dir 直接改稱自己的python site_packages 目錄,可以這樣得到:
$ python -c 'import site; print(site.getsitepackages())'
改變source code 顯示窗的高度: gef config 可以打印和配置所有的配置選項,要打印某條配置的幫助直接敲入如 gef config context.redirect。另如: gef config context.nb_lines_code 25 可以配置source code窗口的大小,配置后不用重啟,直接敲 context 就可以更新顯示。
配置窗體的顯示或隱藏: 全部顯示: gef config context.layout "legend regs stack code args source memory threads trace extra", 部分顯示只需要刪掉其中一些就行了,其中的code是說的匯編代碼。一般調試主要使用 gef config context.layout "-legend -regs stack -code args source memory threads trace extra"
legend
: a text explanation of the color coderegs
: the state of registersstack
: the content of memory pointed by$sp
registercode
: the code being executedargs
: if stopping at a function calls, print the call argumentssource
: if compiled with source, this will show the corresponding line of source codethreads
: all the threadstrace
: the execution call traceextra
: if an automatic behavior is detected (vulnerable format string, heap vulnerability, etc.) it will be displayed in this panememory
: peek into arbitrary memory locations
如果你只想臨時顯示某個contex窗口,則在gef命令行鍵入: context regs
Redirecting context output to another tty/file (將顯示重定向到單獨的tty,參考文檔:https://gef.readthedocs.io/en/master/commands/context/):
先查找你窗口的tty: $ tty 輸出為 /dev/pts/x
然后在gef命令行鍵入: gef config context.redirect /dev/pts/x 如果想要回歸正常則鍵入: gef config context.redirect ""
若gef運行在tmux環境里,它的 tmux-setup 命令能將自己的界面split成左右兩半,左邊只輸入命令,右邊是context窗口,這樣可以實現gdb(及gef)命令與顯示窗體分離,比較清爽。
文檔:
https://gef.readthedocs.io/en/master/
3、PwnDbg
https://github.com/pwndbg/pwndbg
它不需要安裝pyenv,但還是將它排在gef的后面,因為gef實在是輕巧且配置靈活,其實它們都差不多,都是主要調試二進制文件的(破解?),方便查看heap,stack及內存的值等,打印出來閱讀方便。
修改source code顯示行數的方法:
在配置文件搜索 context-source-code-lines 或 source_code_lines,將里面的10改稱你要的,需要重啟。
可以在調試的時候使用 config source 或 config tty來獲取幫助,這只是獲取幫助,沒有在線配置功能,智能改配置文件然后重啟。
每次刷新主顯示窗口,敲 context 就可以。
文檔:
https://browserpwndbg.readthedocs.io/en/docs/
4、radare2
https://github.com/radareorg/radare2
主要拿來做逆向工程用的,二進制文件分析。
5、peda
https://github.com/longld/peda
和PwnDbg及gef差不多,但是代碼很久沒更新了。
6、Gdbinit
https://github.com/gdbinit/Gdbinit
就是一般的gdb彩色顯示配置,功能簡單,入門級。
最后,gdb-dashboard、PwnDbg、gef、radare2、peda、Gdbinit 的自動切換,其實就是切換配置文件:
先把他們全部裝上,當然你可以選擇自己感興趣的安裝,他們的配置都需要通過 ~/.gdbinit 來配置,因此他們是互斥的,配置里只能配置一種,但是可以用下面的這種方法解決,下面的示例只寫了 peda、PwnDbg和gef,其它自己加。
1、Open your .gdbinit
file, 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
Then, create the following 3 files in one of your $PATH
folder:
First create a file named by gdb-peda
and paste the following:
#!/bin/sh exec gdb -q -ex init-peda "$@"
Then gdb-pwndbg:
#!/bin/sh exec gdb -q -ex init-pwndbg "$@"
Then gdb-gef:
#!/bin/sh exec gdb -q -ex init-gef "$@"
最后修改它們的可執行權限:
chmod +x /usr/bin/gdb-*
然后你就可以使用 gdb-peda, gdb-pwndbg 或 gdb-gef 來運行相應的gdb plugin版了。