|
| 1 | +# Multi-Binary Binary Ninja MCP Setup |
| 2 | + |
| 3 | +This document describes how to set up and use the multi-binary functionality that allows you to work with multiple Binary Ninja instances simultaneously through the MCP bridge. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The multi-binary setup extends the original single-binary MCP bridge to support: |
| 8 | +- Multiple Binary Ninja instances running on different ports |
| 9 | +- Automatic server discovery and routing |
| 10 | +- Binary selection through MCP tools |
| 11 | +- Concurrent analysis of multiple binaries |
| 12 | + |
| 13 | +## Architecture |
| 14 | + |
| 15 | +``` |
| 16 | +MCP Client (Claude Desktop, etc.) |
| 17 | + ↓ |
| 18 | +MCP Bridge (port 8010) |
| 19 | + ↓ (routing based on binary_id) |
| 20 | +Multiple Binary Ninja Servers: |
| 21 | + - Binary A → port 9009 |
| 22 | + - Binary B → port 9010 |
| 23 | + - Binary C → port 9011 |
| 24 | + - etc. |
| 25 | +``` |
| 26 | + |
| 27 | +## Setup Instructions |
| 28 | + |
| 29 | +### 1. Install the Enhanced Plugin |
| 30 | + |
| 31 | +The plugin now supports both legacy single-binary mode and new multi-binary mode. |
| 32 | + |
| 33 | +### 2. Load Multiple Binaries in Binary Ninja |
| 34 | + |
| 35 | +1. Open Binary Ninja |
| 36 | +2. Load your first binary |
| 37 | +3. Use `MCP Server > Start Server for This Binary` |
| 38 | +4. Open a new Binary Ninja window (or tab) |
| 39 | +5. Load your second binary |
| 40 | +6. Use `MCP Server > Start Server for This Binary` |
| 41 | +7. Repeat for additional binaries |
| 42 | + |
| 43 | +Each binary will get its own MCP server on a unique port (9009, 9010, 9011, etc.). |
| 44 | + |
| 45 | +### 3. Start the Multi-Binary Bridge |
| 46 | + |
| 47 | +Use the new multi-binary bridge instead of the original: |
| 48 | + |
| 49 | +```bash |
| 50 | +python bridge/bn_mcp_bridge_multi_http.py |
| 51 | +``` |
| 52 | + |
| 53 | +This bridge will: |
| 54 | +- Automatically discover all running Binary Ninja MCP servers |
| 55 | +- Provide routing to the correct server based on binary selection |
| 56 | +- Expose enhanced tools for binary management |
| 57 | + |
| 58 | +### 4. Configure Your MCP Client |
| 59 | + |
| 60 | +Update your MCP client configuration to use the multi-binary bridge: |
| 61 | + |
| 62 | +```json |
| 63 | +{ |
| 64 | + "mcpServers": { |
| 65 | + "binary_ninja_multi_mcp": { |
| 66 | + "command": "/path/to/venv/bin/python", |
| 67 | + "args": [ |
| 68 | + "/path/to/binary_ninja_mcp/bridge/bn_mcp_bridge_multi_http.py" |
| 69 | + ] |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +## Usage |
| 76 | + |
| 77 | +### Binary Selection |
| 78 | + |
| 79 | +The multi-binary bridge provides several ways to select which binary to work with: |
| 80 | + |
| 81 | +#### 1. List Available Binaries |
| 82 | + |
| 83 | +```python |
| 84 | +# List all available Binary Ninja servers |
| 85 | +list_binary_servers() |
| 86 | +``` |
| 87 | + |
| 88 | +This returns information about all running servers, including: |
| 89 | +- `binary_id`: Unique identifier for the server |
| 90 | +- `filename`: Name of the loaded binary |
| 91 | +- `port`: Server port number |
| 92 | +- Binary metadata (architecture, platform, etc.) |
| 93 | + |
| 94 | +#### 2. Select Binary by Filename |
| 95 | + |
| 96 | +```python |
| 97 | +# Find a binary by filename (supports partial matches) |
| 98 | +select_binary_by_filename("malware.exe") |
| 99 | +``` |
| 100 | + |
| 101 | +#### 3. Use Binary ID in Tools |
| 102 | + |
| 103 | +All MCP tools now accept an optional `binary_id` parameter: |
| 104 | + |
| 105 | +```python |
| 106 | +# List methods from a specific binary |
| 107 | +list_entities(kind="methods", binary_id="port_9009") |
| 108 | + |
| 109 | +# Decompile function from a specific binary |
| 110 | +decompile_function("main", binary_id="port_9010") |
| 111 | + |
| 112 | +# Get data from a specific binary |
| 113 | +list_data(binary_id="port_9011") |
| 114 | +``` |
| 115 | + |
| 116 | +If no `binary_id` is provided, the bridge uses the first available server as default. |
| 117 | + |
| 118 | +### Plugin Commands |
| 119 | + |
| 120 | +The plugin provides several new commands for multi-binary management: |
| 121 | + |
| 122 | +#### Main Operations |
| 123 | +- `MCP Server > Start Server for This Binary` - Start server for current binary |
| 124 | +- `MCP Server > Stop Server for This Binary` - Stop server for current binary |
| 125 | +- `MCP Server > Restart Server for This Binary` - Restart server for current binary |
| 126 | + |
| 127 | +#### Management |
| 128 | +- `MCP Server > Show Server Status` - Detailed status and connection info |
| 129 | +- `MCP Server > List Active Servers` - Quick list of running servers |
| 130 | +- `MCP Server > Stop All Servers` - Stop all MCP servers |
| 131 | + |
| 132 | +#### Legacy (Backward Compatibility) |
| 133 | +- `MCP Server > Legacy > Start MCP Server` - Original single-binary mode |
| 134 | +- `MCP Server > Legacy > Stop MCP Server` - Stop legacy server |
| 135 | + |
| 136 | +## Testing |
| 137 | + |
| 138 | +Run the test script to verify your multi-binary setup: |
| 139 | + |
| 140 | +```bash |
| 141 | +python test_multi_binary.py |
| 142 | +``` |
| 143 | + |
| 144 | +This will: |
| 145 | +- Check bridge connectivity |
| 146 | +- Discover available Binary Ninja servers |
| 147 | +- Test binary selection functionality |
| 148 | +- Verify routing works correctly |
| 149 | + |
| 150 | +## Troubleshooting |
| 151 | + |
| 152 | +### No Servers Found |
| 153 | + |
| 154 | +If the bridge can't find any Binary Ninja servers: |
| 155 | + |
| 156 | +1. Make sure Binary Ninja is running |
| 157 | +2. Load at least one binary |
| 158 | +3. Use `MCP Server > Start Server for This Binary` |
| 159 | +4. Check that the server is accessible: `curl http://localhost:9009/status` |
| 160 | + |
| 161 | +### Port Conflicts |
| 162 | + |
| 163 | +If you get port conflicts: |
| 164 | + |
| 165 | +1. Check what's running on ports 9009+: `netstat -an | grep 900` |
| 166 | +2. Stop conflicting services |
| 167 | +3. Restart Binary Ninja MCP servers |
| 168 | + |
| 169 | +### Bridge Connection Issues |
| 170 | + |
| 171 | +If the MCP client can't connect to the bridge: |
| 172 | + |
| 173 | +1. Verify the bridge is running: `curl http://localhost:8010/health` |
| 174 | +2. Check firewall settings |
| 175 | +3. Ensure the bridge discovered servers: check startup logs |
| 176 | + |
| 177 | +### Binary Selection Not Working |
| 178 | + |
| 179 | +If binary selection isn't working: |
| 180 | + |
| 181 | +1. Use `list_binary_servers()` to see available binaries |
| 182 | +2. Check that `binary_id` values are correct |
| 183 | +3. Verify the target server is still running |
| 184 | + |
| 185 | +## Advanced Configuration |
| 186 | + |
| 187 | +### Custom Port Ranges |
| 188 | + |
| 189 | +You can modify the port range in `plugin/core/config.py`: |
| 190 | + |
| 191 | +```python |
| 192 | +@dataclass |
| 193 | +class MultiBinaryServerConfig: |
| 194 | + host: str = "localhost" |
| 195 | + base_port: int = 9009 # Starting port |
| 196 | + max_servers: int = 10 # Maximum number of servers |
| 197 | +``` |
| 198 | + |
| 199 | +### Bridge Discovery Settings |
| 200 | + |
| 201 | +Modify discovery settings in `bridge/bn_mcp_bridge_multi_http.py`: |
| 202 | + |
| 203 | +```python |
| 204 | +BINJA_BASE_PORT = 9009 # Starting port to scan |
| 205 | +MAX_SERVERS = 10 # Maximum servers to discover |
| 206 | +discovery_interval = 30.0 # How often to rediscover (seconds) |
| 207 | +``` |
| 208 | + |
| 209 | +## Migration from Single-Binary |
| 210 | + |
| 211 | +If you're upgrading from the single-binary setup: |
| 212 | + |
| 213 | +1. The original bridge (`bn_mcp_bridge_http.py`) still works for single-binary use |
| 214 | +2. Use the new bridge (`bn_mcp_bridge_multi_http.py`) for multi-binary support |
| 215 | +3. Legacy plugin commands are still available under `MCP Server > Legacy` |
| 216 | +4. Your existing MCP client configuration will work with minor updates |
| 217 | + |
| 218 | +## Examples |
| 219 | + |
| 220 | +### Analyzing Multiple Malware Samples |
| 221 | + |
| 222 | +```python |
| 223 | +# List all loaded binaries |
| 224 | +servers = list_binary_servers() |
| 225 | + |
| 226 | +# Analyze each binary |
| 227 | +for server in servers['servers']: |
| 228 | + binary_id = server['binary_id'] |
| 229 | + filename = server['filename'] |
| 230 | + |
| 231 | + print(f"Analyzing {filename}...") |
| 232 | + |
| 233 | + # Get overview |
| 234 | + overview(binary_id=binary_id) |
| 235 | + |
| 236 | + # List functions |
| 237 | + functions = list_entities(kind="methods", binary_id=binary_id, limit=10) |
| 238 | + |
| 239 | + # Decompile main function if it exists |
| 240 | + decompile_function("main", binary_id=binary_id) |
| 241 | +``` |
| 242 | + |
| 243 | +### Comparing Binaries |
| 244 | + |
| 245 | +```python |
| 246 | +# Get function lists from two binaries |
| 247 | +binary1_functions = list_entities(kind="methods", binary_id="port_9009") |
| 248 | +binary2_functions = list_entities(kind="methods", binary_id="port_9010") |
| 249 | + |
| 250 | +# Compare function names, signatures, etc. |
| 251 | +``` |
| 252 | + |
| 253 | +This multi-binary setup enables powerful comparative analysis workflows that weren't possible with the single-binary approach. |
0 commit comments