IDA Pro MCP

by mrexodia
Verified
MIT License
1,471
  • Linux
  • Apple

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Integrates with GitHub for repository management, as the MCP server itself is hosted on GitHub and references GitHub resources.

IDA Pro MCP

简单的MCP 服务器允许在 IDA Pro 中进行氛围逆转。

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

视频的二进制文件和提示可在mcp-reversing-dataset存储库中找到。

可用功能:

  • check_connection :检查 IDA 插件是否正在运行。
  • get_metadata() :获取有关当前 IDB 的元数据。
  • get_function_by_name(name) :通过名称获取函数。
  • get_function_by_address(address) :通过地址获取函数。
  • get_current_address() :获取用户当前选择的地址。
  • get_current_function() :获取用户当前选择的函数。
  • convert_number(text, size) :将数字(十进制、十六进制)转换为不同的表示形式。
  • list_functions(offset, count) :列出数据库中的所有函数(分页)。
  • list_strings(offset, count) :列出数据库中的所有字符串(分页)。
  • search_strings(pattern, offset, count) :搜索包含给定模式的字符串(不区分大小写)。
  • decompile_function(address) :反编译给定地址的函数。
  • disassemble_function(start_address) :获取函数的汇编代码(地址:指令;注释)。
  • get_xrefs_to(address) :获取对给定地址的所有交叉引用。
  • get_entry_points() :获取数据库中的所有入口点。
  • set_comment(address, comment) :为函数反汇编和伪代码中的给定地址设置注释。
  • rename_local_variable(function_address, old_name, new_name) :重命名函数中的局部变量。
  • rename_global_variable(old_name, new_name) :重命名全局变量。
  • set_global_variable_type(variable_name, new_type) :设置全局变量的类型。
  • rename_function(function_address, new_name) :重命名函数。
  • set_function_prototype(function_address, prototype) :设置函数的原型。
  • declare_c_type(c_declaration) :从 C 声明创建或更新本地类型。
  • set_local_variable_type(function_address, variable_name, new_type) :设置局部变量的类型。

先决条件

安装

安装(或升级)IDA Pro MCP 包:

pip install --upgrade git+https://github.com/mrexodia/ida-pro-mcp

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

ida-pro-mcp --install

重要提示:请确保完全重启 IDA/Visual Studio Code/Claude,以使安装生效。Claude 在后台运行,您需要通过托盘图标退出。

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

快速工程

LLM 容易出现幻觉,所以你的提示需要具体。对于逆向工程来说,整数和字节之间的转换尤其成问题。下面是一个最简单的示例提示,如果你使用其他提示取得了不错的效果,欢迎随时发起讨论或提交问题:

你的任务是使用 IDA Pro 分析一个 Crackme 文件。你可以使用 MCP 工具来检索信息。一般来说,使用以下策略:

  • 检查反编译并添加注释以说明您的发现
  • 将变量重命名为更合理的名称
  • 如有必要,更改变量和参数类型(尤其是指针和数组类型)
  • 更改函数名称,使其更具描述性
  • 如果需要更多详细信息,请拆解该函数并添加注释和您的发现
  • 切勿自行转换进制。如有需要,请使用 convert_number MCP 工具!
  • 不要尝试暴力破解,任何解决方案都只能通过反汇编和简单的 Python 脚本来获得。
  • 创建一份 report.md,其中包含你的发现和最后采取的步骤
  • 当你找到解决方案时,提示用户使用你找到的密码进行反馈

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

提高法学硕士(LLM)准确性的技巧

大型语言模型 (LLM) 是强大的工具,但它们有时会难以处理复杂的数学计算,或出现“幻觉”(即虚构事实)。请务必告知 LLM 使用conver_number MCP,并且您可能还需要math-mcp进行某些操作。

另外需要注意的是,LLM 在处理混淆代码时效果不佳。在尝试使用 LLM 解决问题之前,请先检查一下二进制文件,并花些时间(自动)删除以下内容:

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

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

手动安装

注意:本节适用于需要详细安装说明的 LLM 和高级用户。

手动安装 MCP 服务器(Cline/Roo 代码)

要自行安装 MCP 服务器,请按照以下步骤操作:

  1. 全局安装uv
    • Windows: pip install uv
    • Linux/Mac: curl -LsSf https://astral.sh/uv/install.sh | sh
  2. 克隆此存储库,例如C:\MCP\ida-pro-mcp
  3. 导航到 Cline/Roo Code MCP 服务器配置(见屏幕截图)。
  4. 单击*“已安装*”选项卡。
  5. 单击配置 MCP 服务器,将打开cline_mcp_settings.json
  6. 添加ida-pro-mcp服务器:
{ "mcpServers": { "github.com/mrexodia/ida-pro-mcp": { "command": "uv", "args": [ "--directory", "c:\\MCP\\ida-pro-mcp", "run", "server.py", "--install-plugin" ], "timeout": 1800, "disabled": false, "autoApprove": [ "check_connection", "get_metadata", "get_function_by_name", "get_function_by_address", "get_current_address", "get_current_function", "convert_number", "list_functions", "list_strings", "search_strings", "decompile_function", "disassemble_function", "get_xrefs_to", "get_entry_points", "set_comment", "rename_local_variable", "rename_global_variable", "set_global_variable_type", "rename_function", "set_function_prototype", "declare_c_type", "set_local_variable_type" ], "alwaysAllow": [ "check_connection", "get_metadata", "get_function_by_name", "get_function_by_address", "get_current_address", "get_current_function", "convert_number", "list_functions", "list_strings", "search_strings", "decompile_function", "disassemble_function", "get_xrefs_to", "get_entry_points", "set_comment", "rename_local_variable", "rename_global_variable", "set_global_variable_type", "rename_function", "set_function_prototype", "declare_c_type", "set_local_variable_type" ] } } }

要检查连接是否有效,您可以执行以下工具调用:

<use_mcp_tool> <server_name>github.com/mrexodia/ida-pro-mcp</server_name> <tool_name>check_connection</tool_name> <arguments></arguments> </use_mcp_tool>

IDA插件安装

MCP 服务器启动时,IDA Pro 插件将自动安装。如果您禁用了--install-plugin选项,请按照以下步骤操作:

  1. src/ida_pro_mcp/mcp-plugin.py复制(而不是移动)到您的插件文件夹(Windows 上为%appdata%\Hex-Rays\IDA Pro\plugins )中。
  2. 打开 IDB 并单击Edit -> Plugins -> MCP来启动服务器。

与其他 MCP 服务器的比较

目前市面上有一些 IDA Pro MCP 服务器,但我出于以下几个原因创建了自己的服务器:

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

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

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

发展

添加新功能的过程非常简单流畅。您只需在mcp-plugin.py中添加一个新的@jsonrpc函数,即可在 MCP 服务器中使用,无需任何额外的样板代码!以下视频演示了我在不到 2 分钟的时间内(包括测试)添加get_metadata函数的过程:

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

要测试 MCP 服务器本身:

uv run mcp dev src/ida_pro_mcp/server.py

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

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

uv run ida-pro-mcp --install

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

git log --first-parent --no-merges 1.2.0..main "--pretty=- %s"
ID: 35q428b8zg