IDA Pro MCP服务器

IDA Pro MCP服务器是一款用于逆向工程的工具,通过MCP协议与多种客户端集成,提供函数分析、类型转换、内存读取等功能。

  • by supitsmike
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 supitsmike/ida-pro-mcp

使用说明

IDA Pro MCP

简单 MCP服务器 允许IDA Pro中的氛围反转。

https://github.com/user-attachments/assets/6ebeaa92-a9db-43fa-b756-eececce2aca0

视频的二进制文件和提示可在 mcp反向数据集 存储库。

先决条件

安装(克劳德代码)

在Claude Code中安装无头IDA Pro MCP:

claude plugin marketplace add mrexodia/claude-marketplace
claude plugin install ida-pro-mcp@mrexodia

要更新到最新版本:

claude plugin update ida-pro-mcp@mrexodia

备注:这需要全局激活idalib 紫外线 安装:

# windows
uv run "C:\Program Files\IDA Professional 9.3\idalib\python\py-activate-idalib.py"
# macos
uv run "/Applications/IDA Professional 9.3.app/Contents/MacOS/idalib/python/py-activate-idalib.py"

安装(GUI)

备注:不再推荐MCP插件,最终将被弃用。使用 idalib-mcp 相反。

如果要从IDA GUI手动配置MCP服务器:

pip uninstall ida-pro-mcp
pip install https://github.com/mrexodia/ida-pro-mcp/archive/refs/heads/main.zip

配置MCP服务器并安装IDA插件:

ida-pro-mcp --install

重要:确保您完全重新启动IDA和MCP客户端,以便安装生效。一些客户端(如Claude)在后台运行,需要从托盘图标中退出。

提示工程

LLMs容易产生幻觉,你需要明确你的提示。对于逆向工程,整数和字节之间的转换尤其成问题。下面是一个最小的示例提示,如果您使用不同的提示获得了良好的结果,请随时开始讨论或打开问题:

Your task is to analyze a crackme in IDA Pro. You can use the MCP tools to retrieve information. In general use the following strategy:

- Inspect the decompilation and add comments with your findings
- Rename variables to more sensible names
- Change the variable and argument types if necessary (especially pointer and array types)
- Change function names to be more descriptive
- If more details are necessary, disassemble the function and add comments with your findings
- NEVER convert number bases yourself. Use the `int_convert` MCP tool if needed!
- Do not attempt brute forcing, derive any solutions purely from the disassembly and simple python scripts
- Create a report.md with your findings and steps taken at the end
- When you find a solution, prompt to user for feedback with the password you found

这个提示只是第一个实验,如果你找到了提高输出的方法,请分享!

另一个提示由 @公元1357年:

Your task is to create a complete and comprehensive reverse engineering analysis. Reference AGENTS.md to understand the project goals and ensure the analysis serves our purposes.

Use the following systematic methodology:

1. **Decompilation Analysis**
   - Thoroughly inspect the decompiler output
   - Add detailed comments documenting your findings
   - Focus on understanding the actual functionality and purpose of each component (do not rely on old, incorrect comments)

2. **Improve Readability in the Database**
   - Rename variables to sensible, descriptive names
   - Correct variable and argument types where necessary (especially pointers and array types)
   - Update function names to be descriptive of their actual purpose

3. **Deep Dive When Needed**
   - If more details are necessary, examine the disassembly and add comments with findings
   - Document any low-level behaviors that aren't clear from the decompilation alone
   - Use sub-agents to perform detailed analysis

4. **Important Constraints**
   - NEVER convert number bases yourself - use the int_convert MCP tool if needed
   - Use MCP tools to retrieve information as necessary
   - Derive all conclusions from actual analysis, not assumptions

5. **Documentation**
   - Produce comprehensive RE/*.md files with your findings
   - Document the steps taken and methodology used
   - When asked by the user, ensure accuracy over previous analysis file
   - Organize findings in a way that serves the project goals outlined in AGENTS.md or CLAUDE.md

直播讨论提示并显示一些真实世界的恶意软件分析:

提高LLM准确性的技巧

大型语言模型(LLM)是强大的工具,但它们有时会难以处理复杂的数学计算或表现出“幻觉”(编造事实)。确保告诉LLM使用 int_convert MCP工具,您可能还需要 数学mcp 对于某些操作。

另一件要记住的事情是,LLM在混淆的代码上表现不佳。在尝试使用LLM解决问题之前,先看看二进制文件,花一些时间(自动)删除以下内容:

  • 字符串加密
  • 导入哈希
  • 控制流扁平化
  • 代码加密
  • 反反编译技巧

您还应该使用Lumina或FLIRT等工具来尝试解析所有开源库代码和C++STL,这将进一步提高准确性。

运输和无头MCP

您可以运行SSE服务器连接到用户界面,如下所示:

uv run ida-pro-mcp --transport http://127.0.0.1:8744/sse

安装后 idalib 您还可以运行无头MCP服务器。您可以从初始二进制文件开始:

uv run idalib-mcp --host 127.0.0.1 --port 8745 path/to/executable

或者在没有二进制文件的情况下开始,稍后使用打开任意文件 idb_open(...):

uv run idalib-mcp --host 127.0.0.1 --port 8745

对于基于stdio的客户端,请使用:

uv run idalib-mcp --stdio

数据库工作进程是持久的:每个工作进程都作为一个独立的进程运行 当一个新的主管(超过stdio) 或HTTP)调用 idb_open 对于已经在worker下打开的二进制文件 在这个主机上,主管透明地采用该员工—— 没有单独的“共享”模式可启用。当没有请求时,工人自动退出 打他们一段空闲时间。

备注:The idalib 该功能由以下人员贡献 Willi Ballenthin.

无头idalib会话模型

idalib-mcp 是一个监督程序,它将每个打开的数据库保存在自己的idalib工作进程中。工人在主机本地发现目录中注册自己,并比产生他们的主管活得更久;任何想要相同路径的后续主管都会采用正在运行的worker。当没有请求到达其空闲TTL(默认1小时)时,工作进程会自动退出。没有 idb_close 工具——不再关心数据库的客户端只需停止使用它,只有用户可以关闭GUI窗口。

idb_open 通过其 mode 参数:

  • prefer_headless (默认):生成一个idalib worker(或采用一个已经打开文件的worker)。
  • force_headless:相同,但即使有文件,也永远不要采用正在运行的GUI。
  • prefer_gui:对文件采用运行GUI;否则生成一个idalib worker。
  • force_gui:对文件采用运行GUI;否则启动新的IDA GUI进程。

每个工具调用都必须包含一个显式 database 争论。没有隐式的“当前数据库”——调用者指定他们想要操作的会话名称。

uv run idalib-mcp --stdio --max-workers 4

典型流程:

idb_open("/path/to/binary_a.exe", preferred_session_id="binary_a")
idb_open("/path/to/library.dll", preferred_session_id="library")

decompile("main", database="binary_a")
xrefs_to("ImportantExport", database="library")

database 必须是由返回的会话ID idb_open (或如图所示 idb_list);不接受文件名和路径。

管理工具

  • idb_open(input_path, mode="prefer_headless", run_auto_analysis=True, build_caches=True, init_hexrays=True, preferred_session_id=""):打开二进制文件,预热子系统(字符串缓存、十六进制光线),并返回其会话ID。如果此路径的工作进程或GUI已在主机上运行,则采用该实例 preferred_session_id 被忽略。
  • idb_list():列出打开的会话和正在运行的GUI IDA实例。每个条目都有 adopted (如果此主管管理它,则为True,对于通过以下方式发现但尚未打开的GUI/工作人员,则为False idb_open), backend (worker 或 gui), is_active以及进程ID。
  • idb_save(session_id, path=""):将会话的IDB保存到磁盘。作为普通工人工具转发(database=<id> 注入)——两个后端都有相同的签名。
  • 根据数据库运行状况:调用 server_health(database=<id>) (转发)。 idb_list() 报告 is_active 来自主管的TCP/RPC探测。

工人控制:

  • --max-workers N:最大并发数据库工作者数(0 =无限制,默认 4).
  • IDA_MCP_MAX_WORKERS:环境默认值 --max-workers.

MCP资源

资源 表示遵循MCP哲学的可浏览状态(只读数据)。

IDB核心州:

  • ida://idb/metadata -IDB文件信息(路径、拱、基、大小、哈希)
  • ida://idb/segments -具有权限的内存段
  • ida://idb/entrypoints -入口点(主、TLS回调等)

UI状态:

  • ida://cursor -当前光标位置和功能
  • ida://selection -当前选择范围

类型信息:

  • ida://types -所有本地类型
  • ida://structs -所有结构/工会
  • ida://struct/{name} -带字段的结构定义

查询:

  • ida://import/{name} -按名称导入详细信息
  • ida://export/{name} -按名称导出详细信息
  • ida://xrefs/from/{addr} -地址的交叉引用

核心功能

  • lookup_funcs(queries):按地址或名称获取函数(自动检测,接受列表或逗号分隔的字符串)。
  • int_convert(inputs):将数字转换为不同的格式(十进制、十六进制、字节、ASCII、二进制)。
  • list_funcs(queries):列表函数(分页、筛选)。
  • list_globals(queries):列出全局变量(分页、筛选)。
  • imports(offset, count):列出所有带有模块名称的导入符号(分页)。
  • decompile(addr):在给定地址处分解函数。
  • disasm(addr):带完整细节(参数、堆栈框架等)的反汇编函数。
  • xrefs_to(addrs):获取地址的所有交叉引用。
  • xrefs_to_field(queries):获取对特定结构字段的交叉引用。
  • callees(addrs):获取地址处函数调用的函数。

修改操作

  • add_bookmark(addr, name, prefix):在地址处添加或替换IDA书签;集 prefix="" 没有前缀。
  • set_comments(items):在反汇编和反编译器视图中的地址处设置注释。
  • patch_asm(items):地址处的补丁组装说明。
  • declare_type(decls):在本地类型库中声明C类型。
  • define_func(items):在地址处定义功能。可选择指定 end 对于明确的界限。
  • define_code(items):将字节转换为地址处的代码指令。
  • undefine(items):取消定义地址处的项,转换回原始字节。可选择指定 end 或 size.

内存读取操作

  • get_bytes(addrs):读取地址处的原始字节。
  • get_int(queries):使用ty读取整数值(i8/u64/i16le/i16be/etc)。
  • get_string(addrs):读取以null结尾的字符串。
  • get_global_value(queries):按地址或名称读取全局变量值(自动检测、编译时值)。

堆栈框架操作

  • stack_frame(addrs):获取函数的堆栈帧变量。
  • declare_stack(items):在指定的偏移量处创建堆栈变量。
  • delete_stack(items):按名称删除堆栈变量。

结构操作

  • read_struct(queries):读取特定地址的结构字段值。
  • search_structs(filter):按名称模式搜索结构。

调试器操作(扩展)

默认情况下,调试器工具是隐藏的。启用 ?ext=dbg 查询参数:

http://127.0.0.1:13337/mcp?ext=dbg

控制:

  • dbg_start():启动调试器进程。
  • dbg_exit():退出调试器进程。
  • dbg_continue():继续执行。
  • dbg_run_to(addr):跑到地址。
  • dbg_step_into():进入指令。
  • dbg_step_over():跳过指令。

断点:

  • dbg_bps():列出所有断点。
  • dbg_add_bp(addrs):添加断点。
  • dbg_delete_bp(addrs):删除断点。
  • dbg_toggle_bp(items):启用/禁用断点。

寄存器:

  • dbg_regs():所有寄存器,当前线程。
  • dbg_regs_all():所有寄存器,所有线程。
  • dbg_regs_remote(tids):所有寄存器,特定线程。
  • dbg_gpregs():GP寄存器,当前线程。
  • dbg_gpregs_remote(tids):GP寄存器,特定线程。
  • dbg_regs_named(names):命名寄存器,当前线程。
  • dbg_regs_named_remote(tid, names):命名寄存器,特定线程。

堆栈和内存:

  • dbg_stacktrace():使用模块/符号信息调用堆栈。
  • dbg_read(regions):从调试进程中读取内存。
  • dbg_write(regions):将内存写入调试进程。

高级分析操作

  • py_eval(code):在IDA上下文中执行任意Python代码(返回带有result/stout/stderr的dict,支持Jupyter风格的求值)。
  • analyze_funcs(addrs):全面的函数分析(反编译、汇编、外部参照、被调用者、调用者、字符串、常量、基本块)。

模式匹配和搜索

  • find_regex(queries):使用不区分大小写的正则表达式(分页)搜索字符串。
  • find_bytes(patterns, limit=1000, offset=0):查找二进制中的字节模式(例如“48 8B????”)。最大限额:10000。
  • find_insns(sequences, limit=1000, offset=0):在代码中查找指令序列。最大限额:10000。
  • find(type, targets, limit=1000, offset=0):高级搜索(即时值、字符串、数据/代码引用)。最大限额:10000。

控制流分析

  • basic_blocks(addrs):获取继承者和前任的基本块。

类型操作

  • set_type(edits):将类型应用于函数、全局变量、局部变量或堆栈变量。
  • infer_types(addrs):使用十六进制射线或启发式方法推断地址处的类型。

出口业务

  • export_funcs(addrs, format):以指定格式导出函数(json、c_header或原型)。

图的运算

  • callgraph(roots, max_depth):从具有可配置深度的根函数构建调用图。

批量操作

  • rename(batch):函数、全局变量、局部变量和堆栈变量的统一批重命名操作(接受带可选参数的dict func, data, local, stack 按键)。
  • patch(patches):一次修补多个字节序列。
  • put_int(items):使用ty(i8/u64/i16le/i16be/etc)写入整数值。

主要特点:

  • 安全型API:所有函数都使用具有TypedDict模式的强类型参数,以获得更好的IDE支持和LLM结构化输出
  • 批量优先设计:大多数操作同时接受单个项目和列表
  • 一致的错误处理:所有批处理操作返回 [{..., error: null|string}, ...]
  • 基于光标的分页:搜索函数返回 cursor: {next: offset} 或 {done: true} (默认限制:1000,强制最大值:10000,以防止令牌溢出)
  • 演出:字符串以基于MD5的无效方式缓存,以避免重复 build_strlist 大型项目中的电话

发展

添加新功能是一个超级简单和简化的过程。你所要做的就是添加一个新的 @tool 中模块化API文件的函数 src/ida_pro_mcp/ida_mcp/api_*.py 您的功能将在MCP服务器中可用,无需任何额外的样板!下面是我添加的视频 get_metadata 在2分钟内完成功能(包括测试):

https://github.com/user-attachments/assets/951de823-88ea-4235-adcb-9257e316ae64

要测试MCP服务器本身:

npx -y @modelcontextprotocol/inspector

这将打开一个web界面http://localhost:5173并允许您与MCP工具进行交互以进行测试。

为了测试,我创建了一个指向IDA插件的符号链接,然后直接向POST发送JSON-RPC请求 http://localhost:13337/mcp.之后 启用符号链接 您可以运行以下命令:

uv run ida-pro-mcp --install

生成直接提交的变更日志 main:

git log --first-parent --no-merges 1.2.0..main "--pretty=- %s"