xsuneth/Easy-RSH

GitHub: xsuneth/Easy-RSH

基于 OpenSSL 认证的 C++ 远程命令执行系统,提供安全的客户端-服务端架构,支持多客户端并发连接和远程 Shell 操作。

Stars: 2 | Forks: 0

# 基于 OpenSSL 认证的远程命令执行系统 (客户端-服务端) ``` ███████╗ █████╗ ███████╗██╗ ██╗ ██████╗ ███████╗██╗ ██╗ ██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝ ██╔══██╗██╔════╝██║ ██║ █████╗ ███████║███████╗ ╚████╔╝ ██████╔╝███████╗███████║ ██╔══╝ ██╔══██║╚════██║ ╚██╔╝ ██╔══██╗╚════██║██╔══██║ ███████╗██║ ██║███████║ ██║ ██║ ██║███████║██║ ██║ ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ Easy Remote Shell Server v1.0 ``` 一个 C++ TCP **客户端-服务端命令执行系统**,允许远程客户端连接到服务端,并通过 **OpenSSL** 的 **SHA-256 + Salt 密码认证** 安全地执行 shell 命令。 本系统包含: - `server` : 远程命令服务端 (认证 + 命令执行) - `client` : 用于发送命令的远程客户端 - `adduser`: 用于将用户添加到用户数据库 (`users.txt`) 的实用工具 ## 📌 核心功能 - **基于 TCP socket 的客户端-服务端通信** - **使用 OpenSSL 进行安全认证** - 带有随机 Salt 的 SHA-256 哈希 - 用户凭据存储格式为:`username:salt:hash` - 成功登录后颁发会话 token - 基于 token 的命令授权 - **远程命令执行** - 在服务端执行 shell 命令并返回输出 - 支持 `cd ` (专门处理目录切换) - 通过管道进行实时输出捕获 - **多客户端支持** - 基于 fork 的进程模型 - 并发客户端处理 - 自动清理僵尸进程 ## 🗂️ 项目结构 ``` os-assignment/ │ ├── include/ │ ├── Auth.h # Authentication & hashing logic │ ├── Client.h # Client class interface │ ├── CommandExecutor.h # Command execution handler │ ├── Colors.h # Terminal color codes │ ├── Server.h # Server class interface │ └── Socket.h # RAII socket wrapper │ ├── src/ │ ├── socket/ │ │ └── Socket.cpp # Socket implementation │ │ │ ├── server/ │ │ ├── Auth.cpp # SHA-256 + Salt authentication │ │ ├── CommandExecutor.cpp # Fork/exec/pipe command handling │ │ ├── Server.cpp # Server logic & client handling │ │ ├── server_main.cpp # Server entry point │ │ └── adduser_main.cpp # User creation utility │ │ │ └── client/ │ ├── Client.cpp # Client implementation │ └── client_main.cpp # Client entry point │ ├── data/ │ └── users.txt # User database (salt:hash) │ ├── build/ # Compiled binaries ├── Makefile # Build configuration ├── README.md # This file ├── ARCHITECTURE.md # Detailed design document └── README_DETAILED.md # Extended documentation ``` ## ⚙️ 使用的技术 - **C++17** - **POSIX TCP socket** - **OpenSSL (`libssl`, `libcrypto`)** - **pthread / 并发支持** - Linux 系统 API (`fork`, `exec`, `pipe`, `waitpid`, `chdir`, `getcwd`) ## ✅ 环境要求 ### 操作系统 - 推荐 Linux (Ubuntu / Debian) ### 编译器 - 支持 C++17 的 `g++` ### 库 安装 OpenSSL 开发包: ``` sudo apt update sudo apt install build-essential libssl-dev make ``` ## 🔧 构建说明 构建所有组件: ``` make ``` 清理并重新构建: ``` make clean all ``` 构建特定目标: ``` make server make client make adduser ``` ## 👤 添加用户 (必需) 在连接之前,至少创建一个用户: ``` ./adduser ``` 示例: ``` ./adduser admin password123 ``` 这会将凭据写入: ``` data/users.txt ``` ## ▶️ 运行 ### 1) 启动服务端 ``` ./server # Run in single-process mode ./server --fork # Run with fork-based multi-client support (recommended) ``` ### 2) 启动客户端 ``` ./client ``` ### 3) 登录并执行命令 ``` Enter username: admin Enter password: ******** Authentication successful! Remote Shell> ls Remote Shell> pwd Remote Shell> cd /tmp Remote Shell> exit ``` ## 🔐 认证流程 1. **建立连接:** 客户端连接到服务端 2. **提供凭据:** 客户端发送 `username:password` 3. **验证:** 服务端: - 检索该用户名存储的 salt - 计算 `salt + password` 的 SHA-256 哈希值 - 与存储的哈希值进行比较 4. **响应:** 服务端返回: - ✅ 成功则返回 `AUTH_SUCCESS ` - ❌ 失败则返回 `AUTH_FAILED ` 5. **授权:** 所有后续命令都需要有效的 token ## 💻 远程命令 认证通过后,你可以运行如下命令: ``` ls pwd whoami date uname -a ``` ### `cd` 支持 ``` cd /home cd .. cd ~/Downloads ``` ## 🛡️ 安全说明 ✅ 已实现: - 密码不以明文形式存储 - 通过 OpenSSL 进行带 Salt 的 SHA-256 哈希处理 ⚠️ 未来可能的改进: - 为所有通信引入 TLS 加密 - 使用 Argon2/bcrypt 进行更强的密码哈希处理 - 命令沙箱化 / 白名单机制 - 速率限制和审计日志 ## 📄 许可证 本项目基于 MIT 许可证授权 - 详情请参阅 [LICENSE](LICENSE) 文件。 ## 🌟 致谢 - 使用 OpenSSL 进行加密操作 - 受传统 Unix 远程 shell 工具启发 - 展示了操作系统概念:进程、IPC、socket 和认证
标签:C++, OpenSSL, SHA-256加密, 安全测试工具, 客户端-服务端架构, 数据擦除, 网络编程, 远程命令执行