Overview
TheBypassProxy implements a transparent HTTP/HTTPS proxy that intercepts HTTP CONNECT and regular HTTP requests, applies DPI bypass techniques, and forwards traffic to destination servers.
This is a specialized proxy that automatically applies SNI fragmentation for TLS connections and Host header fragmentation for HTTP requests.
BypassProxy
The main transparent proxy structure with built-in bypass engine.Structure
Fields
Proxy configuration including listen address and bypass settings
Statistics collector for tracking connections and traffic
DNS-over-HTTPS resolver for bypassing DNS blocking
Atomic flag indicating whether the proxy is running
Channel for sending shutdown signals
Methods
new()
Creates a newBypassProxy instance.
Proxy configuration settings
run()
Starts the proxy and begins accepting connections.Ok(()) on graceful shutdown, or IO error on failure.
Example:
stop()
Stops the proxy gracefully.stats()
Gets a reference to the proxy statistics.ProxyStats.
is_running()
Checks if the proxy is currently running.true if running, false otherwise.
ProxyConfig
Configuration for the transparent proxy.Fields
Address and port to listen onDefault:
127.0.0.1:8844DPI bypass configuration from the engine moduleDefault:
BypassConfig::default()Timeout for establishing connections to remote serversDefault:
30 secondsSize of relay buffers in bytesDefault:
65536 (64 KB)Enable verbose logging of connectionsDefault:
falseProxyStats
Statistics collector for the transparent proxy.Fields
Total number of connections handled since startup
Current number of active connections
Total bytes sent to remote servers
Total bytes received from remote servers
Number of TLS/HTTPS connections
Number of HTTP connections
Number of times DPI bypass was applied
Number of DNS-over-HTTPS queries performed
Total number of errors encountered
Methods
new()
Creates a new statistics collector.print_summary()
Prints a formatted summary of statistics to stdout.Protocol Support
HTTP CONNECT (HTTPS)
Handles HTTP CONNECT tunneling for HTTPS connections:- Parse CONNECT request: Extract target host:port
- DNS resolution: Use DNS-over-HTTPS to resolve hostname
- Establish connection: Connect to remote server
- Send 200 response:
HTTP/1.1 200 Connection Established - Detect protocol: Read first packet and detect TLS ClientHello
- Apply bypass: Fragment SNI if TLS detected
- Relay traffic: Bidirectionally relay all subsequent data
Regular HTTP Requests
Handles direct HTTP requests (non-CONNECT):- Extract target: Parse Host header or URL
- DNS resolution: Resolve via DoH
- Connect to server: Establish TCP connection
- Rewrite request: Convert absolute URL to relative path
- Forward request: Send rewritten request to server
- Relay responses: Forward server responses to client
DPI Bypass Integration
The proxy uses theBypassEngine to detect and modify traffic:
Fragment Sending
When bypass is applied, fragments are sent with optional delays:DNS-over-HTTPS
All DNS queries use DoH to bypass DNS blocking:Error Responses
The proxy returns appropriate HTTP error codes:- 400 Bad Request: Invalid or unsupported request format
- 502 Bad Gateway: Failed to connect to remote server or DNS failure
- 504 Gateway Timeout: Connection timeout exceeded
Example: Complete Usage
Browser Configuration
Configure your browser’s HTTP proxy settings:- HTTP Proxy:
127.0.0.1 - Port:
8844(or your configured port) - Use for HTTPS: Yes
- No proxy for: (leave empty to proxy everything)
Performance Characteristics
- Async I/O: Fully asynchronous using tokio
- Per-connection tasks: Each connection runs independently
- Automatic protocol detection: TLS/HTTP detection on first packet
- DoH caching: DNS resolver caches results internally
- Zero-copy buffers: Efficient buffer management with configurable sizes
- Idle timeouts: 30-second idle timeout for HTTP connections
Platform Support
Supported on all platforms:- Linux
- macOS
- Windows