itcmsgr/nftban

GitHub: itcmsgr/nftban

NFTBan 是一个基于 nftables 的开源 Linux 入侵防御系统与防火墙管理器,通过威胁情报、登录监控、地理封禁等模块实现自动化的威胁检测与响应。

Stars: 5 | Forks: 0

# NFTBan **Linux 入侵防御系统与 nftables 防火墙管理器** [![版本](https://img.shields.io/badge/version-1.55.0-blue)](https://github.com/itcmsgr/nftban/releases) [![许可证: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0) [![Go](https://img.shields.io/badge/Go-1.24-00ADD8.svg)](https://go.dev/) [![状态](https://img.shields.io/badge/status-BETA-yellow)]() [![兼容 FHS](https://img.shields.io/badge/FHS-Compliant-success)]() ### CI/CD 状态 [![Shell 质量](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/6d0862d160110006.svg)](https://github.com/itcmsgr/nftban/actions/workflows/ci-bash.yml) [![Go 质量](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/faf102af9e110007.svg)](https://github.com/itcmsgr/nftban/actions/workflows/ci-go.yml) [![架构](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/742f594ea8110008.svg)](https://github.com/itcmsgr/nftban/actions/workflows/ci-architecture.yml) [![文档](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/7f30c16cbb110009.svg)](https://github.com/itcmsgr/nftban/actions/workflows/ci-docs.yml) [![构建包](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/355a05ec0c110010.svg)](https://github.com/itcmsgr/nftban/actions/workflows/build-packages.yml) [![发布](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/2d24e9449a110011.svg)](https://github.com/itcmsgr/nftban/actions/workflows/release.yml) [Docker](https://github.com/itcmsgr/nftban/actions/workflows/docker.yml/badge.svg)](https://github.com/itcmsgr/nftban/actions/workflows/docker.yml) [![ShellCheck](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/a1d22210b7110012.svg)](https://github.com/itcmsgr/nftban/actions/workflows/shellcheck.yml) ### 安全与供应链 [![SLSA 3](https://slsa.dev/images/gh-badge-level3.svg)](https://slsa.dev) [![SBOM](https://img.shields.io/badge/SBOM-SPDX--JSON-blue)](https://github.com/itcmsgr/nftban/releases) [![OpenSSF 记分卡](https://img.shields.io/ossf-scorecard/github.com/itcmsgr/nftban?label=OpenSSF%20Scorecard)](https://securityscorecards.dev/viewer/?uri=github.com/itcmsgr/nftban) [![OpenSSF 最佳实践](https://www.bestpractices.dev/projects/11959/badge)](https://www.bestpractices.dev/projects/11959) [![CodeQL](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/d9e12728ac110013.svg)](https://github.com/itcmsgr/nftban/actions/workflows/codeql.yml) [![Semgrep](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/15e2368e50110014.svg)](https://github.com/itcmsgr/nftban/actions/workflows/semgrep.yml) [![OSV-Scanner](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/c076b32a55110015.svg)](https://github.com/itcmsgr/nftban/actions/workflows/osv-scanner.yml) [![Trivy](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/66053fba5f110016.svg)](https://github.com/itcmsgr/nftban/actions/workflows/secure-go.yml) [![gitleaks](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/0c5628b6c9110017.svg)](https://github.com/itcmsgr/nftban/actions/workflows/gitleaks.yml) [![模糊测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/02b55ecb96110019.svg)](https://github.com/itcmsgr/nftban/actions/workflows/fuzz.yml) [![依赖审查](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/5d09c2c361110020.svg)](https://github.com/itcmsgr/nftban/actions/workflows/dependency-review.yml) ### 2026 OSSRA 合规性 [![OSSRA 修复](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/af4c04709a110021.svg)](https://github.com/itcmsgr/nftban/actions/workflows/ossra-remediation.yml) [![许可证合规](https://img.shields.io/badge/Licenses-Compliant-success)](https://github.com/itcmsgr/nftban/actions/workflows/ossra-remediation.yml) [![依赖健康状况](https://img.shields.io/badge/Libyear-Tracked-blue)](https://github.com/itcmsgr/nftban/actions/workflows/ossra-remediation.yml) ## 安全加固 (符合 2026 OSSRA 规范) 本项目实现了一个为现代威胁环境设计的 **零信任 CI/CD 流水线**: | 控制措施 | 保护作用 | |---------|------------| | **SLSA Level 3** | 加密来源证明 - 每个二进制文件均可证明其来源 | | **许可证强制执行** | 通过 `go-licenses` 拦截 GPL/copyleft 许可证 - 防止 AI 幻觉 | | **依赖新鲜度** | Libyear 指标标记超过 2 年的 "僵尸" 组件 | | **URL 验证** | Lychee 捕获幻觉/被劫持的文档链接 | | **机密扫描** | Gitleaks + GitGuardian 防止凭证泄露 | | **供应链** | 所有 GitHub Actions 均使用 SHA 固定,以防止劫持 | | **行为分析** | Socket.dev 检测仿冒和恶意软件包 | NFTBan 是一个基于 nftables 构建的开源 Linux 入侵防御系统 (IPS) 和防火墙管理器,旨在与现代 Linux 安全栈完美集成。 它利用原生 nftables 实现内核级别的强制执行,提供自动化的威胁检测与响应,并通过基于 Polkit 的权限分离,实现在无需完整 root 访问权限下的安全操作。 ## Go Module 注意事项 NFTBan 是一个 **系统级防火墙产品**,而不是通用的 Go 库。 虽然此仓库是一个 Go 模块并出现在 [pkg.go.dev](https://pkg.go.dev/github.com/itcmsgr/nftban) 上,但它 **并非设计或支持作为可嵌入的 SDK 使用**。这些 Go 包的存在是为了实现 NFTBan 的 daemon、CLI 和内部工具。 ### 支持的公共包 | 软件包 | 用途 | |---------|---------| | [`pkg/ipc`](https://pkg.go.dev/github.com/itcmsgr/nftban/pkg/ipc) | 与 NFTBan daemon 通信的 IPC 客户端 | | [`pkg/version`](https://pkg.go.dev/github.com/itcmsgr/nftban/pkg/version) | 版本信息 | ### 与 NFTBan 集成 - **CLI:** `nftban ban`, `nftban unban`, `nftban status` - **Go IPC 客户端:** `pkg/ipc` — 支持的公共 Go 包 - **HTTP API:** `http://127.0.0.1:9580/api/` (daemon 运行时可用) 所有位于 `internal/` 下的包均为内部实现细节,可能会在不同版本之间更改,恕不另行通知。 ## 快速安装 ### 级别 0 — 主要平台 #### Ubuntu 24.04 LTS (Noble) ``` wget https://github.com/itcmsgr/nftban/releases/latest/download/nftban-ubuntu24.04-amd64.deb sudo apt update && sudo apt install -y ./nftban-ubuntu24.04-amd64.deb && sudo nftban enable ``` #### Debian 12 (Bookworm) ``` wget https://github.com/itcmsgr/nftban/releases/latest/download/nftban-debian12-amd64.deb sudo apt update && sudo apt install -y ./nftban-debian12-amd64.deb && sudo nftban enable ``` #### Rocky / AlmaLinux / RHEL 9 ``` wget https://github.com/itcmsgr/nftban/releases/latest/download/nftban-el9-x86_64.rpm sudo dnf install -y ./nftban-el9-x86_64.rpm && sudo nftban enable ``` ### 级别 1 — 未来平台 #### Debian 13 (Trixie) ``` wget https://github.com/itcmsgr/nftban/releases/latest/download/nftban-debian13-amd64.deb sudo apt update && sudo apt install -y ./nftban-debian13-amd64.deb && sudo nftban enable ``` #### Rocky / AlmaLinux / RHEL 10 ``` wget https://github.com/itcmsgr/nftban/releases/latest/download/nftban-el10-x86_64.rpm sudo dnf install -y ./nftban-el10-x86_64.rpm && sudo nftban enable ``` ### 级别 2 — 旧版平台 #### Ubuntu 22.04 LTS (Jammy) ``` wget https://github.com/itcmsgr/nftban/releases/latest/download/nftban-ubuntu22.04-amd64.deb sudo apt update && sudo apt install -y ./nftban-ubuntu22.04-amd64.deb && sudo nftban enable ``` ### 从源代码构建 ``` git clone https://github.com/itcmsgr/nftban.git && cd nftban sudo ./install.sh cli # CLI-only (~50MB RAM) # 或 sudo ./install.sh gui # Full with Web GUI (~200MB RAM) ``` ## 可用安装包 ### RPM 包 (EL 系列) | 级别 | 发行版 | 版本 | 安装包 | |------|--------------|---------|---------| | 0 | Rocky / Alma / RHEL / CentOS Stream | 9 | [nftban-el9-x86_64.rpm](https://github.com/itcmsgr/nftban/releases/latest/download/nftban-el9-x86_64.rpm) | | 1 | Rocky / Alma / RHEL / CentOS Stream | 10 | [nftban-el10-x86_64.rpm](https://github.com/itcmsgr/nftban/releases/latest/download/nftban-el10-x86_64.rpm) | ### DEB 包 (Ubuntu + Debian) | 级别 | 发行版 | 版本 | 安装包 | |------|--------------|---------|---------| | 0 | Ubuntu | 24.04 (Noble) | [nftban-ubuntu24.04-amd64.deb](https://github.com/itcmsgr/nftban/releases/latest/download/nftban-ubuntu24.04-amd64.deb) | | 0 | Debian | 12 (Bookworm) | [nftban-debian12-amd64.deb](https://github.com/itcmsgr/nftban/releases/latest/download/nftban-debian12-amd64.deb) | | 1 | Debian | 13 (Trixie) | [nftban-debian13-amd64.deb](https://github.com/itcmsgr/nftban/releases/latest/download/nftban-debian13-amd64.deb) | | 2 | Ubuntu | 22.04 (Jammy) | [nftban-ubuntu22.04-amd64.deb](https://github.com/itcmsgr/nftban/releases/latest/download/nftban-ubuntu22.04-amd64.deb) | ## 功能特性 | 特性 | 描述 | |---------|-------------| | **威胁情报源** | 自动屏蔽来自 Spamhaus, AbuseIPDB, Firehol 的威胁 | | **地理封禁** | 按国家/地区代码屏蔽或允许流量 | | **登录监控** | 检测 SSH 暴力破解和可疑的身份验证模式 | | **端口扫描检测** | 自动检测并拦截侦察行为 | | **DDoS 防护** | 速率限制、SYN flood 防护、连接数限制 | | **HTTP 机器人防护** | 自动爬虫检测,结合内核原生可疑标记 | | **DNS 隧道嫌疑** | 基于 5 个信号的仅建议性 (Advisory-only) DNS 隧道检测 (v1.30.0) | | **Suricata IDS 集成** | 可选的深度包检测 | | **Prometheus 指标** | 面向监控栈的可观测性 | | **Zabbix 集成** | 原生 trapper 协议导出至 Zabbix 服务器 | | **门户** | 集中化指标聚合与集群管理 | | **连接器** | 导出到 Elasticsearch, Kafka, syslog, webhook | | **白名单安全测试** | 具备自动化安全验证的受保护白名单 | ## 快速开始 ``` # 验证安装 nftban version nftban health summary # 启用保护模块 nftban login enable # SSH login monitoring nftban feeds enable # Threat intelligence feeds nftban portscan enable # Port scan detection # 可选:Suricata IDS 集成 nftban suricata install # Install Suricata IDS nftban suricata enable # Enable with weekly rule updates # 常规操作 nftban ban 1.2.3.4 # Block IP nftban unban 1.2.3.4 # Remove ban nftban search 1.2.3.4 # Search across all sets nftban firewall reload # Atomic reload # 检查状态 nftban status ``` ## CLI 概览 ### 系统与健康 ``` nftban status # System overview nftban health # Diagnostics with auto-heal nftban validate # Firewall structure validation nftban services # Systemd services status nftban configtest # Validate config against schema ``` ### IP 管理 ``` nftban ban # Ban IP (with optional timeout) nftban unban # Remove ban nftban search # Search across all sets nftban whitelist add # Add to whitelist ``` ### 防护模块 ``` nftban login status # SSH login monitoring nftban feeds list # Threat feed status nftban geoban list # Geographic blocking nftban portscan status # Port scan detection nftban ddos status # DDoS protection nftban botguard status # HTTP bot guard (v1.20.0) nftban tunnel status # DNS tunnel suspicion (v1.30.0) ``` ### DNS 隧道嫌疑 (v1.30.0) ``` nftban tunnel enable # Enable monitoring (disabled by default) nftban tunnel status # Show status and summary nftban tunnel scan # Run scan now nftban tunnel top # Show top suspects by score nftban tunnel explain IP # Signal breakdown for an IP nftban tunnel config # Show configuration ``` 完整文档请参见 [CLI 命令参考](https://github.com/itcmsgr/nftban/wiki/CLI-Commands-Reference)。 ## 架构 ``` ip nftban { # IPv4 rules set whitelist_ipv4 {...} # Protected IPs (never blocked) set blacklist_ipv4 {...} # Unified blocklist (all sources) set tcp_ports_in {...} # Inbound TCP ports set udp_ports_in {...} # Inbound UDP ports chain input {...} chain forward {...} } ip6 nftban { # IPv6 rules set whitelist_ipv6 {...} # Protected IPs (never blocked) set blacklist_ipv6 {...} # Unified blocklist (all sources) chain input {...} chain forward {...} } ``` ### 组件 | 组件 | 类型 | 描述 | |-----------|------|-------------| | `nftban` | Bash CLI | 主命令行界面 (76 个命令) | | `nftban-core` | Go 二进制文件 | 负责信息源、geoip、同步的后端 | | `nftban-ui` | Go 二进制文件 | Web 界面服务器 | ## 系统要求 - **Linux**: Rocky/Alma/RHEL 9-10, CentOS Stream 9-10, Ubuntu 22.04+, Debian 12+ - **nftables**: 1.0+ (原生后端) - **Bash**: 4.4+ - **systemd**: 252+ (支持 sysusers.d, tmpfiles.d) - **jq**: JSON 处理器 (自动安装) - **yq**: YAML 处理器 (自动安装) - **Go 1.21+**: 用于从源代码构建 (可选) ## 支持的平台 NFTBan 采用分层支持模型。详情请参见[完整平台契约](https://github.com/itcmsgr/nftban/wiki/Supported-Platforms)。 ### 级别 0 — 主要 (CI 必测) | 系列 | 平台 | 内核 | nftables | |--------|----------|--------|----------| | DEB | Ubuntu 24.04 LTS | 6.8 | 1.0 | | DEB | Debian 12 | 6.1 | 1.0 | | RPM | Rocky Linux 9.x | 5.14 | 1.0 | ### 级别 1 — 未来 (计划中) - Rocky Linux 10.x / AlmaLinux 10.x / RHEL 10 - Debian 13 (Trixie) - Ubuntu 26.04 LTS ### 级别 2 — 旧版 (尽力支持) - Rocky/RHEL 8.x, Ubuntu 22.04, Debian 11 ## 开发 NFTBan 的开发使用 AI 工具进行代码生成和审查。所有代码均经过人工审查和版本控制。 | 工具 | 用途 | |------|-----| | ChatGPT (OpenAI) | 架构规划 | | Claude (Anthropic) | 实现、测试、审查 | ## 许可证 Mozilla Public License 2.0 (MPL-2.0) Copyright (c) 2024-2026 NFTBan Project / Antonios Voulvoulis ## 安全与供应链 NFTBan 遵循 **纵深防御** 安全实践,在我们的 CI/CD 流水线中使用了 **12 种自动化安全工具**。 ### 安全认证与合规性 | 认证 | 状态 | 徽章 | |--------------|--------|-------| | **OpenSSF 记分卡** | 7+ / 10 | [![OpenSSF 记分卡](https://img.shields.io/ossf-scorecard/github.com/itcmsgr/nftban)](https://securityscorecards.dev/viewer/?uri=github.com/itcmsgr/nftban) | | **OpenSSF 最佳实践** | 通过 | [![CII 最佳实践](https://www.bestpractices.dev/projects/11959/badge)](https://www.bestpractices.dev/projects/11959) | | **SLSA Level 3** | 来源证明 | [![SLSA 3](https://slsa.dev/images/gh-badge-level3.svg)](https://slsa.dev) | | **SBOM** | 每次发布 | SPDX-JSON 格式 | ### 自动化安全流水线
类别工具目的频率
SASTCodeQLGo 语义代码分析每次 PR + Push
Semgrep基于模式的安全规则 (Go + Shell)每次 PR + Push
gosecGo 专属安全 linting每次 PR + Push
ShellCheckShell 脚本安全分析每次 PR + Push
SCAgovulncheckGo 模块漏洞扫描每次 PR + Push
OSV-ScannerGoogle OSV 数据库扫描每次 PR + 每周
Trivy容器及依赖 CVE 扫描每次 PR + Push
机密gitleaks提交中的机密检测每次 PR + Push
GitHub 机密扫描已知机密模式检测持续
供应链SLSA 来源证明加密构建证明每次发布
依赖审查PR 级别的依赖差异分析每次 PR
模糊测试go-fuzz自动化模糊测试每晚
### 供应链安全 ``` Source → Build → Attest → Release → Verify ↓ ↓ ↓ ↓ ↓ Git Hermetic SLSA L3 SBOM sigstore ``` - **SLSA Level 3**: 具有不可伪造来源证明的密闭构建 - **SBOM**: 每次发布均提供完整的软件物料清单 (SPDX-JSON) - **签名发布**: GPG 签名的标签和制品 - **固定的依赖项**: 所有 GitHub Actions 均固定到 SHA ### 安全仪表盘 | 仪表盘 | 描述 | |-----------|-------------| | [安全概览](https://github.com/itcmsgr/nftban/security) | 所有安全功能 | | [代码扫描](https://github.com/itcmsgr/nftban/security/code-scanning) | SAST 结果 | | [Dependabot](https://github.com/itcmsgr/nftban/security/dependabot) | 依赖项 CVE 警报 | | [机密扫描](https://github.com/itcmsgr/nftban/security/secret-scanning) | 凭证泄露检测 | | [OpenSSF 记分卡](https://securityscorecards.dev/viewer/?uri=github.com/itcmsgr/nftban) | 安全健康评分 (7+/10) | | [工作流状态](https://github.com/itcmsgr/nftban/actions) | CI/CD 流水线状态 | ### 漏洞披露 我们遵循 **协同披露** 原则,修复窗口期为 90 天。请将漏洞报告至: - **邮箱**: security@nftban.com - **GitHub 安全公告**: [报告漏洞](https://github.com/itcmsgr/nftban/security/advisories/new) 完整的安全策略、威胁模型和架构请参见 [SECURITY.md](SECURITY.md)。 ## 文档 ### 入门指南 - [Wiki 首页](https://github.com/itcmsgr/nftban/wiki) — 完整文档 - [CLI 命令参考](https://github.com/itcmsgr/nftban/wiki/CLI-Commands-Reference) — 所有命令 - [安装指南](https://github.com/itcmsgr/nftban/wiki/Installation-Guide) — 前置条件、安装、安装后配置 ### 架构与安全 - [架构](docs/ARCHITECTURE.md) — 系统设计与数据流 - [威胁模型](docs/THREAT_MODEL.md) — 资产、对手、攻击面 - [安全策略](SECURITY.md) — 漏洞报告、权限模型 - [可复现构建](docs/REPRODUCIBLE_BUILDS.md) — 构建验证 ### 集成 - [Suricata IDS](https://github.com/itcmsgr/nftban/wiki/Suricata-IDS-Integration) — IDS/IPS 设置 - [控制面板](https://github.com/itcmsgr/nftban/wiki/Panel-Integration) — cPanel, DirectAdmin, Plesk ### 社区 - 网站: https://nftban.com - [报告 Bug](https://github.com/itcmsgr/nftban/issues) - [讨论区](https://github.com/itcmsgr/nftban/discussions)

NFTBan — Linux IPS 与 nftables 防火墙管理器
nftban.com | 报告问题 | 讨论区

标签:DNS解析, Docker, FHS合规, Golang, Go语言, IPS, Metaprompt, nftables, PB级数据处理, SBOM, Shell, SLSA, SPDX, TLS, 入侵防御系统, 威胁检测与响应, 威胁猎捕, 子域名枚举, 安全栈, 安全编程, 安全运维, 安全防御评估, 应用安全, 开源项目, 插件系统, 无线安全, 日志审计, 硬件无关, 程序破解, 系统安全, 网络安全, 请求拦截, 防御工具, 防火墙管理, 隐私保护