Nariod/linky

GitHub: Nariod/linky

一个用 Rust 编写的最小化 C2 框架,旨在通过极简代码库提供跨平台远程控制能力,便于学习、审计和二次开发。

Stars: 2 | Forks: 1

# Linky C2 Framework 一个最小化的 Rust 原生命令与控制 (Command & Control) 框架。重写自 [postrequest/link](https://github.com/postrequest/link)。 ## 快速开始 (Podman, 3 步) ``` # 1. 构建(包含用于动态生成植入程序的完整 Rust 工具链) podman build -t linky-c2 . # 2. 运行(端口 8443,植入程序数据卷 —— SELinux 系统上必需使用 :Z) podman run -it --rm \ -p 8443:8443 \ -v ./implants:/implants:Z \ --name linky-server \ linky-c2 # 3. 从 Linky CLI 提示符生成 Linux 植入程序 linky> generate-linux 192.168.1.10:8443 ``` 你的 implant 位于 `./implants/link-linux`。主机上不需要安装 Rust。 ## 为什么选择 Linky? | 特性 | 详情 | |-------|--------| | **Rust 原生** | 比 Go/Python 更难逆向 — 针对 Rust 二进制文件的 RE 工具有限 | | **小型代码库** | ~2.5k LOC vs Sliver 的 ~50k — 易于审计,易于 fork | | **容器优先** | 3 条命令完成构建 + 运行,无主机依赖 | | **KISS** | 单一二进制文件,单一协议,无需学习插件系统 | Linky **不**追求与 Sliver、Mythic 或 Havoc 的功能对等。它是一个专注的、最小化的 C2,适用于简单的任务和学习。 ## 架构 ``` linky/ ├── server/ # C2 server binary (crate: linky) │ └── src/ │ ├── main.rs # Entry: server + GC + CLI threads │ ├── server.rs # actix-web 4 + rustls 0.23 (self-signed TLS) │ ├── routes.rs # HTTP handlers: 3-stage C2 protocol │ ├── links.rs # Link registry and state management │ ├── tasks.rs # Per-link task queue │ ├── cli.rs # Interactive CLI (rustyline) │ ├── generate.rs # Implant builder (invokes cargo) │ ├── error.rs # Error types (thiserror) │ └── ui.rs # Terminal output helpers ├── links/ │ ├── common/ # Shared: C2 loop, HTTP client, crypto, wire types │ │ └── src/ │ │ ├── lib.rs # run_c2_loop(), crypto, types, helpers │ │ └── dispatch.rs # Cross-platform command dispatch │ ├── linux/ # Linux implant → link-linux (~310 LOC) │ ├── windows/ # Windows implant → link-windows.exe (~380 LOC) │ └── osx/ # macOS implant → link-osx (~220 LOC) ├── server/tests/ │ └── protocol.rs # 16 integration tests covering all 3 C2 stages ├── .github/workflows/ci.yml # CI: fmt + clippy -D warnings + test + audit ├── Dockerfile # Single-stage (Rust toolchain embedded for implant gen) ├── CLAUDE.md # Instructions for Claude Code └── .mistralrc # Instructions for Mistral Vibe ``` ### C2 协议 (3 阶段) 所有通信均使用 HTTPS/JSON,并采用 AES-256-GCM payload 加密。每个请求都会根据混淆的 User-Agent、session cookie 和滚动 UUID header 进行验证。 ``` Implant Server │ │ │── GET /js ───────────────────────▶│ Stage 1: Set-Cookie: banner=banner │ │ │── POST /static/register ─────────▶│ Stage 2: register + initial x_request_id │ header: X-Client-ID (secret) │ │◀─ { x_request_id } ──────────────│ │ │ │── POST /static/get ──────────────▶│ Stage 3: polling loop │ header: x-request-id │ body: AES-256-GCM encrypted payload │ body: { data: hex(nonce+ct) } │ ← implant submits task output (encrypted) │◀─ { data: hex(nonce+ct), xid } ──│ → server returns next task (encrypted) ``` 每个 implant 都有一个 **唯一的 AES-256-GCM 密钥**,该密钥在构建时通过 SHA-256 从随机 secret 派生。回调地址也在二进制文件中加密。密钥和地址永远不会以明文形式出现在二进制文件中。 ### 安全属性 | 属性 | 实现 | |----------|---------------| | 单 implant 密钥 | SHA-256(secret ‖ "callback-salt") — 每次构建随机 32 字节 secret | | 回调地址 | AES-256-GCM 加密存于二进制中,运行时解密 | | 传输 | HTTPS/TLS 1.3 (自签名, rustls 0.23) | | 字符串混淆 | 所有敏感字面量使用 `obfstr!()` 宏 | | 阶段验证 | UA + session cookie + 滚动 UUID x-request-id | | OOM 保护 | JSON payload 限制 64 KB,字段截断 (256 字节) | ## CLI 参考 ### 主菜单 ``` linky> help links Manage active links generate [--shellcode] Build Windows implant (x86_64-pc-windows-gnu) generate-linux [--shellcode] Build Linux implant (x86_64-unknown-linux-musl) generate-osx [--shellcode] Build macOS implant (x86_64-apple-darwin) help Show this help exit / kill Quit linky --shellcode Linux/macOS: extract .text section via objcopy → flat .bin Windows: copy PE (use sRDI/Donut for PIC conversion — item B.9) Uses release-shellcode profile (panic=abort, lto, opt-level=z) LINKY_OUTPUT_DIR Output directory for generated implants (default: .) ``` ### Link 交互 (平台感知帮助) ``` ── Execution ──────────────────────────────────────── shell Run via /bin/sh or cmd.exe cmd cmd.exe /C wrapper (Windows only) powershell powershell.exe wrapper (Windows only) ── Navigation ─────────────────────────────────────── ls / cd / pwd / whoami / pid ── Reconnaissance ─────────────────────────────────── info Detailed system information ps Running processes netstat Network connections ── File transfer ──────────────────────────────────── download Download file from implant upload Upload file to implant Quote paths with spaces: "path/to file" /remote/dest 'path/to file' /remote/dest ── Operational ────────────────────────────────────── sleep [jitter%] Polling interval (e.g. sleep 30 20) killdate Auto-exit date (e.g. killdate 2026-12-31) ── Windows ────────────────────────────────────────── integrity Token integrity level inject Inject base64 shellcode into PID ── Session ────────────────────────────────────────── kill Send exit + mark link dead back Return to links menu ``` 提示符会根据 implant 的平台进行适配:`link-1|lnx>`、`link-1|win>`、`link-1|osx>`。当与 Linux 或 macOS link 交互时,Windows 专用命令会被隐藏。 ### 下载 下载的文件会保存到服务器工作目录(或 `LINKY_OUTPUT_DIR`,如果已设置)下的 `downloads//` 中。 ## 从源码构建 ### 前置条件 **仅服务器:** Rust 1.70+ **完整版 (服务器 + implant 生成):** ``` # Debian/Ubuntu sudo apt-get install -y musl-tools mingw-w64 clang lld pkg-config libssl-dev binutils rustup target add x86_64-pc-windows-gnu x86_64-unknown-linux-musl # Fedora/RHEL sudo dnf install -y musl-gcc mingw64-gcc clang lld pkg-config openssl-devel binutils rustup target add x86_64-pc-windows-gnu x86_64-unknown-linux-musl ``` `binutils` 是 `objcopy` 所必需的(在 Linux 上由 `--shellcode` 使用)。 ### 构建并运行 ``` cargo build --release -p linky ./target/release/linky 0.0.0.0:8443 ``` ### Podman ``` podman build -t linky-c2 . podman run -it --rm -p 8443:8443 -v ./implants:/implants:Z linky-c2 ``` ## Implant 能力 | 功能 | Linux | Windows | macOS | |---------|-------|---------|-------| | Shell 执行 | `/bin/sh -c` | `cmd.exe /C` (CREATE_NO_WINDOW) | `/bin/sh -c` | | 系统信息 | `/proc`, `/etc/os-release` | PowerShell, 环境变量 | `sysctl`, `sw_vers` | | 进程列表 | `/proc` 解析 | `tasklist /FO CSV` | `ps aux` (shell) | | 网络连接 | `/proc/net/tcp*` (IPv4 + IPv6) | `netstat -ano` | `netstat -an` (shell) | | 文件下载/上传 | ✅ | ✅ | ✅ | | 可配置 sleep+jitter | ✅ | ✅ | ✅ | | Kill date | ✅ | ✅ | ✅ | | 加密 C2 通信 | AES-256-GCM | AES-256-GCM | AES-256-GCM | | 单 implant 密钥 | ✅ | ✅ | ✅ | | 混淆字符串 | ✅ | ✅ | ✅ | | Shellcode 导出 (.bin) | ✅ objcopy | PE copy (需要 sRDI) | ✅ objcopy | | 进程注入 | — | VirtualAllocEx + CreateRemoteThread | — | | 完整性级别 | — | Token 查询 | — | | 主机名检测 | `/etc/hostname` | `COMPUTERNAME` 环境 | `scutil --get ComputerName` | | 外部 IP | TCP peer addr (服务器端) | TCP peer addr | TCP peer addr | ## Roadmap ### 已知局限性 - **规避 (Evasion)**:零 EDR 规避。Windows 注入使用监控最严的 API (VirtualAllocEx + CreateRemoteThread)。无 AMSI/ETW 绕过。二进制签名问题未处理。 - **功能**:无持久化,无 SOCKS 代理,无凭证窃取,无横向移动。 - **运维**:单操作员,无日志写入磁盘,无 Web UI。 - **传输**:TLS 为自签名,无证书锁定或域前置。 ### Roadmap 状态 | Sprint | 重点 | 状态 | |--------|-------|--------| | 0–1.5 | 死代码清理,错误处理,加密,重构 | ✅ Done | | 1.6 | Cargo.toml 清理,CLI UX (平台感知帮助 + 提示符) | ✅ Done | | 2.2 | 构建配置 (release + release-shellcode) | ✅ Done | | 2.6 | `--shellcode` 标志:通过 objcopy 生成 `.bin` (Linux),PE (Windows) | ✅ Done | | 4.1–4.5 | 集成测试,CI/CD,macOS 对齐,link-common 测试 | ✅ Done | | **5** | **健壮性 (加密集中化,IPv6,退避,stage3 重构)** | **✅ Done** | | 3 | 持久化 (Linux+Windows),SOCKS 代理,env cmd,磁盘日志 | ⬜ Planned | | 6 | GUI — TUI ratatui 或嵌入式 Web UI (待定) | ⬜ Planned | | 2.x | 可配置配置文件 (Malleable profiles),间接系统调用,AMSI/ETW 绕过 | ⬜ Planned | | B.9 | sRDI 集成 (DLL → PIC shellcode Windows) | ⬜ Backlog | 详见 `TODO.txt` 获取详细任务列表,包括 GUI 架构对比。 ## 安全声明 此工具仅用于**经授权的**渗透测试任务。请勿在未经明确书面许可的情况下针对系统使用。 ## 测试 ``` # 完整质量检查 cargo fmt --all -- --check cargo clippy --workspace -- -D warnings cargo test --workspace # 构建所有植入程序(需要交叉编译工具链) cargo check -p link-linux --target x86_64-unknown-linux-musl cargo check -p link-windows --target x86_64-pc-windows-gnu cargo check -p link-osx cargo check -p link-common # 运行服务器 cargo run --release --bin linky 0.0.0.0:8443 ``` ### 验证端到端 ``` linky> generate-linux 127.0.0.1:8443 # 在另一个终端中运行生成的植入程序,然后: linky> links linky> -i link-1 link-1|lnx> whoami ``` 结果会显示在格式化框中: ``` ╔═ link-1 · whoami · 14:38:23 ═══════════════════╗ ║ root@hostname ╚═════════════════════════════════════════════════╝ ``` ## 已知 Bug | ID | 严重性 | 描述 | 状态 | |----|----------|-------------|--------| | B6-1 | Medium | `netstat` 输出中 IPv6 地址格式错误 | ✅ Fixed | | B6-2 | Minor | cli.rs 中的 `show_completed_task_results()` 实际上是死代码 | ✅ Documented as fallback | | B6-3 | Minor | Crypto 辅助函数在 3 处重复 (存在偏离风险) | ✅ Fixed | | B6-4 | Minor | `downloads/` 目录相对于服务器 CWD,未记录 | ✅ Fixed (`LINKY_OUTPUT_DIR`) | | B6-5 | Minor | Stage 1 重试循环无退避 (会淹没不可达的服务器) | ✅ Fixed | | B6-6 | Minor | Stage 3 中的网络错误会丢弃待处理任务输出 | ✅ Fixed | | B6-7 | Minor | `upload` 不支持单引号路径 | ✅ Fixed | | B6-8 | Minor | 64 KB JSON 限制对大文件上传来说太小 | ✅ Fixed (16 MB for `/static/get`) | | B6-9 | Minor | `inject_shellcode` 使用了未记录的 `transmute` | ✅ Fixed | | — | Minor | Link 计数器在服务器重启时重置 | Backlog | ## 面向 AI 开发者的配置 - **`CLAUDE.md`** — Claude Code 的约定、架构、安全规则 - **`.mistralrc`** — Mistral Vibe 的约定和工作流 - **`TODO.txt`** — 权威 Roadmap,包括 GUI 架构建议
标签:actix-web, C2框架, HTTPS通信, Implant生成, IP 地址批量处理, Link_Derived, Rust, Rust原生, 反向工程困难, 可视化界面, 命令控制, 安全学习资源, 容器化安全, 恶意软件, 数据采集, 最小化攻击框架, 网络信息收集, 网络安全, 网络流量审计, 自动化编译, 远程控制, 通知系统, 隐私保护