Skip to main content
Glama
RuoJi6

Memory Shell Detector MCP

by RuoJi6

download_detector_tools

Downloads the required Java agent and CLI jar files to initiate memory shell detection and scanning. Supports local and remote SSH deployment.

Instructions

下载 Java 内存马检测工具包(detector-agent.jar 和 detector-cli.jar)

此工具会下载两个核心 jar 包:

  • detector-agent-1.0.0-SNAPSHOT.jar: Java Agent,用于注入目标 JVM 进程

  • memory-shell-detector-cli.jar: 命令行工具,提供扫描、反编译、移除等功能

这是使用内存马检测功能的前置步骤,下载完成后才能执行后续的扫描和分析操作。

Args: tools_dir: 工具存放目录,不指定则从环境变量 TOOLS_DIR 读取,都没有则使用系统临时目录 use_ssh: 是否在远程服务器上下载 ssh_host: SSH 主机地址(不指定则从环境变量 SSH_HOST 读取) ssh_username: SSH 用户名(不指定则从环境变量 SSH_USERNAME 读取) ssh_password: SSH 密码(不指定则从环境变量 SSH_PASSWORD 读取) ssh_key_path: SSH 私钥路径(不指定则从环境变量 SSH_KEY_PATH 读取) ssh_port: SSH 端口(不指定则从环境变量 SSH_PORT 读取)

Returns: 下载结果,包含工具目录路径和 jar 文件名

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tools_dirNo
use_sshNo
ssh_hostNo
ssh_usernameNo
ssh_passwordNo
ssh_key_pathNo
ssh_portNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'download_detector_tools' MCP tool. Decorated with @mcp.tool(), it downloads Java memory shell detector jar files (detector-agent-1.0.0-SNAPSHOT.jar and memory-shell-detector-cli.jar). Supports both local and SSH modes, checks if tools already exist, validates network availability, and downloads from predefined URLs.
    @mcp.tool()
    def download_detector_tools(
        tools_dir: Optional[str] = None,
        use_ssh: bool = False,
        ssh_host: Optional[str] = None,
        ssh_username: Optional[str] = None,
        ssh_password: Optional[str] = None,
        ssh_key_path: Optional[str] = None,
        ssh_port: int = 22
    ) -> dict:
        """
        下载 Java 内存马检测工具包(detector-agent.jar 和 detector-cli.jar)
        
        此工具会下载两个核心 jar 包:
        - detector-agent-1.0.0-SNAPSHOT.jar: Java Agent,用于注入目标 JVM 进程
        - memory-shell-detector-cli.jar: 命令行工具,提供扫描、反编译、移除等功能
        
        这是使用内存马检测功能的前置步骤,下载完成后才能执行后续的扫描和分析操作。
        
        Args:
            tools_dir: 工具存放目录,不指定则从环境变量 TOOLS_DIR 读取,都没有则使用系统临时目录
            use_ssh: 是否在远程服务器上下载
            ssh_host: SSH 主机地址(不指定则从环境变量 SSH_HOST 读取)
            ssh_username: SSH 用户名(不指定则从环境变量 SSH_USERNAME 读取)
            ssh_password: SSH 密码(不指定则从环境变量 SSH_PASSWORD 读取)
            ssh_key_path: SSH 私钥路径(不指定则从环境变量 SSH_KEY_PATH 读取)
            ssh_port: SSH 端口(不指定则从环境变量 SSH_PORT 读取)
        
        Returns:
            下载结果,包含工具目录路径和 jar 文件名
        """
        if use_ssh:
            ssh_host, ssh_username, ssh_password, ssh_key_path, ssh_port = resolve_ssh_params(
                ssh_host, ssh_username, ssh_password, ssh_key_path, ssh_port
            )
            if not ssh_host or not ssh_username:
                return {"success": False, "message": "SSH模式需要提供ssh_host和ssh_username,或设置SSH_HOST和SSH_USERNAME环境变量", "tools_dir": None}
        
        if tools_dir:
            target_dir = tools_dir
        elif os.environ.get("TOOLS_DIR"):
            target_dir = os.environ.get("TOOLS_DIR")
        else:
            if use_ssh:
                target_dir = "/tmp/memory-shell-detector"
            else:
                target_dir = os.path.join(get_temp_dir(), "memory-shell-detector")
        
        agent_jar_name = "detector-agent-1.0.0-SNAPSHOT.jar"
        cli_jar_name = "memory-shell-detector-cli.jar"
        
        if not use_ssh:
            agent_path = os.path.join(target_dir, agent_jar_name)
            cli_path = os.path.join(target_dir, cli_jar_name)
            
            if os.path.exists(agent_path) and os.path.exists(cli_path):
                return {
                    "success": True,
                    "message": "工具已存在,无需下载",
                    "tools_dir": target_dir,
                    "agent_jar": agent_jar_name,
                    "cli_jar": cli_jar_name
                }
        else:
            check_cmd = f'test -f "{target_dir}/{agent_jar_name}" && test -f "{target_dir}/{cli_jar_name}" && echo "exists"'
            result = execute_ssh_command(
                host=ssh_host,
                username=ssh_username,
                command=check_cmd,
                password=ssh_password,
                key_path=ssh_key_path,
                port=ssh_port
            )
            if "exists" in result["stdout"]:
                return {
                    "success": True,
                    "message": "工具已存在,无需下载",
                    "tools_dir": target_dir,
                    "agent_jar": agent_jar_name,
                    "cli_jar": cli_jar_name
                }
        
        if not use_ssh:
            network_check = check_network_available()
            if not network_check["available"]:
                return {
                    "success": False,
                    "message": f"网络检测失败: {network_check['message']}",
                    "tools_dir": None
                }
        
        if use_ssh:
            mkdir_cmd = f"mkdir -p {target_dir}"
            agent_path = f"{target_dir}/detector-agent-1.0.0-SNAPSHOT.jar"
            cli_path = f"{target_dir}/memory-shell-detector-cli.jar"
            
            download_agent_cmd = f'curl -L -o "{agent_path}" "{DETECTOR_AGENT_URL}" || wget -O "{agent_path}" "{DETECTOR_AGENT_URL}"'
            download_cli_cmd = f'curl -L -o "{cli_path}" "{DETECTOR_CLI_URL}" || wget -O "{cli_path}" "{DETECTOR_CLI_URL}"'
            
            result = execute_ssh_command(host=ssh_host, username=ssh_username, command=mkdir_cmd, password=ssh_password, key_path=ssh_key_path, port=ssh_port)
            if not result["success"]:
                return {"success": False, "message": f"创建目录失败: {result['stderr']}", "tools_dir": None}
            
            result = execute_ssh_command(host=ssh_host, username=ssh_username, command=download_agent_cmd, password=ssh_password, key_path=ssh_key_path, port=ssh_port, timeout=120)
            if not result["success"]:
                return {"success": False, "message": f"下载detector-agent失败: {result['stderr']}", "tools_dir": None}
            
            result = execute_ssh_command(host=ssh_host, username=ssh_username, command=download_cli_cmd, password=ssh_password, key_path=ssh_key_path, port=ssh_port, timeout=120)
            if not result["success"]:
                return {"success": False, "message": f"下载detector-cli失败: {result['stderr']}", "tools_dir": None}
        else:
            os.makedirs(target_dir, exist_ok=True)
            
            agent_path = os.path.join(target_dir, "detector-agent-1.0.0-SNAPSHOT.jar")
            cli_path = os.path.join(target_dir, "memory-shell-detector-cli.jar")
            
            download_cmd = get_download_command(DETECTOR_AGENT_URL, agent_path)
            result = execute_local_command(download_cmd, timeout=120)
            if not result["success"] and not os.path.exists(agent_path):
                return {"success": False, "message": f"下载detector-agent失败: {result['stderr']}", "tools_dir": None}
            
            download_cmd = get_download_command(DETECTOR_CLI_URL, cli_path)
            result = execute_local_command(download_cmd, timeout=120)
            if not result["success"] and not os.path.exists(cli_path):
                return {"success": False, "message": f"下载detector-cli失败: {result['stderr']}", "tools_dir": None}
        
        return {
            "success": True,
            "message": "工具下载完成",
            "tools_dir": target_dir,
            "agent_jar": "detector-agent-1.0.0-SNAPSHOT.jar",
            "cli_jar": "memory-shell-detector-cli.jar"
        }
  • Function signature / input schema for download_detector_tools. Parameters: tools_dir (optional), use_ssh (bool), ssh_host, ssh_username, ssh_password, ssh_key_path, ssh_port. Returns a dict with success, message, tools_dir, agent_jar, cli_jar.
    def download_detector_tools(
        tools_dir: Optional[str] = None,
        use_ssh: bool = False,
        ssh_host: Optional[str] = None,
        ssh_username: Optional[str] = None,
        ssh_password: Optional[str] = None,
        ssh_key_path: Optional[str] = None,
        ssh_port: int = 22
    ) -> dict:
  • The '@mcp.tool()' decorator registers download_detector_tools as an MCP tool on the FastMCP instance named 'memory-shell-detector'.
    @mcp.tool()
  • Helper function get_download_command() used by download_detector_tools to construct the OS-appropriate download command (curl/wget for Unix, curl/powershell for Windows).
    def get_download_command(url: str, output_path: str) -> str:
        """根据系统获取下载命令"""
        system = platform.system().lower()
        
        if system == "windows":
            return f'curl -L -o "{output_path}" "{url}" || powershell -Command "Invoke-WebRequest -Uri \'{url}\' -OutFile \'{output_path}\'"'
        else:
            return f'curl -L -o "{output_path}" "{url}" || wget -O "{output_path}" "{url}"'
  • Helper function check_network_available() used by download_detector_tools to verify network connectivity before attempting downloads.
    def check_network_available(test_url: str = "https://xget.xi-xu.me") -> dict:
        """检测网络是否可用"""
        system = platform.system().lower()
        
        if system == "windows":
            cmd = f'curl -s -o nul -w "%{{http_code}}" --connect-timeout 10 "{test_url}" || powershell -Command "(Invoke-WebRequest -Uri \'{test_url}\' -TimeoutSec 10 -UseBasicParsing).StatusCode"'
        else:
            cmd = f'curl -s -o /dev/null -w "%{{http_code}}" --connect-timeout 10 "{test_url}" 2>/dev/null || wget -q --spider --timeout=10 "{test_url}" && echo "200"'
        
        result = execute_local_command(cmd, timeout=30)
        
        if result["success"] or "200" in result["stdout"]:
            return {"available": True, "message": "网络连接正常"}
        else:
            return {"available": False, "message": f"网络连接失败: {result['stderr']}"}
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It explains what is downloaded and the basic behavior, but lacks details on side effects like file overwriting, disk space needs, or error handling. The description is adequate but not rich on behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear purpose up front, followed by parameter details and return value. It is efficient with no wasted sentences.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (7 optional parameters) and absence of annotations, the description is quite complete, explaining parameters and return. However, it lacks details on error conditions or failure handling, and the output schema is not described, but since output schema exists, this is a minor gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Parameter descriptions in the Args section cover all 7 parameters, adding meaning beyond the schema, which has 0% description coverage. Each parameter explains its purpose and fallback to environment variables, providing clear guidance.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool downloads two specific jar files for Java memory shell detection. It uses specific verbs ('下载') and resource names ('detector-agent.jar', 'detector-cli.jar'), and distinguishes itself from sibling tools like scan_process and remove_memory_shell by being a prerequisite step.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states it is a prerequisite step before scanning and analysis, providing clear context for when to use the tool. However, it does not mention when not to use it or suggest alternatives, which slightly reduces the score.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/RuoJi6/memory-shell-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server