Overview
vanguards-rs is a Rust implementation of vanguards, the Python addon for protecting Tor hidden services against guard discovery attacks. It provides the same security protections with Rust's safety guarantees and async-first design.
Even with Tor's v3 onion service protocol, hidden services face sophisticated attacks that require additional defenses. vanguards-rs implements these defenses as a controller addon, protecting your onion services ahead of their integration into Tor core.
use ;
async
โจ Features
๐ก๏ธ Vanguard Selection
Persistent guard relay selection at multiple layers to prevent guard discovery attacks.
- Layer 2 Guards โ 4-8 relays, 1-45 day lifetime
- Layer 3 Guards โ 4-8 relays, 1-48 hour lifetime
- Bandwidth-weighted selection
- Automatic rotation and replenishment
๐ Bandwidth Monitoring
Detect bandwidth-based side-channel attacks through circuit analysis.
- Circuit size limits (configurable MB threshold)
- Circuit age monitoring (default 24 hours)
- HSDIR descriptor size limits
- Disconnection warnings
๐ฏ Rendezvous Point Analysis
Statistical detection of rendezvous point overuse attacks.
- Usage tracking per relay
- Bandwidth-weighted expected usage
- Configurable overuse thresholds
- Automatic circuit closure on detection
๐ Log Monitoring
Monitor Tor logs for security-relevant events.
- Protocol warning detection
- Configurable log buffering
- Security event alerting
- Integration with Tor's logging
โฑ๏ธ Circuit Build Timeout Verification
Verify circuit construction timing to detect manipulation.
- Track circuit build times
- Detect anomalous patterns
- Optional component (disabled by default)
๐ Path Verification
Verify circuit paths conform to vanguard configuration.
- Ensure guards are used correctly
- Detect path manipulation
- Optional component (disabled by default)
๐ Quick Start
Add vanguards-rs to your Cargo.toml:
[]
= "1"
= { = "1", = ["full"] }
Or install the CLI:
Enable Tor's Control Port
Add to your torrc:
ControlPort 9051
CookieAuthentication 1
DataDirectory /var/lib/tor
Or for Unix socket:
ControlSocket /run/tor/control
CookieAuthentication 1
DataDirectory /var/lib/tor
Run vanguards-rs
# Connect to default control port (127.0.0.1:9051)
# Connect via Unix socket
# Generate default configuration file
# Use custom configuration
๐ก Examples
Basic CLI Usage
# Run with default settings
# Connect to specific control port
# Use Unix socket with custom state file
# One-shot mode: set vanguards and exit
# Enable debug logging
# Log to file
Component Control
# Disable specific components
# Enable optional components
Library Usage
use ;
use PathBuf;
async
Loading Configuration from File
use Config;
use Path;
let config = from_file?;
โ๏ธ Configuration
Configuration can be loaded from multiple sources (in order of precedence):
- CLI Arguments โ Highest priority
- Environment Variables โ
VANGUARDS_STATE,VANGUARDS_CONFIG - Config File โ TOML format
- Defaults โ Sensible defaults for all options
Example Configuration File
# Connection settings
= "127.0.0.1"
= 9051
# control_socket = "/run/tor/control" # Alternative: Unix socket
# control_pass = "my_password" # If using password auth
# File paths
= "vanguards.state"
# Logging
= "notice" # debug, info, notice, warn, error
# logfile = "/var/log/vanguards.log"
# Component toggles
= true
= true
= true
= true
= false
= false
# Operational settings
= true
= false
[]
= 2
= 4
= 8
= 24
= 1080 # 45 days
= 1
= 48
[]
= 0 # 0 = disabled
= 24
= 30
= 30
= 15
[]
= 1000
= 20000
= 100
= 5.0
= true
[]
= true
= 25
= "notice"
๐ฆ Module Reference
| Module | Description |
|---|---|
api |
High-level Vanguards struct for programmatic use |
config |
Configuration management (TOML, CLI, environment) |
control |
Main event loop and Tor connection management |
vanguards |
Vanguard state and guard selection |
bandguards |
Bandwidth monitoring and attack detection |
rendguard |
Rendezvous point usage tracking |
logguard |
Tor log monitoring and buffering |
cbtverify |
Circuit build timeout verification |
pathverify |
Circuit path verification |
node_selection |
Bandwidth-weighted relay selection |
๐ Security
vanguards-rs is designed with security as a priority:
- Memory Safety โ Passwords cleared after use (zeroize)
- File Permissions โ State files written with 0600 permissions
- Input Validation โ All external inputs validated
- Atomic Writes โ State file corruption prevention
- Guard Persistence โ Prevents restart-based guard discovery
โก Performance
- Async-first โ Built on Tokio for high-performance async I/O
- Efficient State โ Python pickle format for compatibility
- Low Overhead โ Minimal CPU usage during normal operation
๐ Python Compatibility
State files are compatible with Python vanguards for seamless migration:
# Migrate from Python vanguards
๐ ๏ธ Requirements
- Rust 1.70+
- Tokio runtime
- Tor instance with control port enabled
๐งช Testing
# Run unit tests
๐ Comparison with Python vanguards
| Feature | Python vanguards | vanguards-rs |
|---|---|---|
| Vanguard Selection | โ | โ |
| Bandwidth Monitoring | โ | โ |
| Rendezvous Analysis | โ | โ |
| Log Monitoring | โ | โ |
| CBT Verification | โ | โ |
| Path Verification | โ | โ |
| State Compatibility | โ | โ |
| Type Safety | โ | โ |
| Memory Safety | โ | โ |
| Async/Await | โ | โ |
๐ License
Copyright 2026 vanguards-rs contributors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
๐ค Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request