使用 rust 实现的飞连客户端
使用 rust 实现的 飞连 客户端,支持 Linux/Windows10/MacOS
下载 release 中的安装包,并安装
pacman -U corplink-rs-4.1-1-x86_64.pkg.tar.zst
欢迎贡献其它包管理器的打包脚本
git clone https://github.com/PinkD/corplink-rs --depth 1
cd corplink-rs
# build libwg
cd libwg
./build.sh
# if you are using Windows, you can clone and build libwg maunally
# ref: wireguard-go/Makefile:libwg
cargo build --release
# install corplink-rs to your PATH
mv target/release/corplink-rs /usr/bin/
前提: 需要 Go (≥1.22)、GCC (MinGW-w64)、make、Rust (GNU 工具链)。
安装工具链后,在 PowerShell 中执行:
# 1. 构建 libwg(生成 libwg.a + libwg.h)
cd libwg
.\build.ps1
# 2. 构建 Rust 项目
cd ..
rustup toolchain install stable-gnu
rustup default stable-x86_64-pc-windows-gnu
cargo build --release
编译的
build.ps1会调用make libwg,该目标会以CGO_ENABLED=1编译 Go 代码。 MinGW GCC 需要在 PATH 中,且 make 需要支持 bash 风格环境变量语法。 也可在 MSYS2 UCRT64 环境中执行./build.sh(同样需要 Go + GCC)。
该程序需要 root 权限来启动
wg-go(windows 上需要管理员权限)
# direct
corplink-rs config.json
# systemd
# config is /etc/corplink/config.json
systemctl start corplink-rs.service
# auto start
systemctl enable corplink-rs.service
# systemd with custom config
# config is /etc/corplink/test.json
# NOTE: cookies.json is reserved by cookie storage
systemctl start [email protected]
corplink-rs-*-windows.zipsetup.ps1 自动获取 wintun.dll:powershell -ExecutionPolicy Bypass -File setup.ps1
config.json,填入公司代码和登录信息(见下方配置文件实例).\corplink-rs.exe config.json
# 调试模式
$env:RUST_LOG="debug"; .\corplink-rs.exe config.json
corplink-rs 依赖 Wintun 虚拟网卡驱动来创建 WireGuard 隧道。由于 Wintun 的许可证要求用户从官网直接获取,我们无法在 release 包中附带该文件。
setup.ps1 脚本会自动从 wintun.net 下载并解压 amd64 版本的 wintun.dll 到当前目录。
手动获取:访问 wintun.net,下载 zip 包,将 bin/amd64/wintun.dll 复制到 corplink-rs.exe 所在目录。
程序需要管理员权限,原因:
wg-go 需要创建 TUN 虚拟网卡如果运行时提示 please run as administrator,右键 PowerShell 选择"以管理员身份运行"。
setup.ps1 或手动下载放入同目录// comment 需要删除macos 要求 tun 设备的名称满足正则表达式 utun[0-9]* ,因此需要将配置文件中的 interface_name 改为符合正则的名字,例如 utun12345
另外, utun 后的数字类型应该是 int16 ,如果大于 32767 会报错 Failed to create TUN device: invalid argument 。具体参考 #46
本项目使用 env_logger 作为 log 库,修改 log level 需要使用环境变量,示例:
RUST_LOG=debug ./corplink-rs config.json
最小配置
{
"company_name": "company code name",
"username": "your_name"
}
推荐配置(自用配置)
{
"company_name": "company code name",
"username": "your_name",
"password": "your_pass",
"platform": "ldap"
}
完整配置
…
设置 socks5_listen 后,corplink-rs 不再创建内核 TUN 网卡,而是用 wg-go 的 gVisor netstack 在用户态跑 WireGuard,并在该地址上暴露一个 SOCKS5 代理:
CONNECT 和 UDP ASSOCIATE,域名在隧道内解析(用 --socks5-hostname 让客户端把 DNS 也交给代理)socks5_username(及 socks5_password)即开启;留空则免认证# 例:通过代理访问内网
curl --socks5-hostname user:[email protected]:1080 https://intranet.example.com/
此模式下 interface_name、use_vpn_dns、auto_setup_routes 等与系统网卡/路由相关的设置不生效。
魔改了配置的方式,加了鉴权
猜测是:
因此,我们只需要生成 wg 的 key ,然后去找服务端拿配置,然后写到 wg 配置里,启动 wg ,就能连上服务端了
2.0.9 版本(或者更早)新增了 protocol_version 字段,需要使用魔改后的 wg-corplink 才能连接
graph TD;
A[Password Login];
B[Request Email Code];
C[Email Login];
D[Verify 2-FA];
E[List VPN];
F[Ping VPN];
G[Connect VPN];
A-->D;
B-->C-->D;
D-->E-->F-->G;
graph TD;
A[Password Login];
B[Request Email Code];
C[Email Login];
D[List VPN];
E[Ping VPN];
F[Connect VPN With 2-FA Code];
A-->D;
B-->C;
C-->D-->E-->F;
飞连的 otp 是使用的标准的 totp ,在 ua 为 Android 时,会在登录时返回 totp 的 token ,然后使用 totp 算法就能生成出当前时间的验证码了,然后在获取连接信息时传输该验证码,就不需要单独验证验证码了
cookies.jsonanyhowcookies.jsonprotocol_versionconf_name/conf_dir and add interface_name/wg_binary in config…
No open issues yet, or sync has not completed.