tiredvpn/tiredvpn

GitHub: tiredvpn/tiredvpn

一款采用自适应策略引擎、内置二十余种绕过手段的抗 DPI 审查 VPN 工具,支持会话期间的策略自动探测与无缝回退。

Stars: 34 | Forks: 1

# TiredVPN [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/tiredvpn/tiredvpn/actions/workflows/ci.yml) [![Release](https://img.shields.io/github/v/release/tiredvpn/tiredvpn)](https://github.com/tiredvpn/tiredvpn/releases/latest) [![Docker Pulls](https://img.shields.io/docker/pulls/tiredvpn/tiredvpn)](https://hub.docker.com/r/tiredvpn/tiredvpn) [![Go Report Card](https://goreportcard.com/badge/github.com/tiredvpn/tiredvpn)](https://goreportcard.com/report/github.com/tiredvpn/tiredvpn) [![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](LICENSE) [![Go Version](https://img.shields.io/github/go-mod/go-version/tiredvpn/tiredvpn)](go.mod) ![TiredVPN](https://static.pigsec.cn/wp-content/uploads/repos/cas/dc/dc4e151daf3cc0bf57a1dd7165b549470ebb5f1f868c995afd00aa25744911de.png) **相关仓库:** [tiredvpn/tiredvpn-android](https://github.com/tiredvpn/tiredvpn-android) — Android 客户端 ## 什么是 TiredVPN? TiredVPN 是一款抗审查的 VPN,它采用多种绕过策略,在存在深度包检测 (DPI) 的网络环境中建立并维持连接。它不依赖单一的混淆技术,而是实现了一个自适应策略引擎,能够根据当前的网络状况自动选择最佳的传输方式。 该系统会探测可用的策略,按延迟和可靠性对它们进行排名,如果当前使用的策略被封锁,则会在会话期间切换到备用方案。这使其能够有效应对复杂的过滤系统,如 TSPU(俄罗斯)、GFW(中国)以及类似的 DPI 基础设施。 主要设计目标: - **高弹性** - 没有单点故障;如果某一策略被封锁,客户端会无缝切换到另一策略。 - **隐蔽性** - 流量模式经过伪装,使其类似于合法服务(视频流媒体、CDN 流量、HTTPS 浏览)。 - **高性能** - 通过 smux 进行多路复用、QUIC 传输以及自适应 RTT 掩盖,将开销降至最低。 ## 功能 - **20 多种 DPI 绕过策略**,支持自动选择和会话期间切换 - **QUIC 和 TLS 传输**,带有 Salamander 填充和 SNI 碎片化 - **REALITY 协议** - 以近乎完美的 TLS 指纹模拟合法网站 - **HTTP/2 隐写术** - 将隧道数据隐藏在真实的 HTTP/2 帧中 - **流量伪装** - 在统计特征上与热门服务的流量模式相匹配 - **Geneva 引擎** - 特定国家的数据包操作规则(俄罗斯、中国、伊朗、土耳其) - **基于 smux 的多路复用连接**,用于高效的流管理 - **TUN 模式**,用于全系统流量隧道传输 - **SOCKS5 和 HTTP 代理** 模式 - **端口跳跃**,支持随机、顺序和斐波那契策略 - **IPv6 传输**,支持双栈和自动回退 - **加密客户端问候 (ECH)**,向 DPI 隐藏 SNI - **后量子密码学** (ML-KEM-768 + ML-DSA-65) - **多跳路由**,通过链式服务器传输 - **Prometheus 兼容的指标**端点 - **Android 集成**,通过 JNI(c-shared 构建模式) - **Docker 支持**,使用多阶段构建 - **客户端管理**,配备 Redis 后端和 REST API - **二维码生成**,用于移动客户端配置 ## TiredVPN 对比 | 功能 | TiredVPN | Xray/VLESS | sing-box | Outline | |---------|----------|------------|----------|---------| | 绕过策略 | 20+ | 3–5 | 5–8 | 1–2 | | 自适应回退 | ✅ 会话期间 | ❌ | 部分 | ❌ | | TSPU 研究 | [每日报告](https://github.com/tiredvpn/tiredvpn-measurements) | ❌ | ❌ | ❌ | | 后量子加密 | ✅ ML-KEM-768 | ❌ | ❌ | ❌ | | Geneva 引擎 | ✅ | ❌ | ❌ | ❌ | | RTT 掩盖 | ✅ | ❌ | ❌ | ❌ | | ICMP 回退 | ✅ | ❌ | ❌ | ❌ | | 流量伪装 | ✅ | ❌ | ❌ | ❌ | | Android 应用 | ✅ 原生 | 第三方 | 第三方 | ✅ | | 开源协议 | AGPL-3.0 | MPL-2.0 | GPL-3.0 | Apache-2.0 | ## 快速开始 ### 安装 #### 一行命令安装(推荐) ``` curl -fsSL https://tiredvpn.github.io/tiredvpn/install.sh | sudo bash -s -- --port 443 ``` 这会安装服务端,生成密钥和 TLS 证书,启动服务,并打印连接字符串以及供移动应用使用的二维码。可以使用 `--port N` 选择不同的端口(默认为 443)。 #### Debian/Ubuntu (apt) ``` curl -fsSL https://tiredvpn.github.io/tiredvpn/gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/tiredvpn-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/tiredvpn-archive-keyring.gpg] https://tiredvpn.github.io/tiredvpn/apt stable main" | sudo tee /etc/apt/sources.list.d/tiredvpn.list sudo apt update && sudo apt install tiredvpn sudo tiredvpn-init # generates secret/cert, prints keys, starts the service ``` #### Fedora/RHEL (dnf) ``` sudo tee /etc/yum.repos.d/tiredvpn.repo >/dev/null <<'EOF' [tiredvpn] name=TiredVPN baseurl=https://tiredvpn.github.io/tiredvpn/rpm/$basearch enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://tiredvpn.github.io/tiredvpn/gpg.key EOF sudo dnf install tiredvpn && sudo tiredvpn-init ``` apt 和 dnf 包在安装时默认处于**禁用**状态 —— 它们仅安装了二进制文件,但不会启动。请运行 `sudo tiredvpn-init` 来完成设置:它会生成密钥和证书,打印访问密钥,并启动服务。一行命令安装脚本和 `install.sh` 已经为您做好了这些。 #### 手动下载二进制文件 对于其他发行版或没有 systemd 的主机,请直接下载二进制文件: ``` curl -LO https://github.com/tiredvpn/tiredvpn/releases/latest/download/tiredvpn-linux-amd64.tar.gz tar xzf tiredvpn-linux-amd64.tar.gz sudo mv tiredvpn-linux-amd64 /usr/local/bin/tiredvpn ``` 可用平台:`linux-amd64`、`linux-arm64`。其他安装方法将在下方的 [Docker](#docker) 和[从源码构建](#building-from-source) 章节中说明。 通过 Helm 部署 Kubernetes(在单一发布版中包含服务端和/或客户端): ``` helm install my-tiredvpn oci://ghcr.io/tiredvpn/charts/tiredvpn --version 0.1.0 \ -f my-values.yaml ``` 有关配置值、示例以及 TLS/认证/Redis/HPA 选项,请参见 [deploy/helm/tiredvpn/README.md](deploy/helm/tiredvpn/README.md)。 ### 生成共享密钥 ``` openssl rand -hex 32 ``` ### 生成 TLS 证书 用于测试时,请创建自签名证书: ``` openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 \ -days 365 -nodes -keyout server.key -out server.crt \ -subj "/CN=your-server.com" ``` 在生产环境中,请使用 [Let's Encrypt](https://letsencrypt.org/) 和 certbot: ``` sudo certbot certonly --standalone -d your-server.com # 证书将位于: # /etc/letsencrypt/live/your-server.com/fullchain.pem # /etc/letsencrypt/live/your-server.com/privkey.pem ``` ### 服务端 ``` tiredvpn server \ -listen :443 \ -cert server.crt \ -key server.key \ -secret ``` 服务端默认同时监听 TCP (TLS) 和 UDP (QUIC)。它向未经身份验证的访问者提供虚假网站,使其与普通的 HTTPS 服务器无异。 ### 服务端防火墙和转发(TUN 模式必需) **如果您使用 TUN 模式(`-tun` / `-ip-pool`),您必须自行在服务器主机上启用 IP 转发和 NAT。** TiredVPN 不会主动修改您的防火墙或路由表。否则,TUN 客户端虽然可以连接并且服务端会记录 `TUN mode established`,但不会有任何流量通过 —— 客户端的数据包到达服务端的 TUN 接口后无处可去。(SOCKS5 代理模式不受此影响:服务端进程会自行将流量发出。) ``` # 1) 启用 IP forwarding(并将其持久化) sysctl -w net.ipv4.ip_forward=1 echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf # 2) 将 client pool 通过您的 uplink interface 进行 NAT。 # 使用以下命令查找 uplink:ip route get 1.1.1.1 (即 "dev " 部分) iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o -j MASQUERADE # 3) 仅当您的 FORWARD policy 为 DROP 时(检查:iptables -S FORWARD | head -1) iptables -A FORWARD -s 10.8.0.0/24 -j ACCEPT iptables -A FORWARD -d 10.8.0.0/24 -j ACCEPT ``` 将 `10.8.0.0/24` 替换为您的 `-ip-pool` CIDR,将 `` 替换为您实际的上行链路接口(例如 `eth0`、`enp1s0`)。对于 IPv6 地址池,请使用 `ip6tables` 和 `net.ipv6.conf.all.forwarding=1` 镜像这些规则。如果您愿意,也可以使用防火墙管理器(nftables、ufw、firewalld)—— 要求都是相同的:转发并 NAT 该地址池。 ### 客户端(SOCKS5 代理) ``` tiredvpn client \ -server your-server.com:443 \ -secret \ -listen 127.0.0.1:1080 ``` 这将在 1080 端口启动一个本地 SOCKS5 代理。将您的浏览器或应用程序指向 `socks5://127.0.0.1:1080`。 ### 客户端(完整 VPN / TUN 模式) ``` sudo tiredvpn client \ -server your-server.com:443 \ -secret \ -tun \ -tun-routes 0.0.0.0/0 ``` 这将创建一个 TUN 接口,并通过 VPN 路由所有流量。 ## 配置 TiredVPN 完全通过 CLI 标志进行配置。运行 `tiredvpn server -help` 或 `tiredvpn client -help` 查看完整列表。 ### 服务端标志 | 标志 | 默认值 | 描述 | |------|---------|-------------| | `-listen` | `:443` | IPv4 监听地址 | | `-listen-v6` | `[::]:995` | IPv6 监听地址 | | `-cert` | `server.crt` | TLS 证书文件 | | `-key` | `server.key` | TLS 私钥文件 | | `-secret` | | 共享密钥(单客户端模式) | | `-redis` | | 用于多客户端模式的 Redis 地址 | | `-api-addr` | `127.0.0.1:8080` | 用于客户端管理的 REST API | | `-ip-pool` | | 用于 TUN 客户端 IP 分配的 CIDR | | `-tun-mtu` | `1280` | TUN 接口 MTU (1280-9000) | | `-port-range` | | 多端口监听(例如 `47000-47100`) | | `-no-quic` | `false` | 禁用 QUIC/UDP 监听器 | | `-upstream` | | 用于多跳的上游服务器 | | `-fake-root` | `./www` | 向未经身份验证的访问者提供的目录 | | `-enable-icmp` | `false` | 启用 ICMP 隧道监听器(需要 CAP_NET_RAW) | | `-debug` | `false` | 启用详细日志记录 | ### 客户端标志 | 标志 | 默认值 | 描述 | |------|---------|-------------| | `-server` | | 远程服务器地址(必填) | | `-secret` | | 共享密钥(必填) | | `-listen` | `127.0.0.1:1080` | 本地 SOCKS5/HTTP 代理地址 | | `-tun` | `false` | 启用 TUN 模式(完整 VPN) | | `-tun-routes` | | 要通过隧道传输的路由(例如 `0.0.0.0/0`) | | `-quic` | `false` | 启用 QUIC 传输 | | `-strategy` | | 强制使用特定策略 | | `-port-hop` | `false` | 启用端口跳跃 | | `-ech` | `false` | 启用加密客户端问候 | | `-pq` | `false` | 启用后量子加密 | | `-rtt-masking` | `false` | 隐藏代理时间签名 | | `-prefer-ipv6` | `true` | 优先使用 IPv6 传输 | | `-fallback` | `true` | 会话期间策略回退 | | `-benchmark` | `false` | 运行策略延迟基准测试 | ### 客户端管理 ``` # 添加 client(使用 Redis 的 multi-client 模式) tiredvpn admin add -api http://127.0.0.1:8080 -server vpn.example.com:443 # 列出 client tiredvpn admin list -api http://127.0.0.1:8080 # 删除 client tiredvpn admin delete -api http://127.0.0.1:8080 -id # 为移动应用生成 QR code tiredvpn admin qr -server vpn.example.com:443 -secret ``` ## Docker 预构建的镜像可在 Docker Hub 上获取。支持平台:`linux/amd64`、`linux/arm64`。 | 标签 | 描述 | |-----|-------------| | `latest` | 最新稳定发布版本 | | `1.3.3` | 固定版本 | | `edge` | 最新 main 分支构建版本 | ### 运行服务端 ``` docker run -d \ --name tiredvpn-server \ -p 443:443/tcp \ -p 443:443/udp \ -v /path/to/certs:/certs:ro \ tiredvpn/tiredvpn:latest \ server -listen :443 \ -cert /certs/server.crt \ -key /certs/server.key \ -secret ``` ### Docker Compose ``` curl -O https://raw.githubusercontent.com/tiredvpn/tiredvpn/main/docker-compose.yml TIREDVPN_SECRET= docker compose up -d ``` 或者使用自定义的 `docker-compose.yml`: ``` version: "3.8" services: tiredvpn-server: image: tiredvpn/tiredvpn:latest ports: - "443:443/tcp" - "443:443/udp" volumes: - ./certs:/certs:ro command: - "server" - "-listen" - ":443" - "-cert" - "/certs/server.crt" - "-key" - "/certs/server.key" - "-secret" - "${TIREDVPN_SECRET}" - "-redis" - "redis:6379" depends_on: - redis restart: unless-stopped redis: image: redis:7-alpine volumes: - redis-data:/data restart: unless-stopped volumes: redis-data: ``` ### 本地构建 ``` docker build -t tiredvpn . ``` ### 容器中的 TUN 模式 默认镜像是一个干净的代理构建版本,不包含 `iptables`,因此服务端的 TUN(`-ip-pool`)在其中无法工作。要进行完整的 TUN 隧道传输,请使用 `tun` 构建目标(`tiredvpn:tun`),它需要 `/dev/net/tun`、`NET_ADMIN` 权限以及可写的 `net.ipv4.ip_forward` 配置;它的 entrypoint 会自动为您设置 NAT。这也适用于通过 Helm 部署时的 `server.tun.enabled`。完整的 docker run / compose / Helm 配置见 [docs/deployment.md → 容器中的 TUN 模式](docs/deployment.md#tun-mode-in-containers)。 ## 从源码构建 ### 要求 - Go 1.26 或更高版本 - Linux、macOS 或 Windows(TUN 模式需要 Linux) ### 构建 ``` git clone https://github.com/tiredvpn/tiredvpn.git cd tiredvpn make build ``` 或直接使用 Go: ``` go build -o tiredvpn ./cmd/tiredvpn/ ``` ### 交叉编译 Linux (amd64) ``` make build-linux ``` ### 交叉编译 Android (arm64) ``` make build-android ``` ### 运行测试 ``` make test ``` ## 策略 TiredVPN 包含一个自适应策略引擎,可自动选择最佳传输方式。每种策略都针对 DPI 规避的不同方面。 | ID | 名称 | 描述 | |----|------|-------------| | `quic_salamander` | QUIC Salamander | 基于 UDP 的 QUIC,带有 Salamander 填充(默认启用,最难被指纹识别) | |quic` | QUIC 隧道 | 带有版本欺骗的 QUIC 传输(draft-29 以绕过 TSPU) | | `reality` | REALITY 协议 | 使用真实的 TLS 指纹模拟合法网站 | | `http2_stego` | HTTP/2 隐写术 | 将数据隐藏在 HTTP/2 帧中,使用 NaiveProxy 风格的填充 | | `websocket_padded` | WebSocket Salamander | 带有 Salamander 混淆填充的 WebSocket 传输 | | `http_polling` | HTTP 轮询 | 短暂的 HTTP/1.1 请求(类似 meek),规避长连接检测 | | `morph_*` | 流量伪装 | 重塑流量以匹配视频流媒体特征(如 Yandex、VK) | | `confusion_*` | 协议混淆 | 使数据包看起来像基于 TLS 的 DNS/HTTP/SSH/SMTP | | `geneva_*` | Geneva 引擎 | 特定国家的数据包操作(俄罗斯 TSPU、中国 GFW、伊朗、土耳其) | | `antiprobe` | 防探测 | 服务端伪装为普通网站;仅向通过认证的客户端显示隧道 | | `state_exhaustion` | 状态耗尽 | 用诱饵淹没 DPI 状态表以触发其开放失败(fail-open)模式 | | `mesh_relay` | 网状中继 | 通过过滤较轻地区的节点进行中继路由 | | `icmp_tunnel` | ICMP 隧道 | 基于 ICMP Echo 的备用隧道(隐蔽模式,需要 CAP_NET_RAW) | | `ssh_camouflage` | SSH 伪装 | 在 SSH 流量下建立隧道(优先级 28,需要服务端支持) | | `imap_camouflage` | IMAP 伪装 | 在 IMAP 邮件协议下建立隧道(优先级 29,需要服务端支持) | 策略引擎支持: - **自动探测** - 测试所有可用策略并按延迟排名 - **熔断机制** - 在达到可配置的失败阈值后禁用相应策略 - **会话期间切换** - 在不断开连接的情况下切换策略 - **定期重新探测** - 在定时器上重新评估被封锁的策略 - **基准测试** - 使用 `tiredvpn client -benchmark` 测试所有策略 ## 架构 ``` cmd/tiredvpn/ CLI entrypoint (server, client, admin) internal/ server/ Server-side connection handling, TLS/QUIC listeners client/ Client-side proxy, TUN, strategy orchestration strategy/ DPI bypass strategies and adaptive engine tun/ TUN device management mux/ smux multiplexer integration tunnel/ Tunnel abstractions proxy/ SOCKS5 and HTTP proxy tls/ TLS utilities and uTLS fingerprinting evasion/ Low-level evasion primitives geneva/ Geneva packet manipulation engine porthopping/ Port hopping logic multiport/ Multi-port listener pool/ IP address pool for TUN clients metrics/ Prometheus metrics collector padding/ Traffic padding utilities protect/ Android VpnService socket protection control/ Android control socket protocol config/ Configuration types log/ Structured logging benchmark/ Strategy benchmarking ktls/ Kernel TLS offload ``` ## 文档 完整文档可在 [docs/](docs/) 目录中找到: - [入门指南](docs/getting-started.md) - [服务端参考](docs/server.md) - [客户端参考](docs/client.md) - [DPI 绕过策略](docs/strategies.md) - [部署指南](docs/deployment.md) - [安全模型](docs/security.md) - [监控](docs/monitoring.md) ## 贡献 欢迎各种贡献。请查阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解关于提交补丁、报告问题以及开发工作流的指南。 在提交 pull request 之前: 1. 运行 `make test` 并确保所有测试通过 2. 如果您安装了 golangci-lint,请运行 `make lint` 3. 保持提交内容聚焦且描述清晰 ## 社区 - [GitHub Discussions](https://github.com/tiredvpn/tiredvpn/discussions) — 功能想法、问答交流 ## 许可证 TiredVPN 采用 [GNU Affero General Public License v3.0](LICENSE) 授权。 ## Star 历史 [![Star History Chart](https://api.star-history.com/svg?repos=tiredvpn/tiredvpn&type=Date)](https://star-history.com/#tiredvpn/tiredvpn&Date)
标签:Android, DPI绕过, DSL, EVTX分析, Go语言, VPN, 底层编程, 抗审查, 搜索引擎查询, 日志审计, 流量混淆, 程序破解, 网络通信, 自定义请求头, 请求拦截