gdb-mcp 是一款高权限模型上下文协议(MCP)服务端,可让 Codex 通过 GDB/MI 接口与 pygdbmi 库控制 GDB 调试器。
该项目主要支持的部署架构:
Windows 上的 Codex
-> Windows 上的 gdb-mcp MCP 服务端
-> Windows 本地 GDB
-> target remote / target extended-remote
-> linux 虚拟机中的 gdbserver
-> 虚拟机内的目标程序
本服务端专为本地授权调试、CTF Pwn 解题、崩溃分析、Core Dump 分析、漏洞利用复现、ELF 文件分析场景设计。高风险 GDB 命令不会被永久禁用,首次执行会返回警告,调用方在重试时传入 confirm=true 即可运行。
gdb_session:本地 GDB 会话的启动、停止、重启与状态查询gdb_load:加载本地二进制文件、Core 文件、符号文件与启动参数gdb_exec:通用 GDB CLI 命令执行入口gdb_mi:原生 GDB/MI 命令执行入口gdb_remote:配置并连接虚拟机端gdbservergdb_context:查看寄存器、栈、反汇编、调用栈、断点、内存映射、共享库gdb_memory:内存读取、写入、搜索与转储gdb_register:寄存器读写gdb_breakpoint:普通断点、硬件断点、临时断点、观察点gdb_run_control:运行、继续、单步步入、步过、指令级单步、执行完函数、中断、杀死程序、重启gdb_analyze:崩溃与漏洞利用可行性分析gdb_elf:安全检查(checksec)、ELF 头、节、段、符号、GOT/PLT、重定位、字符串gdb_pwndbg:兼容执行 pwndbg/gef/peda 命令
所有工具返回统一 JSON 结构:
{
"ok": true,
"tool": "gdb_exec",
"action": "exec",
"risk_level": "low",
"need_confirm": false,
"executed_with_risk": false,
"warning": null,
"data": {},
"stdout": "",
"stderr": "",
"raw": {},
"error": null
}
git clone https://github.com/traver88/gdb-mcp.git
本项目支持的运行环境为 Python 3.12。
python --version
python -m venv .venv
.\.venv\Scripts\activate
pip install -e .
- 安装 MSYS2
- 打开 MSYS2 MinGW64 终端
- 执行:
pacman -Syu # 之后重启 MSYS2
pacman -S gdb gdb-multiarch
- 将
C:\msys64\mingw64\bin加入 WindowsPATH - 验证:
gdb --version
gdb-multiarch --version
gdb-mcp项目目录下:
.\.venv\Scripts\activate
python tests\smoke_test.py
成功会输出:
smoke test passed
smoke_test.py测试内容:
- 启动 Windows 本地 GDB
- 加载
examples/hello.c编译的测试程序 - 在
main下断点 - 运行程序
- 读取寄存器
- 读取栈
- 反汇编
- 关闭 GDB
sudo apt update
sudo apt install -y gdbserver gdb gcc make binutils file
cd xxx/xxx/
gdbserver 0.0.0.0:1234 ./pwn
powershell:
ping 192.168.56.101
Test-NetConnection 192.168.56.101 -Port 1234
[mcp_servers.gdb-mcp]
command = "D:\\gdb-mcp\\.venv\\Scripts\\python.exe"
args = ["D:\\gdb-mcp\\server.py"]
command:指向启动 MCP 服务端的 Python 程序args:指向server.py服务端入口
需求示例:
请使用 gdb-mcp:
- 启动 GDB
- 加载本地符号文件 E:/ctf/pwn/pwn
- 连接 192.168.56.101:1234 的 gdbserver
- 在 main 下断点
- continue
- 显示寄存器、栈、RIP 附近反汇编、backtrace
等价 MCP 调用:
gdb_session(action="start")
gdb_remote(
action="connect",
host="192.168.56.101",
port=1234,
mode="remote",
local_binary="E:/ctf/pwn/pwn",
confirm=true
)
gdb_breakpoint(action="add", location="main")
gdb_run_control(action="continue")
gdb_register(action="read_all")
gdb_memory(action="read", address="$rsp", size=160)
gdb_exec(command="x/20i $rip")
gdb_exec(command="bt")
gdb_context(depth=20)
等价 GDB 命令:
file "E:/ctf/pwn/pwn"
target remote 192.168.56.101:1234
b main
c
info registers
x/20gx $rsp
x/20i $rip
bt
虚拟机:
gdbserver --multi 0.0.0.0:1234
MCP 调用:
gdb_remote(
action="connect",
host="192.168.56.101",
port=1234,
mode="extended-remote",
local_binary="E:/ctf/pwn/pwn",
remote_binary="/xxx/pwn",
confirm=true
)
gdb_breakpoint(action="add", location="main")
gdb_run_control(action="run")
gdb_context(depth=20)
内部 GDB 命令:
file "E:/ctf/pwn/pwn"
set remote exec-file /xxx/pwn
target extended-remote 192.168.56.101:1234
- Windows 无法 ping 通虚拟机:检查虚拟机 IP 与网卡模式
- 1234 端口无法连接:确认
gdbserver正在运行 gdbserver仅监听本地:使用gdbserver 0.0.0.0:1234 ./pwn- Windows 防火墙拦截:放行 GDB 或对应端口
- 虚拟机 NAT 模式无法访问:改用仅主机 / 桥接网卡或配置端口转发
local_binary与remote_binary混淆:前者为 Windows 路径,后者为 Linux 路径- Windows GDB 无法解析 Linux ELF:使用对应架构的多架构 GDB
- 远程模式下
info proc mappings不可用:gdb_context会标记为不可用而非崩溃 - 远程 libc 符号缺失:使用
gdb_remote(action="set_sysroot", ...)或set_solib_search_path
需确认的高风险命令示例:
target remote HOST:PORTtarget extended-remote HOST:PORTdisconnectdetachset remote exec-file PATHset sysroot PATHset solib-search-path PATHshell ...source ...python ...dump memory ...restore ...maintenance ...
首次调用:
gdb_exec(command="target remote 192.168.56.101:1234")
服务端返回 need_confirm=true,带确认重试:
gdb_exec(command="target remote 192.168.56.101:1234", confirm=true)
执行后返回中 executed_with_risk=true。