外观主题
阅读语言

CloudSH —— 云 SSH 中继,无公网 IP 也能远程

软件 本站软件 3天前 更新于 20小时前
https://yxp.hk/p/qL5PML

📦 开源仓库:yxpil/CloudSH


CloudSH

云 SSH 中继 — 通过 HTTP 转发命令到被控主机,无需公网 IP,无需开放端口。

你 (任何网络)         云 VPS              被控主机 (内网)
cloudsh exec ──HTTP──→ Server ←──poll── cloudsh-agent
    ↑                    │                     │
    │                    │   命令入队           │ 本地执行
    │                    │                     │
    └── 同步等待 ←──── 转发结果 ←──── result ──┘

架构

组件 部署位置 作用
Server 云 VPS HTTP API 中继,命令队列 + 结果转发
Agent 被控主机 轮询命令,本地执行,返回文本
Client 用户机 CLI,注册 / 执行命令 / 查看状态

特性

  • 纯文本转发(拒绝二进制和控制字符)
  • 被控主机无需公网 IP、无需开放 SSH 端口
  • Agent 主动外连,穿透任意防火墙/NAT
  • 常量时间密码比较,防时序攻击
  • 内存存储,无持久化依赖,重启即清
  • 最多支持数千台被控主机

安装

git clone https://github.com/yxpil/CloudSH
cd CloudSH

# 一键编译全部
bash install.sh

# 或分机器编译
bash install.sh server   # 云 VPS 上
bash install.sh agent    # 被控主机上
bash install.sh client   # 用户机上

需要 Rust 1.80+。脚本会自动安装。

快速开始

1. 启动 Server(云 VPS)

CLOUDSH_PORT=8080 cloudsh-server

2. 注册 + 获取凭证(本地)

cloudsh -s http://:8080 register
# client_id:  a1b2c3d4
# password:   xxxxxxxxxxxxxxxx

3. 启动 Agent(被控主机)

CLOUDSH_SERVER=http://:8080 \
CLOUDSH_CLIENT_ID=a1b2c3d4 \
CLOUDSH_PASSWORD=xxxxxxxxxxxxxxxx \
cloudsh-agent

4. 执行命令

cloudsh -s http://:8080 exec whoami
cloudsh -s http://:8080 exec "ls -la /var/log"
cloudsh -s http://:8080 exec "df -h && free -m"

API

所有端点均为 POST,Content-Type: application/json。

POST /register

注册,返回 client_id + password。

→ (空)
← {"client_id": "a1b2c3d4", "password": "xxxxxxxxxxxxxxxx"}

POST /agent/poll

Agent 心跳 + 获取待执行命令。

→ {"client_id": "...", "password": "..."}
← {"command": {"command_id": "xxx", "command": "whoami"}}
← {"command": null}  // 无待执行命令

POST /agent/result

Agent