Navneet200523/Custom-C2-infrastructure-Framework
GitHub: Navneet200523/Custom-C2-infrastructure-Framework
RedOps 是一个集成了 MITRE ATT&CK 自动映射的红队 C2 基础设施框架,提供多通道通信、Agent 植入和自动化渗透报告生成能力。
Stars: 0 | Forks: 0
# 🔴 RedOps — 自定义 C2 基础设施框架
## ⚠️ 法律免责声明
## 📖 概述
**RedOps** 是一个自定义构建的命令与控制(C2)基础设施框架,旨在受控环境中模拟现实世界的对手行为。它为红队和安全研究人员提供了一个功能齐全的 C2 流水线 —— 从植入部署到操作员任务分配,再到自动映射 MITRE ATT&CK 的报告生成。
### 为什么选择 RedOps?
- **专为学习打造** — 深入了解真实的 C2 框架底层运行原理
- **原生支持 MITRE ATT&CK** — 每条命令都会自动映射到 ATT&CK 技术
- **多通道通信** — 支持 HTTP、HTTPS (TLS) 和 DNS 隧道
- **模块化架构** — 插件系统便于轻松扩展功能
- **完整的操作员体验** — 丰富的 CLI + 实时 Web 仪表盘
- **自动化报告** — 生成包含技术热图的 PDF 渗透测试报告
## 🏗️ 架构
```
┌──────────────────────────────────────────────────────────────────┐
│ OPERATOR LAYER │
│ ┌─────────────────┐ ┌──────────────────────────┐ │
│ │ Rich CLI │ │ Web Dashboard (Flask) │ │
│ │ c2_cli.py │ │ Real-time SocketIO │ │
│ └────────┬─────────┘ └────────────┬─────────────┘ │
│ │ REST API │ │
│ └──────────────┬────────────────────┘ │
├──────────────────────────┼───────────────────────────────────────┤
│ C2 SERVER │
│ ┌───────────────────────┼───────────────────────────────┐ │
│ │ ┌────────▼────────┐ │ │
│ │ │ Flask Router │ │ │
│ │ └────────┬────────┘ │ │
│ │ ┌──────────┬───────┼───────┬──────────┐ │ │
│ │ ▼ ▼ ▼ ▼ ▼ │ │
│ │ HTTP(S) DNS Crypto SQLite MITRE Mapper │ │
│ │ Listener Listener Engine Models Auto-Tagger │ │
│ └───────────────────────────────────────────────────────┘ │
├──────────────────────────────────────────────────────────────────┤
│ AGENT (IMPLANT) │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ Beacon Loop ──▶ Execute Tasks ──▶ Return Results │ │
│ │ │ │
│ │ Modules: Sysinfo │ Persistence │ Adaptive Beacon │ │
│ │ Stubs: Keylogger │ Process Injection │ │
│ └───────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────┘
```
## ✨ 功能
### 核心基础设施
| 功能 | 描述 |
|---|---|
| **HTTP Listener** | 带有 beacon/task/result endpoint 的 RESTful Flask C2 服务器 |
| **HTTPS Listener** | 支持自签名证书的 TLS 加密 C2 |
| **DNS Listener** | 用于绕过防火墙的隐蔽 DNS 隧道 |
| **AES-256 加密** | 每条消息使用随机 IV 的 CBC 模式 payload 加密 |
| **SQLite 数据库** | 持久化存储 agent、task 和 result |
### Agent 功能
| 模块 | 描述 | MITRE 技术 |
|---|---|---|
| **系统侦察** | OS、主机名、用户名、网络信息 | T1082, T1033 |
| **命令执行** | 任意 shell 命令执行 | T1059 |
| **持久化** | 安装 Cron job / systemd 服务 | T1053 |
| **自适应 Beaconing** | 基于 ML (IsolationForest) 的智能 beacon 定时 | T1029 |
| **键盘记录器** *(存根)* | 按键捕获接口 | T1056 |
| **进程注入** *(存根)* | 内存注入接口 | T1055 |
### 操作员工具
| 工具 | 描述 |
|---|---|
| **Rich CLI** | 具有彩色表格和 MITRE 标记的全功能终端 UI |
| **Web 仪表盘** | 基于 Flask + SocketIO 的实时仪表盘,可显示实时 agent 状态 |
| **PDF 报告生成器** | 带有 MITRE ATT&CK 技术热图的自动化渗透测试报告 |
### 安全与规避
- 🔐 AES-256-CBC 加密的 payload
- 🕐 抖动的 beacon 间隔,以规避时间分析
- 🤖 AI 驱动的自适应 beaconing(IsolationForest ML 模型)
- 📦 PyInstaller 二进制编译(目标机器上无需 Python 环境)
- 🌐 多通道通信(HTTP / HTTPS / DNS)
## 📂 项目结构
```
RedOps-C2/
├── agent/ # Implant (runs on target)
│ ├── agent.py # Main HTTP beacon agent
│ ├── dns_agent.py # DNS tunneling agent
│ ├── modules/ # Post-exploitation modules
│ │ ├── base_module.py # Abstract plugin interface
│ │ ├── sysinfo_module.py # System reconnaissance
│ │ ├── persistence.py # Cron/systemd persistence
│ │ ├── adaptive_beacon.py # ML-based beacon timing
│ │ ├── plugin_loader.py # Dynamic module loader
│ │ ├── keylogger_stub.py # Keylogger (interface only)
│ │ └── process_injection_stub.py # Injection (interface only)
│ ├── evasion/ # AV evasion techniques
│ └── comms/ # Communication channels
│
├── server/ # C2 Server
│ ├── listeners/
│ │ ├── http_listener.py # HTTP C2 listener (Flask)
│ │ ├── https_listener.py # HTTPS/TLS C2 listener
│ │ └── dns_listener.py # DNS tunneling listener
│ ├── crypto/
│ │ └── encryption.py # AES-256-CBC crypto engine
│ └── db/
│ └── models.py # SQLAlchemy ORM models
│
├── operator/ # Operator interface
│ ├── cli/
│ │ └── c2_cli.py # Rich CLI operator console
│ └── dashboard/
│ ├── app.py # Flask web dashboard
│ ├── templates/ # Jinja2 HTML templates
│ └── static/ # CSS/JS assets
│
├── shared/ # Shared utilities
│ ├── config.py # Global configuration
│ ├── secure_config.py # Env-based secret management
│ └── mitre_mapper.py # ATT&CK technique auto-tagger
│
├── reports/ # Report generation
│ ├── generate_report.py # PDF report engine
│ ├── templates/ # Report HTML templates
│ └── output/ # Generated report PDFs
│
├── certs/ # TLS certificates
│ ├── cert.pem # Self-signed certificate
│ └── key.pem # Private key
│
├── tests/ # Test suite
├── docs/ # Documentation
├── requirements.txt # Python dependencies
└── README.md # This file
```
## 🚀 安装说明
### 前置条件
- **Python 3.10+**
- **pip** 和 **venv**
- **OpenSSL**(用于生成 TLS 证书)
- 推荐使用 **Linux**(Ubuntu/Kali)
### 设置
```
# 1. Clone the repository
git clone https://github.com/Navneet200523/Custom-C2-infrastructure-Framework.git
cd Custom-C2-infrastructure-Framework
# 2. 创建并激活虚拟环境
python3 -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
# 3. Install dependencies
pip install --upgrade pip
pip install -r requirements.txt
# 4. (可选) 为 HTTPS 生成 TLS certificates
mkdir -p certs && cd certs
openssl req -x509 -newkey rsa:4096 \
-keyout key.pem -out cert.pem \
-days 365 -nodes \
-subj "/C=US/ST=State/L=City/O=RedOps/CN=redops.local"
cd ..
```
## 🎮 使用方法
### 1. 启动 C2 服务器
```
# HTTP mode (默认)
python server/listeners/http_listener.py
# HTTPS mode (TLS encrypted)
python server/listeners/https_listener.py
# DNS tunneling mode
python server/listeners/dns_listener.py
```
### 2. 部署 Agent(在目标机器上)
```
# 直接运行
python agent/agent.py
# 或编译为 standalone binary (目标机器无需 Python)
pyinstaller --onefile --noconsole agent/agent.py --name redops_agent
# Binary output: dist/redops_agent
```
### 3. 通过 CLI 进行操作
```
# 列出已连接的 agents
python operator/cli/c2_cli.py agents
# 加入一个命令 (自动标记 MITRE technique)
python operator/cli/c2_cli.py task
"whoami"
python operator/cli/c2_cli.py task "cat /etc/passwd"
python operator/cli/c2_cli.py task "netstat -tulpn"
# 查看任务结果
python operator/cli/c2_cli.py results
```
### 4. Web 仪表盘
```
python operator/dashboard/app.py
# 在浏览器中导航至 http://localhost:5001
```
### 5. 生成报告
```
python reports/generate_report.py
# PDF 输出保存至 reports/output/
```
## 🗺️ MITRE ATT&CK 映射
RedOps 会自动将操作员命令映射到 [MITRE ATT&CK](https://attack.mitre.org/) 技术:
| 命令 | 技术 ID | 技术名称 |
|---|---|---|
| `whoami` | T1033 | System Owner/User Discovery |
| `ifconfig` / `ip a` | T1016 | System Network Configuration Discovery |
| `netstat` | T1049 | System Network Connections Discovery |
| `ps` | T1057 | Process Discovery |
| `ls` / `find` | T1083 | File and Directory Discovery |
| `cat /etc/passwd` | T1003 | OS Credential Dumping |
| `crontab` | T1053 | Scheduled Task/Job |
| `wget` / `curl` | T1105 | Ingress Tool Transfer |
| `chmod` | T1222 | File and Directory Permissions Modification |
| `ssh` | T1021 | Remote Services |
| `scp` | T1041 | Exfiltration Over C2 Channel |
## 🔧 配置
### 环境变量
| 变量 | 描述 | 默认值 |
|---|---|---|
| `C2_HOST` | 服务器绑定地址 | `0.0.0.0` |
| `C2_PORT` | 服务器端口 | `5000` |
| `AES_KEY` | 加密密钥 (hex) | 自动生成 |
| `BEACON_INTERVAL` | Agent 签入间隔(秒) | `30` |
| `BEACON_JITTER` | ± 随机抖动(秒) | `10` |
### 配置文件
- [config.py](file:///d:/NIRMA/PROJECTS/c2%20infra/shared/config.py) — 全局设置(主机、端口、数据库路径、beacon 定时)
- [secure_config.py](file:///d:/NIRMA/PROJECTS/c2%20infra/shared/secure_config.py) — 基于环境的密钥管理
## 🧪 测试
```
# 运行 test suite
pytest tests/ -v
# 验证 server 已启动
python server/listeners/http_listener.py &
curl http://localhost:5000/agents
```
## 🗓️ 开发路线图
- [x] **阶段 1** — 核心 C2 基础设施(HTTP 监听器、agent、CLI、加密)
- [x] **阶段 2** — Web 仪表盘、DNS 隧道、持久化、PDF 报告
- [x] **阶段 3** — HTTPS/TLS、AI 自适应 beaconing、插件架构
- [ ] **阶段 4** — ICMP 隧道、横向移动模块、多操作员支持
- [ ] **阶段 5** — 可塑性 C2 配置文件、流量整形、云重定向器
## 🛠️ 技术栈
| 组件 | 技术 |
|---|---|
| **语言** | Python 3.10+ |
| **服务器** | Flask, Flask-SocketIO, Flask-SQLAlchemy |
| **数据库** | SQLite (SQLAlchemy ORM) |
| **加密** | PyCryptodome (AES-256-CBC) |
| **CLI** | Click, Rich |
| **仪表盘** | Flask + SocketIO + Jinja2 |
| **报告** | WeasyPrint (HTML→PDF) |
| **ML** | Scikit-learn (IsolationForest) |
| **MITRE** | mitreattack-python |
| **二进制构建** | PyInstaller |
## 📜 许可证
本项目仅用于**教育和授权的安全测试目的**。请参阅上方的[法律免责声明](#️-legal-disclaimer)。
## 📬 联系方式
**Navneet** — [GitHub 主页](https://github.com/Navneet200523)
为学习而生。为防御而生。请负责任地使用。
标签:C2框架, Flask, IP 地址批量处理, Python, 安全学习资源, 无后门, 漏洞挖掘, 网络安全, 逆向工具, 隐私保护