0x7D4/Ghost-Protocol

GitHub: 0x7D4/Ghost-Protocol

一个基于 eBPF 的 Linux 移动目标防御系统,周期旋转端口与服务指纹并以 LLM 驱动的陷阱欺骗扫描者。

Stars: 0 | Forks: 0

# Ghost-Protocol — 每 60 秒更换一次 Linux 服务器身份 [![Build](https://img.shields.io/badge/build-passing-brightgreen)](https://github.com/0x7d4/Ghost-Protocol/actions) [![Tests](https://img.shields.io/badge/tests-26%20passing-brightgreen)](https://github.com/0x7d4/Ghost-Protocol) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/0x7d4/Ghost-Protocol/blob/main/LICENSE-APACHE) [![Rust](https://img.shields.io/badge/rust-1.80%2B-orange)](https://www.rust-lang.org) Ghost-Protocol 将你的 Linux 服务器从“固定靶子”变成矩阵中的故障点。如今,如果攻击者对您的 IP 运行 `nmap`,他们看到的正是您正在运行的内容:OpenSSH、Nginx,或许还有一个随机的 Redis 端口。使用 Ghost-Protocol,您的真实服务会被物理移动到一个基于 TOTP 密钥的高熵端口范围内,而所有 65,535 个标准端口则被欺骗性的粘滞陷阱(tarpit)所替代。这个陷阱不仅仅是挂起,还会利用 LLM 驱动的人格模拟真实服务握手,浪费自动化和人工侦察的时间,同时在内核层面标记攻击者。 ## 架构 ``` graph TD A[Attacker] -->|Ingress Traffic| XDP[eBPF XDP Ingress Hook] XDP -->|Recognized Scanner| TP[Tarpit Engine] XDP -->|Valid Signature| PH[Port Hopper Proxy] TP -->|Slow Drain| PE[LLM Persona Engine] PE -->|Ollama/Phi3| A PH -->|Proxy| RS[Real Services] RS -->|Egress SYN-ACK| TC[eBPF TC Egress Hook] TC -->|Rewrite headers| A subgraph Deception Layer TP PE end subgraph Hardened Core XDP PH TC end ``` ## 快速开始 ``` # 克隆仓库 git clone https://github.com/0x7d4/Ghost-Protocol.git && cd Ghost-Protocol # 构建完整的工作区 cargo build --release --workspace # 启动守护进程(需要 root 权限以使用 eBPF) sudo ./target/release/ghostd --config ghostd.toml ``` 首次使用?请运行设置脚本——它会自动处理 TOTP 密钥生成和 SSH 配置: ``` bash scripts/setup.sh # 启用 ollama LLM 支持: bash scripts/setup.sh --with-ollama ``` ## 生成 TOTP 密钥 设置脚本会自动生成并保存您的密钥。 如需手动生成: ``` openssl rand -base32 20 ``` ## SSH 连接 设置脚本在您运行 `bash scripts/setup.sh` 时会自动配置。 如需手动配置,请将以下内容添加到 `~/.ssh/config`: ``` Host ghost-server HostName YOUR_SERVER_IP User YOUR_USERNAME ProxyCommand /path/to/ghost-knock %h 10000 1000 "YOUR_SECRET" ``` 然后使用以下命令连接:`ssh ghost-server` ## ghostd.toml 配置参考 | 字段 | 类型 | 默认值 | 描述 | | :--- | :--- | :--- | :--- | | `interface` | `String` | `eth0` | 用于 eBPF 附加的网络接口。 | | `listen_addr` | `IpAddr` | `0.0.0.0` | 端口跳跃器的绑定地址。 | | `tarpit_enabled` | `Bool` | `true` | 启用欺骗性粘滞陷阱引擎。 | | `ollama_url` | `String` | `http://localhost:11434` | LLM 驱动响应的端点。 | | `persona_dir` | `Path` | `./personas` | 包含人格 `.toml` 文件的目录。 | | `rotation_interval` | `U64` | `60` | 端口旋转频率(秒)。 | **完整的 `ghostd.toml` 示例:** ``` # 要附加 eBPF 程序的网络接口 interface = "eth0" # 端口跳跃器的绑定地址 listen_addr = "0.0.0.0" # 启用欺骗性陷井引擎 tarpit_enabled = true # LLM 响应的 Ollama API 端点 ollama_url = "http://localhost:11434/api/chat" # 包含 persona .toml 文件的目录 persona_dir = "./personas" # 端口轮换间隔(秒)(必须与 ghost-knock 客户端匹配) rotation_interval = 60 ``` ## 人格参考 Ghost-Protocol 使用 `personas/` 目录中的 `.toml` 文件定义其与好奇扫描器的交互方式。 - **ssh.toml**:模拟 OpenSSH 7.4 服务器,带有真实的横幅延迟。 - **http.toml**:提供假的 Apache 2.4.41 管理面板。 - **mysql.toml**:实现 MySQL 线协议以进行握手欺骗。 - **smb.toml**:模拟 Windows Server 2019 文件共享服务。 - **generic.toml**:对未知端口提供低延迟混淆。 **自定义人格示例:** 创建 `personas/my-service.toml`: ``` system_prompt = "You are a bespoke industrial control system (SCADA). Respond with cryptic but valid-looking status codes." static_fallback = "ERROR: SYSTEM_HALTED_0xDEADBEEF\r\n" ``` ## 工作原理 - **第一层:eBPF 变形器**:TC 出口钩子重写出站 SYN-ACK 的 TTL 值、TCP 窗口大小、IP ID 序列以及 TCP 选项(SACK、wscale、时间戳),以匹配旋转的操作系统人格——让您的机器看起来像 Linux,然后是 Windows Server,接着是 Cisco 路由器,每 60 秒轮换一次。 - **第二层:端口跳跃器**:高性能代理,监听 1,000 个端口的范围。它使用 TOTP(基于时间的一次性密码)算法决定本分钟哪个端口是“开放”的,其余端口均导向粘滞陷阱。 - **第三层:粘滞陷阱**:采用内核级标记系统。一旦 IP 访问了一个关闭的端口,它就会被加入 `SCANNER_MAP`。来自该 IP 的所有后续流量都会被粘滞陷阱引擎拦截并进行慢速响应。 - **第四层:LLM 人格引擎**:与 Ollama 集成以流式传输真实的终端/协议输出。如果 LLM 离线,它会优雅地回退到静态蜜罐横幅以维持欺骗效果。 ## 系统要求 | 要求 | 版本 | 说明 | | :--- | :--- | :--- | | Linux 内核 | 5.15+ | 需要用于 XDP/TC eBPF 钩子 | | CAP_NET_ADMIN + CAP_BPF | — | 需要加载 eBPF 程序 | | Rust 稳定版 | 1.80+ | 工作区编译 | | Rust 夜间版 | 最新 | 仅 ghost-ebpf BPF 目标需要 | | ollama + phi3:mini | 可选 | LLM 人格引擎 | ### 一键设置(Ubuntu 22.04+) ``` # 安装依赖,生成 TOTP 密钥,配置 SSH, # 并运行 cargo check + clippy + 测试 bash scripts/setup.sh # 同时安装 ollama + phi3:mini: bash scripts/setup.sh --with-ollama ``` 设置脚本会处理所有内容:系统包、Rust 稳定版 + 夜间版、bpf-linker,以及可选的 ollama + phi3:mini。 ## ⚠️ 开始前 — 将您的 IP 加入允许列表 **这是最重要的一步。** 如果您在未将自身 IP 加入允许列表的情况下启动 `ghostd`,将被锁定在服务器之外。 在启动前将管理员 IP 添加到 `ghostd.toml`: ``` [allowlist] ips = ["YOUR.ADMIN.IP.HERE/32", "192.168.1.0/24"] ``` 要查找当前公网 IP: ``` curl -s ifconfig.me ``` 允许列表的 IP 将完全绕过所有 eBPF 钩子——您的 SSH、监控和 CI/CD 将照常运行。 ## 以 systemd 服务运行 对于生产服务器,请以 systemd 服务运行 `ghostd`,以便在重启后仍能保持运行。 创建 `/etc/systemd/system/ghostd.service`: ``` [Unit] Description=Ghost-Protocol Moving Target Defense Daemon After=network.target Wants=network-online.target [Service] Type=simple ExecStart=/usr/local/bin/ghostd --config /etc/ghost-protocol/ghostd.toml ExecStop=/usr/local/bin/ghostd --detach Restart=on-failure RestartSec=5s # eBPF 所需的能力 AmbientCapabilities=CAP_NET_ADMIN CAP_BPF CAP_NET_RAW CapabilityBoundingSet=CAP_NET_ADMIN CAP_BPF CAP_NET_RAW # 安全加固 NoNewPrivileges=yes ProtectSystem=strict ProtectHome=yes ReadWritePaths=/var/log/ghost-protocol /run/ghost-protocol [Install] WantedBy=multi-user.target ``` 启用并启动: ``` sudo cp target/release/ghostd /usr/local/bin/ sudo mkdir -p /etc/ghost-protocol sudo cp ghostd.toml /etc/ghost-protocol/ sudo systemctl daemon-reload sudo systemctl enable ghostd sudo systemctl start ghostd sudo systemctl status ghostd ``` ## 正常运行的表现 **启动时:** ``` [2026-04-19T10:23:01Z INFO ghostd] Ghost-Protocol starting [2026-04-19T10:23:01Z INFO ghostd::ebpf_loader] Attaching XDP hook to eth0 [2026-04-19T10:23:01Z INFO ghostd::ebpf_loader] Attaching TC egress hook to eth0 [2026-04-19T10:23:01Z INFO ghostd::ebpf_loader] Active persona: Linux 5.x (TTL=64, win=29200) [2026-04-19T10:23:01Z INFO ghostd::tarpit] Tarpit listening on 0.0.0.0:2222 [2026-04-19T10:23:01Z INFO ghostd] Ghost-Protocol running. Press Ctrl+C to stop. ``` **扫描器交互时:** ``` [2026-04-19T10:31:14Z WARN ghostd::ebpf_loader] Scanner detected: 45.33.32.156 (16 ports in 3s) [2026-04-19T10:31:15Z INFO ghostd::tarpit] Engaging 45.33.32.156 with persona: SSH-2.0-OpenSSH_7.4 [2026-04-19T10:31:15Z INFO ghostd::persona] Streaming LLM response to 45.33.32.156:54821 [2026-04-19T10:40:02Z INFO ghostd::session] Session closed: { "src_ip": "45.33.32.156", "duration_secs": 523, "credential_tries": 7, "bytes_wasted": 4821, "tool_signature": "Nmap", "score": 1081, "summary": "Confused Nmap for 8m 43s — 4821 bytes wasted, 7 cred attempts" } ``` ## 停止并脱离 eBPF 程序 ``` # 以 systemd 服务运行时 sudo systemctl stop ghostd # 手动运行时 — Ctrl+C 会自动干净地分离 # 强制分离 eBPF 钩子(无需守护进程运行): sudo ./target/release/ghostd --detach ``` ## 已测试的环境 | 发行版 | 内核 | 状态 | | :--- | :--- | :--- | | Ubuntu 22.04 LTS | 5.15 | ✅ 已测试 | | Ubuntu 24.04 LTS | 6.8 | ✅ 已测试 | | Debian 12 | 6.1 | ✅ 已测试 | | Fedora 38 | 6.2 | ✅ 已测试 | | WSL2 (Ubuntu) | 5.15 | 🛠 仅开发环境 — 不支持 eBPF | ## 测试 工作区包含一组严格的集成测试和单元测试。 ``` # 顺序运行完整套件 cargo test --workspace -- --test-threads=1 ``` - **26 个非特权测试**:覆盖 UI、代理逻辑和会话跟踪。 - **1 个特权测试**:`ebpf_test.rs` 需要 root 和 `CAP_NET_ADMIN` 来创建虚拟 veth 对以测试数据平面。 ## 许可证 本项目根据以下之一许可: - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) 或 http://www.apache.org/licenses/LICENSE-2.0) - MIT 许可证 ([LICENSE-MIT](LICENSE-MIT) 或 http://opensource.org/licenses/MIT) ## 贡献 1. **Fork** 仓库:[github.com/0x7d4/Ghost-Protocol](https://github.com/0x7d4/Ghost-Protocol) 2. **创建功能分支**:`git checkout -b feature/my-improvement` 3. **运行测试套件**:提交前执行 `cargo test --workspace -- --test-threads=1` 4. **提交拉取请求**:请提供变更的清晰描述 所有贡献在提交前必须通过 `cargo clippy -- -D warnings` 和 `cargo fmt --check`。
标签:aya, C2, Docker镜像, Linux 伪装, LLM 人格引擎, LLM 欺骗, LLM评估, Ollama, Phi3, ratatui, Rust, SYN-ACK 重写, Tarpit, TC eBPF, tokio, TOTP, XDP, 代理转发, 内核级检测, 反侦察, 可视化界面, 实时混淆, 扫描器陷阱, 服务指纹轮换, 欺骗层, 移动目标防御, 端口混淆, 端口跳转, 网络流量审计, 网络隐身, 蜜罐, 证书利用, 身份轮换, 高熵端口