一种高速隐蔽隧道,将 TCP 流量伪装成 SMTP 电子邮件通信,以绕过深度包检测 (DPI) 防火墙。
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌──────────────┐
│ 应用程序 │─────▶│ 客户端 │─────▶│ 服务器 │─────▶│ 互联网 │
│ (浏览器) │ TCP │ SOCKS5:1080 │ SMTP │ 端口 587 │ TCP │ │
│ │◀─────│ │◀─────│ │◀─────│ │
└─────────────┘ └─────────────┘ └─────────────┘ └──────────────┘
│ │
│ 看上去像 │
│ 电子邮件流量 │
▼ ▼
┌────────────────────────────────┐
│ DPI 防火墙 │
│ ✅ 看到:正常 SMTP 会话 │
│ ❌ 无法看到:隧道数据 │
└────────────────────────────────┘
| 功能 | 描述 |
|---|---|
| 🔒 TLS 加密 | 所有流量在 STARTTLS 后使用 TLS 1.2+ 加密 |
| 🎭 DPI 绕过 | 初始握手模仿真实 SMTP 服务器(Postfix) |
| ⚡ 高速传输 | 握手后采用二进制流协议 - 极低开销 |
| 👥 多用户 | 每个用户独立密钥、IP 白名单和日志设置 |
| 🔑 身份验证 | 基于预共享密钥的 HMAC-SHA256 认证 |
| 🌐 SOCKS5 代理 | 标准代理接口 - 适用于任何应用程序 |
| 📡 多路复用 | 单隧道内支持多个连接 |
| 🛡️ IP 白名单 | 按 IP 地址/CIDR 对用户进行访问控制 |
| 📦 易安装 | 一键服务器安装,集成 systemd 服务 |
| 🎁 客户端包 | 自动为每个用户生成 ZIP 文件 |
| 🔄 自动重连 | 客户端在连接丢失时自动重新连接 |
📚 如需了解详细技术细节、协议规范和安全分析,请参阅 TECHNICAL.md。
获取一个指向你 VPS 的免费域名:
示例:myserver.duckdns.org → 203.0.113.50(你的 VPS IP)
curl -sSL https://raw.githubusercontent.com/x011/smtp-tunnel-proxy/main/install.sh | sudo bash
安装程序将:
完成! 你的服务器已就绪。
smtp-tunnel-adduser bob # 添加用户并生成客户端 ZIP
smtp-tunnel-listusers # 列出所有用户
smtp-tunnel-deluser bob # 删除用户
smtp-tunnel-update # 更新代码,保留配置/证书/用户
username.zip 文件| 平台 | 运行方法 |
|---|---|
| 🪟 Windows | 双击 start.bat |
| 🐧 Linux |
启动器将自动安装依赖并启动客户端。
✅ 你应该看到:
SMTP Tunnel Proxy Client
User: alice
[INFO] Starting SMTP Tunnel...
[INFO] SOCKS5 proxy will be available at 127.0.0.1:1080
Connecting to myserver.duckdns.org:587
Connected - binary mode active
SOCKS5 proxy on 127.0.0.1:1080
cd alice
pip install -r requirements.txt
python client.py
# 下载文件
scp [email protected]:/etc/smtp-tunnel/ca.crt .
# 创建 config.yaml:
cat > config.yaml << EOF
client:
server_host: "myserver.duckdns.org"
server_port: 587
socks_port: 1080
username: "alice"
secret: "your-secret-from-admin"
ca_cert: "ca.crt"
EOF
# 运行客户端
python client.py -c config.yaml
将 SOCKS5 代理设置为:127.0.0.1:1080
127.0.0.1,端口:1080127.0.0.1:1080设置 → 网络和 Internet → 代理 → 手动设置 → socks=127.0.0.1:1080
系统偏好设置 → 网络 → 高级 → 代理 → SOCKS 代理 → 127.0.0.1:1080
export ALL_PROXY=socks5://127.0.0.1:1080
# curl
curl -x socks5h://127.0.0.1:1080 https://ifconfig.me
# git
git config --global http.proxy socks5://127.0.0.1:1080
# 环境变量
export ALL_PROXY=socks5://127.0.0.1:1080
# 应该显示你的 VPS IP
curl -x socks5://127.0.0.1:1080 https://ifconfig.me
config.yaml)users.yaml)每个用户可设置独立参数:
users:
alice:
secret: "auto-generated-secret"
# whitelist: # 可选:限制为特定 IP
# - "192.168.1.100"
# - "10.0.0.0/8" # 支持 CIDR 表示法
# logging: true # 可选:禁用可停止记录该用户日志
bob:
secret: "another-secret"
whitelist:
- "203.0.113.50" # Bob 只能从此 IP 连接
logging: false # 不记录 Bob 的活动
| 选项 | 描述 | 默认值 |
|---|---|---|
secret | 用户的认证密钥 | 必填 |
# 查看状态
sudo systemctl status smtp-tunnel
# 配置更改后重启
sudo systemctl restart smtp-tunnel
# 查看日志
sudo journalctl -u smtp-tunnel -n 100
# 卸载
sudo /opt/smtp-tunnel/uninstall.sh
python server.py [-c CONFIG] [-d]
-c, --config 配置文件(默认:config.yaml)
-d, --debug 启用调试日志
python client.py [-c CONFIG] [--server HOST] [--server-port PORT]
[-p SOCKS_PORT] [-u USERNAME] [-s SECRET] [--ca-cert FILE] [-d]
-c, --config 配置文件(默认:config.yaml)
--server 覆盖服务器域名
--server-port 覆盖服务器端口
-p, --socks-port 覆盖本地 SOCKS 端口
-u, --username 你的用户名
-s, --secret 覆盖密钥
--ca-cert CA 证书路径
-d, --debug 启用调试日志
smtp-tunnel-adduser <用户名> [-u USERS_FILE] [-c CONFIG] [--no-zip]
添加新用户并生成客户端包
smtp-tunnel-deluser <用户名> [-u USERS_FILE] [-f]
删除用户(使用 -f 跳过确认)
smtp-tunnel-listusers [-u USERS_FILE] [-v]
列出所有用户(使用 -v 查看详细信息)
smtp-tunnel-update
将服务器更新到最新版本(保留配置/证书/用户)
smtp_proxy/
├── 📄 server.py # 服务器(运行在 VPS)
├── 📄 client.py # 客户端(本地运行)
├── 📄 common.py # 共享工具
├── 📄 generate_certs.py # 证书生成器
├── 📄 config.yaml # 服务器/客户端配置
├── 📄 users.yaml # 用户数据库
├── 📄 requirements.txt # Python 依赖
├── 📄 install.sh # 一键服务器安装
├── 📄 smtp-tunnel.service # Systemd 单元文件
├── 🔧 smtp-tunnel-adduser # 添加用户脚本
├── 🔧 smtp-tunnel-deluser # 删除用户脚本
├── 🔧 smtp-tunnel-listusers # 列出用户脚本
├── 🔧 smtp-tunnel-update # 更新服务器脚本
├── 📄 README.md # 本文件
└── 📄 TECHNICAL.md # 技术文档
/opt/smtp-tunnel/ # 应用程序文件
/etc/smtp-tunnel/ # 配置文件
├── config.yaml
├── users.yaml
├── server.crt
├── server.key
└── ca.crt
/usr/local/bin/ # 管理命令
├── smtp-tunnel-adduser
├── smtp-tunnel-deluser
├── smtp-tunnel-listusers
└── smtp-tunnel-update
systemctl status smtp-tunnel 或 ps aux | grep server.pynetstat -tlnp | grep 587ufw statususername 和 secret 是否与 users.yaml 中的匹配smtp-tunnel-listusers -v 确认用户存在10.0.0.0/8)server_host 与证书主机名一致ca.crt 文件# 启用详细日志
python server.py -d
python client.py -d
# 查看 systemd 日志
journalctl -u smtp-tunnel -f
ca_cert,以防止中间人攻击smtp-tunnel-adduser 自动生成强密钥users.yaml - 包含所有用户密钥(chmod 600)logging: false)📚 有关详细的安全分析和威胁模型,请参阅 TECHNICAL.md。
本项目仅供教育和授权使用。请负责任地使用,并遵守适用法律。
本工具专为合法的隐私保护和审查规避用途而设计。用户有责任确保其使用符合适用法律法规。
❤️ 为互联网自由而制作
运行 ./start.sh |
| 🍎 macOS | 运行 ./start.sh |
| 选项 | 描述 | 默认值 |
|---|
host | 监听接口 | 0.0.0.0 |
port | 监听端口 | 587 |
hostname | SMTP 主机名(必须与证书匹配) | mail.example.com |
cert_file | TLS 证书路径 | server.crt |
key_file | TLS 私钥路径 | server.key |
users_file | 用户配置文件路径 | users.yaml |
log_users | 全局日志记录设置 | true |
whitelist |
| 允许访问该用户的 IP(支持 CIDR) |
| 所有 IP |
logging | 是否记录该用户的活动 | true |
| 选项 | 描述 | 默认值 |
|---|
server_host | 服务器域名 | 必填 |
server_port | 服务器端口 | 587 |
socks_port | 本地 SOCKS5 端口 | 1080 |
socks_host | 本地 SOCKS5 接口 | 127.0.0.1 |
username | 你的用户名 | 必填 |
secret | 你的认证密钥 | 必填 |
ca_cert | 用于验证的 CA 证书 | 推荐 |