. 一个面向 Rust 的高级隐身 HTTP 客户端。
专为注重隐私的开发者打造,让你能够完全掌控自己的网络指纹。
看起来像浏览器。行为像浏览器。用 Rust 编写。
基于 bogdanfinn/tls-client 构建 —— 这是业界领先的 TLS 指纹库,受到全球安全专业人士的信赖。我们通过 FFI 绑定使用 bogdanfinn 久经考验的共享库(.dll/.so/.dylib),原因如下:
RustTLSX 以类型安全、人性化的 API 将这一成熟技术带入 Rust,其速度比 Python 替代方案快 6 倍。
现代 Web 应用会分析你 HTTP 请求的方方面面——不仅是请求头和 Cookie,还包括 TLS 握手的深层加密签名。标准 Rust HTTP 客户端(reqwest、hyper、ureq)会生成容易被检测的模式,从而立即识别出自动化流量。
RustTLSX 通过以下方式解决这一问题:
从 tls-client releases 下载适用于你平台所需的 TLS 客户端库:
tls-client-windows-64-1.3.3.dlltls-client-linux-ubuntu-amd64-1.3.3.sotls-client-darwin-amd64-1.3.3.dylib将库文件放在项目根目录、系统库路径(/usr/local/lib/)中,或确保可通过 PATH 访问。
将 RustTLSX 添加到你的 Cargo.toml:
[dependencies]
rust-tlsx = "0.1"
use rust_tlsx::{TlsClient, BrowserProfile};
fn main() -> anyhow::Result<()> {
let client = TlsClient::new(BrowserProfile::Firefox120)
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0")
.timeout(30);
let response = client.get("https://example.com")?;
println!("Status: {}", response.status);
println!("Body: {}", response.body);
Ok(())
}
RustTLSX 支持跨主流浏览器的 30 多种浏览器配置文件:
// Chrome versions
BrowserProfile::Chrome103
BrowserProfile::Chrome107
BrowserProfile::Chrome109
BrowserProfile::Chrome120
// Firefox versions
BrowserProfile::Firefox102
BrowserProfile::Firefox105
BrowserProfile::Firefox108
BrowserProfile::Firefox120
// Safari versions
BrowserProfile::Safari15_6_1
BrowserProfile::Safari16_0
BrowserProfile::SafariIos16_0
// Opera and others
BrowserProfile::Opera89
BrowserProfile::Opera90
let client = TlsClient::new(BrowserProfile::Chrome109)
.header("Accept", "application/json")
.header("Accept-Language", "en-US,en;q=0.9")
.cookie("session", "abc123")
.cookie("token", "xyz789");
let response = client.get("https://api.example.com")?;
let body = r#"{"username": "user", "password": "pass"}"#;
let response = client.post("https://example.com/login", Some(body.to_string()))?;
let client = TlsClient::new(BrowserProfile::Firefox120)
.timeout(60); // seconds
let response = client.get("https://slow-api.example.com")?;
RustTLSX 建立在久经验证的卓越基础之上,而不是重复造轮子。我们通过 FFI 使用 bogdanfinn 编译好的库(.dll/.so/.dylib),原因如下:
研究投入:Bogdanfinn 投入了数千小时逆向工程浏览器 TLS 行为。重复这项研究需要数年时间,而且很可能得到较差的结果。
久经考验的可靠性:这些库被全球主要安全公司、隐私工具和研究机构使用。它们已经过所有主要防护系统的测试。
持续演进:浏览器指纹不断变化。Bogdanfinn 的库会定期更新,以匹配新的浏览器版本和防护系统更新。
性能优化:原生 C/Go 实现对速度和内存效率进行了深度优化,提供了纯 Rust 实现无法企及的性能。
运行时动态加载:使用 FFI 按需加载库,消除了静态链接的复杂性,同时保持性能。
内存管理:Rust 的所有权模型确保了与原生库的安全交互,防止了 C/C++ 实现中常见的内存泄漏和释放后使用(use-after-free)错误。
错误处理:基于 Result 的全面错误处理在保持类型安全的同时提供详细的诊断信息。
连接管理:对 TLS 连接进行智能池化与复用,行为模式与浏览器一致。
底层库管理浏览器 TLS 行为的方方面面:
use rust_tlsx::{TlsClient, BrowserProfile};
fn main() -> anyhow::Result<()> {
let client = TlsClient::new(BrowserProfile::Chrome109);
let response = client.get("https://httpbin.org/get")?;
println!("Status: {}", response.status);
println!("Body: {}", response.body);
Ok(())
}
use rust_tlsx::{TlsClient, BrowserProfile};
fn main() -> anyhow::Result<()> {
let client = TlsClient::new(BrowserProfile::Firefox120);
let response = client.get("https://tls.peet.ws/api/all")?;
println!("TLS Fingerprint Analysis:\n{}", response.body);
Ok(())
}
use rust_tlsx::{TlsClient, BrowserProfile};
fn main() -> anyhow::Result<()> {
let client = TlsClient::new(BrowserProfile::Chrome109)
.header("Authorization", "Bearer YOUR_TOKEN")
.header("Content-Type", "application/json");
let response = client.get("https://api.example.com/data")?;
match response.status {
200 => println!("Success: {}", response.body),
401 => eprintln!("Authentication failed"),
_ => eprintln!("Request failed with status {}: {}", response.status, response.body),
}
Ok(())
}
use rust_tlsx::{TlsClient, BrowserProfile};
fn main() -> anyhow::Result<()> {
// Create a client that appears as a real Firefox browser
let client = TlsClient::new(BrowserProfile::Firefox120)
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0")
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8")
.header("Accept-Language", "en-US,en;q=0.5")
.header("Accept-Encoding", "gzip, deflate, br")
.header("DNT", "1") // Privacy-focused: Do Not Track
.timeout(30);
// Include session cookies for authenticated requests
let client = client.cookie("session_id", "your_session_token");
let response = client.get("https://example-site.com/data")?;
match response.status {
200 => println!("Data retrieved successfully with browser-like privacy"),
403 => println!("Authentication required - check session cookies"),
_ => println!("Response: {}", response.status),
}
Ok(())
}
use rust_tlsx::{TlsClient, BrowserProfile};
use std::collections::HashMap;
fn main() -> anyhow::Result<()> {
// Simulate a specific browser environment
let mut headers = HashMap::new();
headers.insert("User-Agent".to_string(),
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36".to_string());
headers.insert("Sec-Fetch-Site".to_string(), "same-origin".to_string());
headers.insert("Sec-Fetch-Mode".to_string(), "navigate".to_string());
headers.insert("Sec-Fetch-Dest".to_string(), "document".to_string());
let client = TlsClient::new(BrowserProfile::Chrome120)
.headers(headers)
.timeout(45);
// Make request that's indistinguishable from real browser
let response = client.get("https://api.example.com/sensitive-data")?;
println!("Retrieved data with perfect browser mimicry");
println!("Protocol used: {}", response.used_protocol);
Ok(())
}
与所有标准 Rust HTTP 客户端相比,RustTLSX 提供卓越的性能与隐私保护:
零拷贝操作:直接向优化的 C/Go 库发起 FFI 调用,消除了困扰纯 Rust 实现的不必要数据拷贝。
连接池:以与浏览器一致的 keep-alive 行为智能复用 TLS 连接,将握手开销降低高达 80%。
内存效率:Rust 的所有权模型结合优化的原生库,内存占用比等效的 Python 方案低 40%。
并发性能:内置异步支持,配合正确的连接多路复用,可随 CPU 核心数线性扩展。
对比 Python tls-client 绑定:
对比 Go tls-client:
对比 Node.js 方案:
从 tls-client releases 下载合适的二进制文件:
tls-client-windows-64-1.3.3.dlltls-client-linux-ubuntu-amd64-1.3.3.sotls-client-darwin-amd64-1.3.3.dylib将库文件放在项目根目录、系统库目录中,或确保可通过 PATH 访问。
[dependencies]
rust-tlsx = "0.1"
anyhow = "1.0"
use rust_tlsx::{TlsClient, BrowserProfile};
fn main() -> anyhow::Result<()> {
let client = TlsClient::new(BrowserProfile::Firefox120);
let response = client.get("https://example.com")?;
println!("Status: {}", response.status);
Ok(())
}
用于以类浏览器 TLS 指纹发起 HTTP 请求的主要客户端接口。
impl TlsClient {
pub fn new(profile: BrowserProfile) -> Self
pub fn header(self, key: &str, value: &str) -> Self
pub fn headers(self, headers: HashMap<String, String>) -> Self
pub fn cookie(self, name: &str, value: &str) -> Self
pub fn cookies(self, cookies: Vec<CookieInput>) -> Self
pub fn timeout(self, seconds: i32) -> Self
pub fn get(&self, url: &str) -> Result<Response>
pub fn post(&self, url: &str, body: Option<String>) -> Result<Response>
}
可用浏览器指纹配置文件的枚举:
pub enum BrowserProfile {
// Chrome versions
Chrome103, Chrome104, Chrome105, Chrome106,
Chrome107, Chrome108, Chrome109, Chrome120,
// Firefox versions
Firefox102, Firefox104, Firefox105, Firefox106,
Firefox108, Firefox120,
// Safari versions
Safari15_6_1, Safari16_0,
SafariIpad15_6, SafariIos15_5, SafariIos15_6, SafariIos16_0,
// Opera versions
Opera89, Opera90, Opera91,
}
客户端方法返回的 HTTP 响应结构:
pub struct Response {
pub status: i32, // HTTP status code
pub used_protocol: String, // Protocol used ("h2" or "http/1.1")
pub body: String, // Response body content
pub headers: HashMap<String, Vec<String>>, // Response headers
pub cookies: HashMap<String, String>, // Set-Cookie values
}
错误:Failed to load library: cannot find tls-client-*.dll
解决方案:
/usr/local/lib/)即使拥有真实的 TLS 指纹,可能仍需要其他因素:
必需的组件:
完整示例:
let client = TlsClient::new(BrowserProfile::Firefox120)
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0")
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.header("Accept-Language", "en-US,en;q=0.5")
.header("Accept-Encoding", "gzip, deflate, br")
.header("Connection", "keep-alive")
.header("Upgrade-Insecure-Requests", "1");
git clone https://github.com/yourusername/rust-tlsx
cd rust-tlsx
# Download required TLS library
wget https://github.com/bogdanfinn/tls-client/releases/download/v1.3.3/tls-client-windows-64-1.3.3.dll
# Build the project
cargo build --release
# Run tests
cargo test
cargo run --example simple_request
欢迎贡献!请参阅 CONTRIBUTING.md 获取指南。
可改进的方向:
根据以下任一许可证授权:
底层 TLS 客户端库使用 BSD-4-Clause 许可证。
| 库 | TLS 指纹 | 性能 | 隐私级别 | 内存占用 |
|---|
reqwest + rustls | 可检测的 Rust 签名 | 基准 | 低 | 高 |
reqwest + native-tls | 系统 TLS(可检测) | 基准 | 低 | 高 |
hyper + hyper-tls | 通用 HTTP/2 | 快 | 低 | 中 |
ureq | 基础 TLS 1.2/1.3 | 慢 | 低 | 低 |
rust-tlsx | 完美的浏览器模仿 | 快 6 倍 | 最高 | 已优化 |