XMCVE/c2
GitHub: XMCVE/c2
基于纯 C89/C90 编写的极简 Windows C2 框架,提供加密远控通信能力,适合安全研究、红队演练与 C2 协议学习。
Stars: 0 | Forks: 0
# C2 框架
使用 C89/C90 编写的最小化 Windows C2 (命令与控制) 框架,无外部依赖,兼容 VC2008。
## 免责声明
本项目仅供在您拥有或被明确授权评估的系统和环境中进行授权的安全研究、测试和教育用途。您需自行负责遵守所有适用的法律、法规和政策。作者和贡献者对因使用本软件而导致的任何误用、损害或法律后果概不负责。
## 组件
| 二进制文件 | 角色 |
|---|---|
| `agent.exe` | 植入程序 - 在目标上运行,反向连接至服务器 |
| `server.exe` | 中继 - 在 agent 与 controller 之间路由流量 |
| `controller.exe` | 操作员 CLI - 向 agent 下发命令 |
| `tools/keygen.exe` | 构建时密钥生成器 |
## 加密
- **传输**:AES-256-GCM(每个数据包使用随机 12 字节 IV,16 字节认证标签)
- **密钥交换**:RSA-2048 OAEP (SHA-1 MGF1) - agent 和 controller 分别使用各自的 RSA 公钥加密其 AES-256 会话密钥;server 使用私钥进行解密
- **密钥**:在构建阶段由 `keygen.exe` 生成,作为 C 数组嵌入在 `common/keys_agent.h`、`common/keys_ctrl.h`、`common/keys_server.h` 中
## 构建
需要 Visual C++ (VC2008 或更高版本) 和 `nmake`。
```
nmake all
```
这将:
1. 构建 `tools/keygen.exe`
2. 运行 keygen 生成 `common/keys_*.h`
3. 构建 `agent.exe`、`server.exe`、`controller.exe`
清理:
```
nmake clean
```
## 部署
1. 在您的 C2 服务器上运行 `server.exe`(在端口 4444 监听 agent,在 4445 监听 controller)
- 监听器在 Windows 上使用独占端口绑定。当一个 `server.exe` 已经绑定了 `4444` 或 `4445` 时,再启动第二个 `server.exe` 会在启动时失败,并提示明确的 `address already in use` 错误。
2. 将 `agent.exe` 部署到目标机器 - 反向连接至 `example.com:4444`,作为隐藏的后台进程运行(无控制台窗口)
3. 在操作员机器上运行 `controller.exe` - 连接至 `example.com:4445`
## Controller 命令
```
agents list connected agents
use select agent by session id
ls [path] list directory on agent
cd [path] change agent working directory (no path: show cwd)
pwd print agent working directory
cat print file contents from agent
exec execute shell command on agent
shell open interactive shell (type ~. to detach)
upload upload file to agent
download download file from agent
socks start local SOCKS5 proxy tunneled through agent
ping ping selected agent
exit quit
```
远程相对路径是基于 agent 上
每个 controller 的工作目录进行解析的。`cd` 用于更新该目录,`pwd` 用于打印该目录,并且 `ls`、`cat`、
`exec`、`shell`、`upload` 和 `download` 都会使用该目录。
## 网络端口
| 端口 | 用途 |
|---|---|
| 4444 | Agent 信标(连入 server) |
| 4445 | Controller 连接(连入 server) |
## 数据包格式(加密)
```
[4 bytes] plaintext length (big-endian)
[12 bytes] AES-GCM IV (random per packet)
[N bytes] AES-256-GCM ciphertext (PKT_HDR + payload)
[16 bytes] GCM authentication tag
```
整个数据包头部 (`PKT_HDR`) 包含在密文中。密钥交换数据包(在连接开始时发送一次)是明文的 RSA 加密数据块。
## 文档
各模块的详细设计文档:
| 文档 | 描述 |
|---|---|
| [docs/protocol.md](docs/protocol.md) | 数据包格式、命令代码、结构化 payload、路由 |
| [docs/crypto.md](docs/crypto.md) | AES-256-GCM、RSA-2048 OAEP、大数、密钥生成 |
| [docs/agent.md](docs/agent.md) | 信标循环、命令处理程序、shell、SOCKS、文件系统 |
| [docs/server.md](docs/server.md) | 会话管理、数据包路由器、并发模型 |
| [docs/controller.md](docs/controller.md) | REPL、客户端连接、交互式 shell、SOCKS 隧道 |
| [docs/build.md](docs/build.md) | 构建系统、编译器标志、源文件列表 |
标签:AES-256-GCM, C2框架, C89/C90, Conpot, IP 地址批量处理, nmake, pdftotext, RSA-2048, VC2008, Windows安全, 代理中继, 加密通信, 命令与控制, 安全学习资源, 客户端加密, 恶意软件研究, 无外部依赖, 端点可见性, 端点安全, 网络信息收集, 网络安全, 网络安全对抗, 补丁管理, 远控木马, 隐私保护, 隐蔽通信