Merge remote-tracking branch 'origin/main'
# Conflicts: # .gitignore # README.md
This commit is contained in:
commit
3365a7bf98
4 changed files with 176 additions and 69 deletions
164
.gitignore
vendored
164
.gitignore
vendored
|
|
@ -1,2 +1,164 @@
|
||||||
|
# ---> Python
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
||||||
|
.pdm.toml
|
||||||
|
.pdm-python
|
||||||
|
.pdm-build/
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
|
|
||||||
|
|
|
||||||
9
LICENSE
Normal file
9
LICENSE
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 wisedev
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
@ -124,4 +124,4 @@ says what actually broke rather than a generic failure.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
No license file yet -- add one if you're planning to publish this more widely.
|
MIT, see [LICENSE](LICENSE).
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,3 @@
|
||||||
"""
|
|
||||||
IDA MCP Server -- a dynamic instance registry instead of hardcoded "IDA A / IDA B".
|
|
||||||
|
|
||||||
How it works:
|
|
||||||
Each ida_mcp_plugin.py instance finds a free port on its own and sends a
|
|
||||||
heartbeat here every 10s (POST /instances/register). Open a third, a tenth
|
|
||||||
IDA -- it just shows up in the registry, no manual ports/SSH. Instances that
|
|
||||||
stop sending heartbeats for longer than INSTANCE_TTL seconds are dropped.
|
|
||||||
|
|
||||||
Tools take an optional "instance" argument:
|
|
||||||
- omitted, exactly one IDA open -> that one is used
|
|
||||||
- omitted, several open -> the most recently active one is used,
|
|
||||||
and the response says so explicitly
|
|
||||||
- given -> that specific instance is used
|
|
||||||
See what's currently open with the ida_list_instances tool.
|
|
||||||
|
|
||||||
Run: python ida-mcp-server.py
|
|
||||||
Requires: pip install httpx starlette uvicorn
|
|
||||||
|
|
||||||
Security: if IDA_MCP_TOKEN is set (same value here and in the plugin's
|
|
||||||
environment):
|
|
||||||
- MCP tool calls (/sse) require Authorization: Bearer <token>
|
|
||||||
- instance registration (/instances/register|unregister) requires the same token
|
|
||||||
Without a token the server is fully open to anyone who can reach the port --
|
|
||||||
fine for localhost-only use, but do NOT expose this over ngrok/the internet
|
|
||||||
without one: anyone who gets the URL gets full control over your open IDA
|
|
||||||
instances (decompiling, renaming, reading code).
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import secrets
|
import secrets
|
||||||
|
|
@ -43,14 +14,11 @@ NGROK_URL = os.environ.get("NGROK_URL", "")
|
||||||
AUTH_TOKEN = os.environ.get("IDA_MCP_TOKEN")
|
AUTH_TOKEN = os.environ.get("IDA_MCP_TOKEN")
|
||||||
INSTANCE_TTL = int(os.environ.get("IDA_MCP_INSTANCE_TTL", 30))
|
INSTANCE_TTL = int(os.environ.get("IDA_MCP_INSTANCE_TTL", 30))
|
||||||
|
|
||||||
http = httpx.AsyncClient(timeout=120.0) # decompiling large functions can be slow
|
http = httpx.AsyncClient(timeout=120.0)
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Instance registry
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
INSTANCES = {} # id -> {host, port, file, pid, last_seen}
|
INSTANCES = {}
|
||||||
AUTH_CODES = {} # one-time OAuth codes -> expiry timestamp, issued only after the token page is filled correctly
|
AUTH_CODES = {}
|
||||||
AUTH_CODE_TTL = 120
|
AUTH_CODE_TTL = 120
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,9 +34,6 @@ def _check_token(request: Request) -> bool:
|
||||||
|
|
||||||
|
|
||||||
class ApiError(Exception):
|
class ApiError(Exception):
|
||||||
"""Exception with a machine-readable .code, so callers can branch on it
|
|
||||||
instead of parsing the error text."""
|
|
||||||
|
|
||||||
def __init__(self, message: str, code: str = "error"):
|
def __init__(self, message: str, code: str = "error"):
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
self.code = code
|
self.code = code
|
||||||
|
|
@ -79,10 +44,6 @@ class ResolveError(ApiError):
|
||||||
|
|
||||||
|
|
||||||
def resolve_instance(instance_id):
|
def resolve_instance(instance_id):
|
||||||
"""Returns (host, port, id, auto_picked). auto_picked=True means instance
|
|
||||||
wasn't passed explicitly and was chosen automatically (the most recently
|
|
||||||
active one) -- the caller should surface this in the response so the
|
|
||||||
choice stays visible instead of silent."""
|
|
||||||
live = _live_instances()
|
live = _live_instances()
|
||||||
if instance_id:
|
if instance_id:
|
||||||
if instance_id not in live:
|
if instance_id not in live:
|
||||||
|
|
@ -103,15 +64,10 @@ def resolve_instance(instance_id):
|
||||||
if len(live) == 1:
|
if len(live) == 1:
|
||||||
(only_id, v), = live.items()
|
(only_id, v), = live.items()
|
||||||
return v["host"], v["port"], only_id, False
|
return v["host"], v["port"], only_id, False
|
||||||
# several instances, none specified: use the most recently active one,
|
|
||||||
# but always report which one was picked instead of guessing silently
|
|
||||||
chosen_id, chosen = max(live.items(), key=lambda kv: kv[1]["last_seen"])
|
chosen_id, chosen = max(live.items(), key=lambda kv: kv[1]["last_seen"])
|
||||||
return chosen["host"], chosen["port"], chosen_id, True
|
return chosen["host"], chosen["port"], chosen_id, True
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# IDA helpers
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
|
|
||||||
def _base(host, port):
|
def _base(host, port):
|
||||||
|
|
@ -143,9 +99,6 @@ async def ida_post(host, port, path, data):
|
||||||
return _unwrap(r)
|
return _unwrap(r)
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Tools
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
_INSTANCE_PARAM = {
|
_INSTANCE_PARAM = {
|
||||||
"instance": {
|
"instance": {
|
||||||
|
|
@ -485,9 +438,6 @@ TOOLS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Tool execution
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
|
|
||||||
async def execute_tool(name: str, arguments: dict):
|
async def execute_tool(name: str, arguments: dict):
|
||||||
|
|
@ -648,9 +598,6 @@ async def _dispatch(name: str, arguments: dict, host, port):
|
||||||
return {"error": f"Unknown tool: {name}", "code": "unknown_tool"}
|
return {"error": f"Unknown tool: {name}", "code": "unknown_tool"}
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Instance registry endpoints (called by the plugin)
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
|
|
||||||
async def handle_register_instance(request: Request):
|
async def handle_register_instance(request: Request):
|
||||||
|
|
@ -695,9 +642,6 @@ async def handle_list_instances(request: Request):
|
||||||
return JSONResponse({"count": len(live), "instances": [{"id": k, **v} for k, v in live.items()]})
|
return JSONResponse({"count": len(live), "instances": [{"id": k, **v} for k, v in live.items()]})
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# MCP JSON-RPC
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
|
|
||||||
def make_response(req_id, result):
|
def make_response(req_id, result):
|
||||||
|
|
@ -742,9 +686,6 @@ async def handle_jsonrpc(msg: dict):
|
||||||
return make_error(req_id, -32601, f"Method not found: {method}")
|
return make_error(req_id, -32601, f"Method not found: {method}")
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# HTTP handlers
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
|
|
||||||
async def handle_mcp_post(request: Request):
|
async def handle_mcp_post(request: Request):
|
||||||
|
|
@ -799,7 +740,6 @@ async def handle_oauth_authorization_server(request: Request):
|
||||||
"authorization_endpoint": f"{NGROK_URL}/authorize",
|
"authorization_endpoint": f"{NGROK_URL}/authorize",
|
||||||
"token_endpoint": f"{NGROK_URL}/token",
|
"token_endpoint": f"{NGROK_URL}/token",
|
||||||
"registration_endpoint": f"{NGROK_URL}/register",
|
"registration_endpoint": f"{NGROK_URL}/register",
|
||||||
# client_credentials would let a script skip the /authorize prompt entirely — not offered.
|
|
||||||
"grant_types_supported": ["authorization_code"],
|
"grant_types_supported": ["authorization_code"],
|
||||||
"response_types_supported": ["code"],
|
"response_types_supported": ["code"],
|
||||||
"code_challenge_methods_supported": ["S256", "plain"],
|
"code_challenge_methods_supported": ["S256", "plain"],
|
||||||
|
|
@ -846,7 +786,6 @@ async def handle_authorize(request: Request):
|
||||||
return JSONResponse({"error": "missing redirect_uri"}, status_code=400)
|
return JSONResponse({"error": "missing redirect_uri"}, status_code=400)
|
||||||
|
|
||||||
if not AUTH_TOKEN:
|
if not AUTH_TOKEN:
|
||||||
# No secret configured — behave as before (fine for trusted localhost-only use).
|
|
||||||
return _redirect_with_code(redirect_uri, state)
|
return _redirect_with_code(redirect_uri, state)
|
||||||
|
|
||||||
submitted = params.get("token")
|
submitted = params.get("token")
|
||||||
|
|
@ -903,9 +842,6 @@ async def handle_token(request: Request):
|
||||||
return JSONResponse({"access_token": AUTH_TOKEN, "token_type": "bearer", "expires_in": 86400})
|
return JSONResponse({"access_token": AUTH_TOKEN, "token_type": "bearer", "expires_in": 86400})
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# App
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue