About RemoteCommandExec
RemoteCommandExec is an MCP server published by Ning9527fff in the Blockchain category: mcp for llm to access remote server.
The repository has 3 stars and 0 forks, with the last commit 4 months ago. Recent commit activity is the strongest signal that reported issues will get attention.
Install
git clone https://github.com/Ning9527fff/RemoteCommandExecThis server has no ConduID identity, so agent calls to it are not receipted. Pin the version you install and review the source before granting it credentials.
Ask AI
Ask AI about RemoteCommandExec
Powered by Claude · Grounded in docs
Security checks
- ✓README presentThe repository ships documentation.
5 checks have not been run yet.
README
RemoteCommandExeced
一个受限的远程命令执行工具,专为 AI 模型设计。通过 MCP 协议让大模型在生产/测试环境的服务器上安全地执行诊断命令。
可以理解为一个阉割过的 SSH:只允许执行白名单内的命令,危险操作一律禁止。
架构
┌─────────────┐ stdio ┌─────────────┐ gRPC ┌─────────────┐
│ AI Model │ ◄──────────► │ MCP Server │ ──────────► │ gRPC Server │
│ (Claude etc) │ │ (本地运行) │ │ (Linux 服务器) │
└─────────────┘ └─────────────┘ └─────────────┘
- gRPC Server:部署在目标 Linux 服务器上,接收并执行命令
- MCP Server:本地运行,通过 stdio 与 AI 模型通信,转发请求到 gRPC Server
安全机制
本项目采用应用层 + OS 层纵深防御,缺一不可。
应用层
黑名单(硬编码,不可绕过)
以下命令无论白名单如何配置都永远禁止:
rm rmdir mkfs dd shred mv truncate
同时禁止 >(输出重定向)、`(反引号)、$() (命令替换)。
管道 |、;、&&、|| 允许使用,但会拆分出每个子命令逐一检查黑名单和白名单。
白名单(前缀匹配)
只有匹配白名单前缀的命令才能执行。例如配置 "docker ps" 后:
docker ps -a— 允许docker rm xxx— 拒绝
Delete 接口
文件删除通过独立的 delete_file 接口完成,自动保护系统关键路径(/、/usr、/etc、/bin 等)。
OS 层(强烈建议配置)
如果你以 root 用户或高权限用户运行本服务,且白名单中包含解释器(python、perl 等),LLM 可以通过解释器执行任意代码,实现无限提权。
例如白名单包含
python3时,LLM 可以:python3 -c "import os; os.system('rm -rf /')" python3 -c "import subprocess; subprocess.run(['chmod', '777', '/etc/shadow'])" python3 -c "import os; os.setuid(0)" # 如果进程本身是 root应用层黑名单在这里完全无效,因为
rm是由 Python 进程内部发起的,不经过本工具的检查。
创建受限用户
# 创建专用用户,禁止登录
useradd -r -s /usr/sbin/nologin rce
在配置文件中指定 run_as,服务启动时会自动降权:
{
"listen": ":9090",
"password": "your-password-here",
"run_as": "rce",
"allow_list": [...]
}
启动时需要 root 权限(降权后自动释放):
sudo ./rce server server_config.json
# 日志: switched to user 'rce' (uid=xxx, gid=xxx)
控制解释器访问
通过 Linux 文件权限决定 rce 用户能否执行解释器:
# 方法一:只允许特定组执行 python
chmod 750 /usr/bin/python3
chgrp staff /usr/bin/python3
# rce 用户不在 staff 组 → 无法执行 python3
# 方法二:如果需要 python 诊断,只放行特定脚本
# 白名单写 "python3 /opt/scripts/diag.py" 而不是裸放 "python3"
限制文件系统权限
# 确保 rce 用户对关键目录只有读权限
chmod o-w /etc /usr /var
# rce 用户即使通过解释器调用 rm,也因没有写权限而失败
安全等级参考
| 等级 | 配置 | 风险 |
|---|---|---|
| 危险 | root 运行 + 白名单含 python3 |
LLM 可完全控制服务器 |
| 较低 | run_as: rce + 白名单含 python3 |
LLM 可在 rce 权限范围内执行任意代码 |
| 安全 | run_as: rce + 解释器无执行权限 |
LLM 只能执行白名单内的诊断命令 |
| 最严格 | run_as: rce + 只读文件系统 + seccomp |
即使存在未知漏洞也难以造成破坏 |
快速开始
编译
go build -o rce .
如需重新生成 protobuf 代码:
protoc --go_out=. --go_opt=paths=source_relative \ --go-grpc_out=. --go-grpc_opt=paths=source_relative \ proto/executor.proto
启动 Server(Linux 服务器)
- 创建配置文件
server_config.json:
{
"listen": ":9090",
"password": "your-password-here",
"run_as": "rce",
"allow_list": [
"ps", "top", "df", "du", "free", "uptime",
"cat", "head", "tail", "grep", "find", "ls",
"netstat", "ss", "ip",
"systemctl status", "journalctl",
"docker ps", "docker logs", "docker inspect",
"kubectl get", "kubectl describe", "kubectl logs"
]
}
- 启动(配置了
run_as需要 root 权限):
sudo ./rce server server_config.json
启动 MCP(本地)
- 创建配置文件
mcp_config.json:
{
"server_addr": "your-server-ip:9090",
"password": "your-password-here"
}
- 在 AI 工具中配置 MCP:
{
"mcpServers": {
"remote-exec": {
"command": "/path/to/rce",
"args": ["mcp", "/path/to/mcp_config.json"]
}
}
}
MCP 工具
| 工具名 | 说明 |
|---|---|
execute_command |
在远程服务器上执行命令(受白名单限制) |
delete_file |
删除远程服务器上的文件或目录(保护关键路径) |
项目结构
├── main.go # 入口,支持 server/mcp 两种模式
├── proto/
│ └── executor.proto # gRPC 协议定义
├── server/
│ └── server.go # gRPC 服务实现(黑名单 + 白名单 + Delete)
├── mcp/
│ └── mcp.go # MCP stdio 服务
├── config/
│ └── config.go # 配置加载
├── server_config.example.json # Server 配置示例
└── mcp_config.example.json # MCP 配置示例
README copy captured when this server was indexed; it may lag the repository. The original is authoritative.