Whispergate/InfraGuard

GitHub: Whispergate/InfraGuard

一款红队 C2 重定向代理与管理工具,通过 C2 profile 验证和多维评分过滤管道保护红队基础设施免受威胁归因。

Stars: 94 | Forks: 4

![InfraGuard Logo](/images/infraguard_logo.svg) 红队基础设施追踪器和 C2 重定向器 —— [RedWarden](https://github.com/mgeeky/RedWarden) 的现代替代方案。 InfraGuard 位于互联网和您的 C2 团队服务器之间,根据您可定制的 C2 profile 验证每个入站请求,并阻止任何不符合规则的流量。扫描器、机器人和蓝队探针会被重定向到诱饵站点,而合法的 beacon 流量则允许通过并到达您的团队服务器。 ![Mythic Callbacks Xenon](/images/xenon_callback.png) ![InfraGuard Dashboard](/images/infraguard_dashboard.png) ## 架构 ![Architecture Diagram](/images/InfraGuard%20Infrastructure%20Diagram.drawio.png) ## 功能特性 - **多域名代理** -- 同时代理多个域名,每个域名拥有独立的 C2 profile、上游和规则 - **C2 profile 验证** -- 解析并强制执行 Cobalt Strike、Mythic、Brute Ratel C4、Sliver 和 Havoc 的 profile 作为重定向器规则 - **多协议监听器** -- HTTP/HTTPS、DNS、MQTT 和 WebSocket 监听器同时运行,并共享 IP 情报和事件跟踪 - **基于评分的过滤管道** -- 7 个过滤器(IP、bot、Header、DNS、GeoIP、profile、重放)各贡献 0.0-1.0 的分数;可配置的阈值决定阻止/允许 - **Anti-bot / 防爬虫** -- 40 多种已知的扫描器/bot User-Agent 模式,Header 异常检测 - **IP 情报** -- 内置 CIDR 黑名单,覆盖 19 个安全供应商范围(Shodan、Censys、Rapid7 等),GeoIP 过滤,反向 DNS 关键词匹配 - **威胁情报源** -- 从公共来源(abuse.ch、Emerging Threats、Spamhaus DROP、Binary Defense)自动更新黑名单,具有可配置的刷新间隔和磁盘缓存 - **规则导入** -- 从现有的 `.htaccess` 和 `robots.txt` 文件导入 IP 黑名单和 User-Agent 模式 - **动态 IP 阻断** -- 阻止白名单范围之外的 IP;在发生 N 次有效 C2 请求后自动将 IP 加入白名单 - **白名单富化** -- 启动时通过 GeoIP 数据库,自动使用 ASN、组织、国家和大洲数据丰富白名单中的 CIDR - **内容分发路由** -- 通过 PwnDrop、本地文件系统或 HTTP 代理后端,在特定路径提供 payload、诱饵和静态文件服务,支持可选的条件分发(向目标提供真实内容,向扫描器提供诱饵) - **丢弃动作** -- 重定向、TCP 重置、代理到诱饵站点或 tarpit(慢速响应以浪费扫描器时间) - **Web 仪表板** -- 实时单页应用(SPA),包含登录页面、实时请求流、域名统计、被阻断最多的 IP、经过身份验证的 WebSocket 事件流以及内联阻断/加白/解除阻断操作 - **Command Post** -- 多实例聚合仪表板,将多个 InfraGuard 节点的统计信息、请求和实时事件合并到一个视图中 - **终端 UI** -- 基于 Textual 的 TUI,带有登录界面、实时 API 轮询和颜色编码的请求日志 - **SIEM 集成** -- 为 Elasticsearch、Wazuh 和 Syslog (CEF/JSON) 提供内置插件,支持批量转发 - **Webhook 告警** -- 为 Discord (embeds)、Slack (Block Kit) 和通用 webhook (Rocket.Chat、Mattermost、Teams) 提供内置插件 - **插件系统** -- 事件驱动架构,带有 `on_event` 钩子、每个插件的配置和事件过滤(only_blocked、min_score、域名包含/排除) - **后端配置生成** -- 生成 Nginx、Caddy 或 Apache 配置,供操作人员完全自定义(TLS、IP 过滤、Header 检查、别名、自定义 Header) - **边缘代理** -- 轻量级 Cloudflare Worker 和 AWS Lambda,用于通过 CDN 基础设施进行域前置、边缘国家阻断和 Host 重写 - **Docker 部署** -- Dockerfile + docker-compose,带有可选的 Let's Encrypt、GeoIP 下载器和 PwnDrop payload 服务器 - **GeoIP 支持** -- 全部三个 GeoLite2 数据库(City、ASN、Country)均支持 Docker 自动下载;启动时自动丰富白名单 CIDR - **自签名 TLS 回退** -- 当配置的路径不存在时自动生成证书 - **环境变量支持** -- 自动加载 `.env` 文件;`${VAR}` 语法适用于所有配置值和键 - **可配置的健康检查端点** -- 更改健康检查路径以避免指纹识别 - **结构化日志** -- 通过 structlog 生成 JSON 格式的结构化日志 - **跟踪与持久化** -- 带有 WAL 模式的 SQLite,用于请求日志记录、统计信息和节点注册 ## 安装指南 查看 [Wiki 页面](https://github.com/Whispergate/InfraGuard/wiki/03.-Installation) 了解安装说明 ## CLI 参考 ``` infraguard --version Show version infraguard --help Show help infraguard run -c config.yaml Start the reverse proxy infraguard run -c config.yaml --port 8443 Override listen port infraguard run -c config.yaml --host 0.0.0.0 Override bind address infraguard dashboard -c config.yaml Start the web dashboard infraguard dashboard -c config.yaml --port 9090 Override dashboard port infraguard tui Launch TUI with login screen infraguard tui --url http://host:8080 --token TOK Auto-connect to dashboard infraguard tui -c config.yaml Read URL/token from config infraguard command-post -c command-post.yaml Start multi-instance dashboard infraguard command-post --instance name:url:token Add instance via CLI (repeatable) infraguard profile parse Parse and display a C2 profile infraguard profile parse --format json Output as JSON infraguard profile parse --type brute_ratel Force profile type infraguard profile convert -o out.json Convert profile to JSON # 支持的 --type 值:auto、cobalt_strike、mythic、brute_ratel、sliver、havoc # 自动检测:.profile = CS,.toml = Havoc,.json = 根据 key 自动检测 infraguard ingest Ingest .htaccess/robots.txt rules infraguard ingest --format blocklist Output as IP blocklist infraguard ingest --format json Output as JSON infraguard ingest -o banned_ips.txt Write blocklist to file infraguard generate nginx -c config.yaml Generate Nginx config infraguard generate caddy -c config.yaml Generate Caddyfile infraguard generate apache -c config.yaml Generate Apache VirtualHost infraguard init -o config.yaml Generate starter config infraguard validate -c config.yaml Validate config file ``` ### 生成器选项 `generate` 命令接受额外的标志以供操作员自定义: | 标志 | 描述 | |---|---| | `--listen-port PORT` | 覆盖监听端口(默认:来自配置) | | `--ssl-cert PATH` | 覆盖 SSL 证书路径 | | `--ssl-key PATH` | 覆盖 SSL 密钥路径 | | `--redirect-url URL` | 覆盖被阻止请求的重定向 URL | | `--default-action redirect\|404` | 不匹配请求的执行动作 | | `--no-ip-filter` | 省略 IP 允许/拒绝块 | | `--no-header-check` | 省略 Header 验证规则 | | `--alias DOMAIN:ALIAS` | 添加服务器名称别名(可重复) | | `--header NAME:VALUE` | 添加自定义响应 Header(可重复) | ## Command Post(多实例仪表板) 当在不同的 VPS 或云提供商上运行多个 InfraGuard 实例时,Command Post 会将所有节点的统计信息、请求和实时事件聚合到一个仪表板中。 ``` ┌─────────────────────────────┐ │ Command Post Dashboard │ │ http://localhost:9090 │ └──────────┬──────────────────┘ │ parallel fetch ┌─────┼──────┬──────────┐ ▼ ▼ ▼ ▼ IG-1 IG-2 IG-3 ... IG-N ``` ![InfraGuard Command Post](/images/infraguard_command_post.png) ### 快速开始 ``` # 通过配置文件 infraguard command-post -c config/command-post.yaml # 通过 CLI 参数 infraguard command-post \ --instance "prod:https://ig1.example.com:8080:TOKEN1" \ --instance "staging:https://ig2.example.com:8080:TOKEN2" \ --port 9090 # 通过 Docker docker compose --profile command-post up -d command-post ``` ### 配置 创建 `config/command-post.yaml`: ``` instances: - name: "prod-cs" url: "https://ig1.example.com:8080" token: "${IG_PROD_TOKEN}" - name: "prod-mythic" url: "https://ig2.example.com:8080" token: "${IG_MYTHIC_TOKEN}" - name: "staging" url: "https://ig3.example.com:8080" token: "${IG_STAGING_TOKEN}" port: 9090 # auth_token:"${COMMAND_POST_TOKEN}" ``` ### 显示内容 - **合并统计** -- 跨所有实例汇总的总请求数、允许数和阻止数 - **实例健康状态条** -- 每个已连接节点的绿色/红色状态 - **交错请求日志** -- 来自所有实例的请求按时间戳排序,每个请求都标有其实例名称 - **合并的被阻止最多的 IP** -- 跨所有实例聚合 - **每个域名的统计** -- 来自所有实例的域名,并重新计算阻止率 - **实时事件流** -- 来自所有节点的多路复用 WebSocket 事件 - **阻断/加白操作** -- 扇出至所有实例或特定实例 ### API 端点 | 端点 | 方法 | 描述 | |---|---|---| | `/api/instances` | GET | 列出所有实例及其健康状态 | | `/api/stats` | GET | 来自所有实例的合并统计信息 | | `/api/requests` | GET | 来自所有实例的交错请求日志 | | `/api/intel/whitelist` | POST | 将 IP 在所有实例上加白 | | `/api/intel/blocklist` | POST | 将 IP 在所有实例上阻断 | | `/api/intel/blocklist` | DELETE | 将 IP 在所有实例上解除阻断 | | `/ws/events` | WS | 来自所有实例的多路复用实时事件 | ## Docker 部署 ### 快速开始 ``` cp .env.example .env # 使用你的域名、teamserver 和 token 编辑 .env docker compose up -d ``` 这会启动两个服务: - **proxy** -- 端口 443 和 80 上的重定向器 - **dashboard** -- 端口 8080 上的 Web UI ### 使用 Let's Encrypt ``` # 在 .env 中设置: # INFRAGUARD_LETSENCRYPT=true # INFRAGUARD_DOMAIN=cdn.example.com # INFRAGUARD_DOMAIN_EMAIL=operator@example.com # 获取初始证书 docker compose --profile letsencrypt up certbot # 启动代理(将使用 LE 证书) docker compose up -d proxy dashboard # 启动自动续期(每 12 小时检查一次) docker compose --profile letsencrypt up -d certbot-renew ``` Let's Encrypt 的要求: - 必须可以从互联网访问端口 80 - `INFRAGUARD_DOMAIN` 必须解析到此主机的公共 IP - `INFRAGUARD_DOMAIN_EMAIL` 必须是有效的电子邮件地址 ### 使用 GeoIP 数据库 ``` # 下载全部三个 GeoLite2 数据库(City、ASN、Country) docker compose --profile geoip up geoip-update # 然后正常启动 - 数据库挂载在 /app/geoip/ docker compose up -d proxy dashboard ``` ### 使用 PwnDrop(payload 分发) ``` # 与代理一起启动 PwnDrop docker compose --profile pwndrop up -d pwndrop # 在 https://localhost:8443 访问 PwnDrop 管理界面 # InfraGuard 在内部通过 http://pwndrop:80 访问它 ``` 然后在您的配置中配置内容路由,将 payload 路径代理到 PwnDrop: ``` domains: cdn.example.com: content_routes: - path: "/downloads/*" backend: type: "pwndrop" target: "http://pwndrop:80" auth_token: "${PWNDROP_TOKEN}" ``` ### 扩展 ``` # 运行多个 redirector 节点 docker compose up -d --scale proxy-node=3 ``` 取消 `docker-compose.yml` 中 `proxy-node` 服务的注释以启用。 ### 卷 | 卷 | 用途 | |---|---| | `./config` | 配置文件(以只读方式挂载) | | `./examples` | C2 profile(以只读方式挂载) | | `./rules` | 导入的黑名单和规则源文件(以只读方式挂载) | | `./data` | SQLite 数据库(持久化) | | `certs` | TLS 证书(在 proxy 和 certbot 之间共享) | | `geoip` | GeoLite2 数据库(由 `geoip-update` 服务填充) | | `pwndrop-data` | PwnDrop 上传的文件和数据库 | ## 架构 ``` infraguard/ __init__.py Package init __main__.py python -m infraguard entry main.py Click CLI config/ YAML config loading, .env support, Pydantic validation core/ ASGI proxy engine (app, proxy, router, TLS, drop actions, content delivery) profiles/ C2 profile parsers (Cobalt Strike, Mythic, Brute Ratel, Sliver, Havoc) pipeline/ Request validation filters (IP, bot, header, DNS, geo, profile, replay) intel/ IP intelligence (blocklists, GeoIP, rDNS, feeds, rule ingestion) tracking/ SQLite persistence (request logging, stats, node registry) plugins/ Plugin system (protocol, loader, builtins) ui/ api/ REST API + WebSocket (Starlette) web/ SPA dashboard (HTML/JS/CSS) tui/ Terminal UI (Textual) with login screen command_post/ Multi-instance aggregation dashboard listeners/ Protocol listeners (HTTP, DNS, MQTT, WebSocket) backends/ Config generators (Nginx, Caddy, Apache) models/ Shared types and event models ``` ## 与 RedWarden 的对比 | 功能 | RedWarden | InfraGuard | |---|---|---| | 架构 | 约 99KB 的单个文件 | 模块化包 | | Profile 解析 | 正则表达式状态机 | 结构化解析器,支持完整的 block/transform | | C2 支持 | 仅限 Cobalt Strike | Cobalt Strike, Mythic, Brute Ratel C4, Sliver, Havoc | | 协议 | 仅限 HTTP | HTTP, DNS, MQTT, WebSocket | | 过滤模型 | 二元通过/失败 | 基于评分(0.0-1.0 阈值) | | 操作员 UI | 无 | Web 仪表板 + 终端 UI + 多实例 Command Post | | 配置生成 | 无 | Nginx, Caddy, Apache,支持完全自定义 | | 规则导入 | 无 | .htaccess + robots.txt 解析器 | | 内容分发 | 无 | PwnDrop,文件系统,带条件分发的 HTTP 代理 | | 威胁情报源 | 无 | 从 5 个公共来源自动更新 | | 插件系统 | 基础的 4 方法接口 | 事件驱动,带有 on_event 钩子 + 每个插件的配置 | | SIEM 集成 | 无 | Elasticsearch, Wazuh, Syslog (CEF/JSON) | | Webhook 告警 | 无 | Discord, Slack, 通用 webhook | | 白名单情报 | 无 | 启动时自动使用 ASN/组织/国家丰富 CIDR | | 防重放 | SQLite 哈希 | 具有可配置时间窗口的内存级处理 | | 丢弃动作 | 重定向,重置,代理 | 重定向,重置,代理,tarpit | | TLS 管理 | 仅限手动 | 自动自签名 + Let's Encrypt 集成 | | 边缘部署 | 无 | Cloudflare Worker + AWS Lambda 边缘代理,支持域前置 | | 部署 | 手动 | 带有健康检查的 Docker Compose | | 日志 | 自定义彩色输出 | 结构化 JSON (structlog) | | 异步 | Tornado 回调 | 原生 async/await (ASGI + uvicorn) | ## 贡献 - Mgeeky - 原始想法 ([RedWarden](https://github.com/mgeeky/RedWarden)) - curi0usJack - [.htaccess 规则](https://gist.github.com/curi0usJack/971385e8334e189d93a6cb4671238b10) - Profiles - threatexpress - [jquery-c2.3.14.profile](https://github.com/threatexpress/malleable-c2/blob/master/jquery-c2.3.14.profile) - InfinityCurve - [Havoc Profile](/examples/kaine.toml) - C2 框架 - [Cobalt Strike](https://www.cobaltstrike.com/) - Malleable C2 profile 支持 - [Mythic](https://github.com/its-a-feature/Mythic) - HTTPX profile 支持 - [Brute Ratel C4](https://bruteratel.com/) - Server config profile 支持 - [Sliver](https://github.com/BishopFox/sliver) - HTTP C2 profile 支持 - [Havoc](https://www.infinitycurve.org/) - TOML profile 支持 如果您希望为项目做出贡献,请创建一个带有版本名称的新分支,并在 Pull Request 中指定相同的版本名称。例如:branch=v1.2.3 | [v1.2.3] Added blah item。 ## 许可证 BSD 2-Clause 许可证。详情请参见 [LICENSE](LICENSE)。 版权所有 (c) 2026, Whispergate
标签:Brute Ratel, C2基础设施管理, C2重定向代理, Cobalt Strike, DNS监听, Havoc, HTTPS监听, IP信誉过滤, IP 地址批量处理, IP黑名单, Malleable C2, Mythic, RedWarden替代, Sliver, WebSocket, 依赖分析, 反扫描, 反爬虫, 多域代理, 威胁情报, 开发者工具, 情报阻断, 攻击归因防护, 攻击诱捕, 数据展示, 程序员工具, 红队, 网络信息收集, 网络攻防, 网络防御规避, 蓝队探测防御, 请求拦截, 逆向工具