Memory Shell Detector MCP
Provides tools for scanning, detecting, and removing Java memory shells on Linux systems, including process management, system information retrieval, and remote command execution via SSH.
Provides tools for scanning, detecting, and removing Java memory shells on macOS systems, including process management, system information retrieval, and remote command execution via SSH.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Memory Shell Detector MCP scan Java process 1234 for suspicious memory shells"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Memory Shell Detector MCP
基于 FastMCP 构建的 Java 内存马检测和清理工具 MCP 服务器,支持本地执行和 SSH 远程执行。
项目地址:https://github.com/RuoJi6/memory-shell-mcp
功能
功能 | 工具名称 | 对应命令 |
执行命令(本地/SSH) |
| - |
下载检测工具 |
| - |
列出Java进程 |
|
|
扫描指定进程 |
|
|
查看可疑类代码 |
|
|
移除内存马 |
|
|
导出检测报告 |
|
|
获取系统信息 |
| - |
检测网络状态 |
| - |
Related MCP server: jdwp-mcp
安全特性
移除内存马前会先获取源代码供 AI 分析确认
需要 AI 确认后(
ai_confirmed=True)才会执行移除操作自动处理移除确认提示
环境要求
Python 3.10+
JDK 1.8+(目标机器)
uv(Python 包管理器)
快速开始(uvx 方式)
发布到 PyPI 后,直接使用 uvx 运行,无需安装:
uvx memory-shell-mcpMCP 配置(uvx 方式)
支持 MCP 的客户端:本工具可配置到任何支持 Model Context Protocol 的 AI 客户端,包括但不限于:
AI 助手:Claude Desktop、Claude Code
以下是常用客户端的配置示例:
Kiro
在 .kiro/settings/mcp.json 中添加:
{
"mcpServers": {
"memory-shell-detector": {
"command": "uvx",
"args": ["memory-shell-mcp"],
"env": {},
"disabled": false,
"autoApprove": []
}
}
}Claude Desktop
在 claude_desktop_config.json 中添加:
{
"mcpServers": {
"memory-shell-detector": {
"command": "uvx",
"args": ["memory-shell-mcp"],
"env": {}
}
}
}说明:
env中的环境变量均为可选配置。不配置时,工具会下载到系统临时目录,SSH 参数可通过 AI 对话传入。
开发者模式(本地源码)
安装
git clone https://github.com/RuoJi6/memory-shell-mcp.git
cd memory-shell-mcp
# 创建虚拟环境并安装依赖
uv venv --python python3.12
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows
uv pip install -e .运行
# 激活虚拟环境后
memory-shell-mcpMCP 配置(开发者模式)
{
"mcpServers": {
"memory-shell-detector": {
"command": "uv",
"args": [
"run",
"--directory",
"/path/to/memory-shell-mcp",
"memory-shell-mcp"
],
"env": {}
}
}
}说明:
env中的环境变量均为可选配置。不配置时,工具会下载到系统临时目录,SSH 参数可通过 AI 对话传入。
环境变量说明(可选)
变量 | 说明 |
| 检测工具(JAR 文件)存放目录,不设置则下载到系统临时目录 |
| SSH 主机地址 |
| SSH 用户名 |
| SSH 密码 |
| SSH 私钥路径(与密码二选一) |
| SSH 端口(默认 22) |
| JDK 路径(可选) |
所有环境变量均为可选,不配置也可正常使用
设置环境变量后,调用工具时无需每次传入对应参数
如果
TOOLS_DIR目录中已存在工具文件,download_detector_tools会跳过下载SSH 参数也可以通过 AI 对话动态传入,优先级高于环境变量
使用流程
完整检测流程
第一步:准备工作
1. 调用 download_detector_tools 下载检测工具
2. 调用 list_java_processes 列出所有 Java 进程,找到目标进程 PID第二步:扫描检测
3. 调用 scan_process(pid=目标PID) 扫描目标进程
4. 扫描结果会列出所有可疑类,记录完整类名第三步:源码分析(关键步骤)
5. 对每个可疑类调用 view_class_code(class_name="类名", pid=PID) 反编译查看源码
6. 分析源码判断是否为内存马内存马判断标准:
✅ 是否包含命令执行代码(
Runtime.exec、ProcessBuilder)✅ 是否包含反射调用敏感方法
✅ 是否有异常的网络连接或文件操作
✅ 是否动态注册 Filter/Servlet/Listener
✅ 是否有加密/编码的可疑字符串(Base64、AES 等)
✅ 是否有 Webshell 特征(参数名为 cmd/command/exec 等)
✅ 类名是否异常(随机字符串、与业务无关)
✅ 是否有类加载器操作(defineClass、ClassLoader)
第四步:清除内存马
7. 确认是内存马后,调用 remove_memory_shell(class_name="类名", pid=PID, ai_confirmed=True)
8. 移除后立即再次调用 scan_process 验证是否清除成功
9. 重要:某些内存马需要多次移除才能彻底清除,如果仍然存在,重复步骤 7-8第五步:生成报告(可选)
10. 调用 export_report 导出检测报告存档示例提示词
直接复制以下提示词发送给 AI 即可开始检测:
本地检测
帮我检测本机的 Java Web 服务,排查是否存在内存马。
检测要求:
1. 先下载检测工具,然后列出 Java 进程找到目标 PID
2. 扫描该进程,获取所有可疑类列表
3. 对每个可疑类反编译源代码,分析是否为内存马
4. 如果确认是内存马,执行移除操作
5. 移除后再次扫描验证,某些内存马需要多次移除才能彻底清除
6. 最后给我一个检测报告总结SSH 远程检测
帮我检测远程服务器上的 Java 服务是否存在内存马。
服务器信息:
- IP: 192.168.1.100
- 用户名: root
- 密码: your_password
检测要求:
1. 通过 SSH 连接到服务器
2. 下载检测工具到 /tmp 目录
3. 列出所有 Java 进程,扫描可疑进程
4. 反编译分析每个可疑类的源代码
5. 确认是内存马后执行移除,并验证移除结果
6. 生成检测报告内存马类型说明
类型 | 特征 | 移除难度 |
Filter 型 | 实现 | 中等,可能需要多次移除 |
Servlet 型 | 继承 | 中等 |
Listener 型 | 实现 | 较易 |
Spring Controller | 使用 | 中等 |
Spring Interceptor | 实现 | 中等 |
Agent 型 | 通过 | 困难,可能需要重启 |
Valve 型 (Tomcat) | 继承 | 中等 |
旧版使用流程(简化版)
1. 下载检测工具
调用 download_detector_tools2. 列出 Java 进程
调用 list_java_processes()3. 扫描可疑进程
调用 scan_process(pid=进程ID)4. 查看可疑类源代码
调用 view_class_code(class_name="类名", pid=进程ID)5. 移除内存马
# AI 确认后调用
调用 remove_memory_shell(class_name="类名", pid=进程ID, ai_confirmed=True)SSH 远程执行
方式1:环境变量预设
在 MCP 配置的 env 中设置:
"env": {
"TOOLS_DIR": "/your/tools/directory",
"SSH_HOST": "192.168.1.100",
"SSH_USERNAME": "root",
"SSH_PASSWORD": "password"
}调用时只需设置 use_ssh=True:
调用 scan_process(pid=12345, use_ssh=True)方式2:AI 对话动态传入
直接告诉 AI SSH 连接信息:
调用 scan_process(
pid=12345,
use_ssh=True,
ssh_host="192.168.1.100",
ssh_username="root",
ssh_password="password"
)对话传入的参数优先级高于环境变量
工具下载地址
工具会自动从以下地址下载:
Agent JAR:
https://xget.xi-xu.me/gh/RuoJi6/memory-shell-mcp/releases/download/1/detector-agent-1.0.0-SNAPSHOT.jarCLI JAR:
https://xget.xi-xu.me/gh/RuoJi6/memory-shell-mcp/releases/download/1/memory-shell-detector-cli.jar
支持系统
Windows / Linux / macOS
风险等级说明
等级 | 说明 |
CRITICAL | 确认为内存马,需立即处理 |
HIGH | 高度可疑,建议人工确认 |
MEDIUM | 中等风险,可能是正常组件 |
LOW | 低风险,基本可排除 |
SAFE | 安全,已在白名单中 |
注意事项
扫描其他进程需要足够的系统权限
目标进程和检测工具需使用相同或兼容的 JDK 版本
Agent JAR 需要和 CLI JAR 放在同一目录下
Agent 型内存马无法通过本工具移除,需要重启应用
移除内存马可能影响应用正常运行,建议先备份
发布到 PyPI
# 1. 注册 PyPI 账号并获取 API Token
# https://pypi.org/manage/account/token/
# 2. 构建包
uv build
# 3. 发布到 PyPI
uv publish --token YOUR_PYPI_TOKEN
# 4. 发布后即可通过 uvx 运行
uvx memory-shell-mcp参考项目
memory-shell-detector - Java 内存马检测工具核心实现
Xget - GitHub 文件加速下载服务
License
MIT License
Available Tools
9 toolscheck_networkA
检测网络连通性
测试是否能访问工具下载服务器,用于在下载检测工具前确认网络状态。 如果网络不通,需要手动下载 jar 包或检查网络配置。
Returns: available: 网络是否可用 message: 状态描述信息
Inputs: no named parameters. Returns: object
download_detector_toolsA
下载 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 文件名
Inputs: tools_dir, use_ssh, ssh_host, ssh_username, +3 more. Returns: object
execute_commandA
执行系统命令(本地或通过 SSH 远程执行)
这是一个通用的命令执行工具,可用于:
检查 Java 环境是否正常(java -version)
查看系统进程状态(ps aux)
执行其他辅助命令
注意:内存马检测的核心功能请使用专用工具(list_java_processes、scan_process 等), 此工具仅用于辅助操作。
Args: command: 要执行的 shell 命令 use_ssh: 是否使用 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 端口,默认 22(不指定则从环境变量 SSH_PORT 读取) timeout: 命令超时时间(秒),默认 300 秒
Returns: 执行结果,包含 success、stdout、stderr、return_code
Inputs: command (required), use_ssh, ssh_host, ssh_username, +4 more. Returns: object
export_reportA
执行 memory-shell-detector-cli.jar 生成内存马检测报告
底层命令: java -jar memory-shell-detector-cli.jar --report <output_file> -p -f
此工具将扫描结果导出为结构化报告,包含:
扫描时间和目标进程信息
检测到的所有可疑类列表
每个可疑类的风险等级和类型判断
反编译的源代码片段
Args: pid: 目标 Java 进程的 PID output_file: 报告输出文件路径 tools_dir: 检测工具 jar 包所在目录 format: 报告格式(json/html/txt) use_ssh: 是否通过 SSH 在远程服务器执行 ssh_host/ssh_username/ssh_password/ssh_key_path/ssh_port: SSH 连接参数
Returns: 导出结果和报告文件路径
Inputs: pid (required), output_file (required), tools_dir, format, +6 more. Returns: object
get_system_info_toolA
获取当前系统环境信息
返回操作系统类型、平台架构、临时目录等信息, 用于判断检测工具的兼容性和确定工具存放路径。
Returns: system: 操作系统(Linux/Windows/Darwin) platform: 完整平台信息 machine: CPU 架构 temp_dir: 系统临时目录路径
Inputs: no named parameters. Returns: object
list_java_processesA
执行 memory-shell-detector-cli.jar 列出系统中所有运行的 Java 进程
底层命令: java -jar memory-shell-detector-cli.jar -l
此工具通过调用内存马检测器的 CLI jar 包,扫描系统中所有 Java 进程, 返回进程 PID、进程名称等信息,用于后续选择目标进程进行内存马扫描。
Args: tools_dir: 检测工具 jar 包所在目录 use_ssh: 是否通过 SSH 在远程服务器执行 ssh_host/ssh_username/ssh_password/ssh_key_path/ssh_port: SSH 连接参数
Returns: processes: Java 进程列表信息
Inputs: tools_dir, use_ssh, ssh_host, ssh_username, +3 more. Returns: object
remove_memory_shellA
执行 memory-shell-detector-cli.jar 从 JVM 内存中移除指定的内存马类
底层命令: java -jar memory-shell-detector-cli.jar -r <class_name> -p
此工具通过 Java Agent 技术从运行中的 JVM 进程中卸载/禁用指定的恶意类, 实现不重启服务的情况下清除内存马。
移除机制:
对于 Filter/Servlet/Listener:从 Web 容器中注销
对于 Spring 组件:从 Spring 容器中移除 Bean
对于 Agent 类型:尝试还原被 hook 的方法
安全机制:首次调用时会先反编译目标类源码供 AI 分析确认, 确认是内存马后需设置 ai_confirmed=True 再次调用才会执行移除。
Args: class_name: 要移除的内存马完整类名 pid: 目标 Java 进程的 PID tools_dir: 检测工具 jar 包所在目录 ai_confirmed: AI 是否已确认该类为内存马(首次调用设为 False) use_ssh: 是否通过 SSH 在远程服务器执行 ssh_host/ssh_username/ssh_password/ssh_key_path/ssh_port: SSH 连接参数
Returns: 首次调用返回反编译源码供分析,确认后返回移除结果
Inputs: class_name (required), pid (required), tools_dir, ai_confirmed, +6 more. Returns: object
scan_processA
执行 memory-shell-detector-cli.jar 对指定 Java 进程进行内存马扫描检测
底层命令: java -jar memory-shell-detector-cli.jar -s
此工具通过 Java Agent 技术注入目标 JVM 进程,扫描以下可疑组件:
Servlet/Filter/Listener 类型内存马
Spring Controller/Interceptor 内存马
Agent 类型内存马
其他动态注册的恶意类
扫描结果会列出所有可疑类的完整类名,供后续反编译分析。
Args: pid: 目标 Java 进程的 PID tools_dir: 检测工具 jar 包所在目录 use_ssh: 是否通过 SSH 在远程服务器执行 ssh_host/ssh_username/ssh_password/ssh_key_path/ssh_port: SSH 连接参数
Returns: scan_result: 扫描结果,包含可疑类列表
Inputs: pid (required), tools_dir, use_ssh, ssh_host, +4 more. Returns: object
view_class_codeA
执行 memory-shell-detector-cli.jar 从 JVM 内存中提取并反编译指定类的字节码
底层命令: java -jar memory-shell-detector-cli.jar -v <class_name> -p
此工具通过 Java Agent 从运行中的 JVM 进程内存中 dump 指定类的字节码, 然后使用内置反编译器将字节码还原为可读的 Java 源代码。
这是分析内存马的关键步骤,可以查看:
类的完整实现逻辑
恶意代码的具体行为(如命令执行、文件操作、网络连接等)
内存马的注入方式和触发条件
Args: class_name: 要反编译的完整类名(如 com.example.EvilFilter) pid: 目标 Java 进程的 PID tools_dir: 检测工具 jar 包所在目录 use_ssh: 是否通过 SSH 在远程服务器执行 ssh_host/ssh_username/ssh_password/ssh_key_path/ssh_port: SSH 连接参数
Returns: source_code: 反编译后的 Java 源代码
Inputs: class_name (required), pid (required), tools_dir, use_ssh, +5 more. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool has a distinct purpose: network check, download, command execution, report export, system info, process listing, scanning, code viewing, and removal. No overlap exists, and descriptions clearly differentiate them.
Most tools follow verb_noun pattern (check_network, download_detector_tools, export_report, etc.). One outlier, get_system_info_tool, uses 'get' instead of a consistent verb and adds redundant '_tool', slightly breaking consistency.
With 9 tools, the server covers the full workflow from preparation (check, download) to detection (list, scan, view) to remediation (remove, report). The count is well-scoped and not excessive.
The toolset covers the entire memory shell detection lifecycle: network check, tool download, process listing, scanning, code review, removal, and report generation. No obvious gaps for the stated purpose.
Maintenance
Related MCP Connectors
Security scanner for AI agents and MCP servers: injection, jailbreak, tool abuse.
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
Ship better Java with your coding agent.
Let AI operate servers without SSH. Choose actions, approve risky changes, and audit every step.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI-powered Java source code vulnerability auditing through function-level taint analysis. Performs reverse tracking from dangerous functions to external entry points to automatically discover potential security vulnerability chains.119-
- AlicenseBqualityDmaintenanceСonnects to live JVMs via JDWP protocol, enabling LLM agents to autonomously debug Java applications — attach to a running process, pause threads, set breakpoints (including conditional), inspect stacks with auto-resolved object fields, evaluate methods, set variable values, and diagnose issues like deadlocks and hung queries.2818 PyPI1MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to securely execute remote commands via SSH or JumpServer, with flexible gateway configuration and plugin-based matchers for JumpServer login interfaces.2Apache 2.0
- AlicenseAqualityDmaintenanceEnables AI agents to execute commands on remote servers via SSH with dynamic host discovery through JumpServer and automatic username fallback.61MIT