IDA Pro MCP服务器

IDA Pro MCP服务器是一个用于在IDA Pro中进行逆向工程分析的插件,支持多种MCP客户端,提供丰富的API功能。

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

使用说明

IDA Pro MCP

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

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

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

先决条件

安装

安装最新版本的IDA Pro 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)在后台运行,需要从托盘图标中退出。

https://github.com/user-attachments/assets/65ed3373-a187-4dd5-a807-425dca1d8ee9

备注:在插件菜单显示之前,您需要在IDA中加载一个二进制文件。

提示工程

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 您还可以运行一个无头SSE服务器:

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

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

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):获取地址处函数调用的函数。

修改操作

  • set_comments(items):在反汇编和反编译器视图中的地址处设置注释。
  • patch_asm(items):地址处的补丁组装说明。
  • declare_type(decls):在本地类型库中声明C类型。

内存读取操作

  • 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 大型项目中的电话

与其他MCP服务器的比较

周围有一些IDA Pro MCP服务器,但我创建了自己的服务器,原因有几个:

  1. 安装应完全自动化。
  2. 其他插件的架构使得快速添加新功能变得困难(不必要的依赖关系的样板太多)。
  3. 学习新技术很有趣!

如果你想查看它们,这里有一个列表(按照我发现它们的顺序):

  • https://github.com/taida957789/ida-mcp-server-plugin(仅限SSE协议,需要在IDAPython中安装依赖项)。
  • https://github.com/fdrechsler/mcp-server-idapro(TypeScript中的MCP服务器,添加新功能需要过多的样板)。
  • https://github.com/MxIris-Reverse-Engineering/ida-mcp-server(自定义套接字协议,样板)。

请在此处打开PR以添加您的IDA Pro MCP服务器。

发展

添加新功能是一个超级简单和简化的过程。你所要做的就是添加一个新的 @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"