背景知识
内存
栈
堆
与栈情况类似,但存储的是文件之类的数据
GDB基本调试命令
GDB基本调试命令 如何使用 GDB
GDB工具使用前期配置
设置对core文件输出大小无限制
1 2 3 4 5 6 7 8 9 10
| su root
vi /etc/profile Shift + G i
ulimit -S -c unlimited > /dev/null 2>&1 wq!
source /etc/profile
|
提示
在图形界面的虚拟终端下,可能需要每次启动都source一遍/etc/profile,请把source加入你的~/.bashrc或~/.zshrc第一行
设置croe信息转储
core文件同名会覆盖. 这里为其加上一个 core命名规则, 让其变成 [core.pid] 格式.
1 2 3 4 5 6 7 8 9 10 11 12 13
| su root
vi /etc/sysctl.conf Shift + G i
kernel.core_pattern = ./core_%t_%p_%e kernel.core_uses_pid = 1
wq!
sysctl -p /etc/sysctl.conf
|
配置peda
1 2
| git clone https://github.com/longld/peda.git ~/peda echo "source ~/peda/peda.py" >> ~/.gdbinit
|
GDB使用
常见用法
- 调试程序。有几种方法可以在gdb下运行你的程序:
- gdb ${你的程序} 进入gdb后,输入run(简写r) ${arg1} ${arg2} … ${argN}
- gdb --args ${你的程序} ${arg1} ${arg2} … ${argN} 进入gdb后,运行run。
- gdb进入gdb后,输入file ${你的程序}。然后使用set args ${arg1} ${arg2} … ${argN} 设定好你的程序参数,再运行run。
- 调试正在运行的程序:
- 查core:
- gdb ${你的程序} -core ${core文件}
静默模式启动gdb
gdb -q
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| gdb:b (break) #设置断点
b func_name #对函数下断点
b *addr #对地址下断点
info b # 查看断点
delete 用法:delete [breakpoints num] [range...] delete可删除单个断点,也可删除一个断点的集合,这个集合用连续的断点号来描述。 例如: delete 5 delete 1-10
clear 用法:clear 删除所在行的多有断点。 clear location clear 删除所选定的环境中所有的断点 clear location location描述具体的断点。 例如: clear list_insert //删除函数的所有断点 clear list.c:list_delet //删除文件:函数的所有断点 clear 12 //删除行号的所有断点 clear list.c:12 //删除文件:行号的所有断点
clear 删除断点是基于行的,不是把所有的断点都删除。
r #启动加载的程序
gdb:disas main #查看函数汇编指令
info r(egister) #查看寄存器情况
ni #单步调试
si #step into 步进 进到某个函数里面
bt #backtrace 查看现在的堆栈情况 对于了解程序执行比较有用
c #continue #继续执行到下一个断点
x /100xg $rsp #以八进制查看从栈顶开始的100字节
|
pattern 工具
1 2 3 4
| pattern 指令,生成长字符串,
pattern create 150 #生成一个长度为150字节的字符串 pattern offset rip地址 #判断从多少字节开始溢出,前提是程序非正常退出,rip内容被覆盖
|
参考资料
http://yaov.net/2018/09/15/linux-pwn%E5%9F%BA%E7%A1%801/