RustGate
MITM-capable HTTP/HTTPS proxy written in Rust. It can be used both as a CLI tool and as a library (crate: rustgate-proxy, lib: rustgate).
Features
- HTTP Proxy - Forwards plain HTTP requests (with hop-by-hop header stripping)
- CONNECT Tunneling - HTTPS passthrough via bidirectional byte relay
- MITM Mode - TLS termination for HTTPS interception and inspection
- Dynamic Certificate Generation - Per-domain CA-signed cert generation with caching
- CA Certificate Management - Auto-generates and stores root CA in
~/.rustgate/on first run (private key set to0600) - Request/Response Rewriting - Hook mechanism via the
RequestHandlertrait - IPv6 Support - Correctly handles CONNECT targets like
[::1]:443 - Security Considerations - Masks query parameters in logs and warns on non-loopback bind
Architecture
Client ──TCP──> RustGate Proxy ──TCP/TLS──> Upstream Server
|
+-----+-----+
| HTTP Router |
+-----+------+
+--------+--------+
v v v
HTTP Forward CONNECT CONNECT
(Plain) (Tunnel) (MITM)
Passthrough TLS Termination
Installation
From crates.io
Build from source
Usage
Basic (passthrough mode)
# Default: starts on 127.0.0.1:8080
# Custom port
MITM mode (TLS interception)
On first startup, a CA certificate is generated at ~/.rustgate/ca.pem.
CLI options
Usage: rustgate [OPTIONS]
Options:
--host <HOST> Listen address [default: 127.0.0.1]
-p, --port <PORT> Listen port [default: 8080]
--mitm Enable MITM mode (TLS interception)
-h, --help Print help
Log level
Controlled with the RUST_LOG environment variable:
RUST_LOG=rustgate=debug
RUST_LOG=rustgate=trace
Quick verification
HTTP proxy
HTTPS passthrough
MITM (TLS interception)
Send an HTTPS request with the CA certificate:
If you install the CA certificate into your OS trust store, --cacert is no longer needed:
# macOS
# Ubuntu/Debian
Use as a library
Crate name is rustgate-proxy; library name is rustgate.
[]
= "0.1"
Custom handler
Implement RequestHandler to inspect or modify requests and responses passing through the proxy:
use ;
use ;
;
Embed the proxy server
use CertificateAuthority;
use LoggingHandler;
use ;
use Arc;
use TcpListener;
async
Public modules
| Module | Description |
|---|---|
rustgate::proxy |
ProxyState, handle_connection, parse_host_port |
rustgate::cert |
CertificateAuthority, CertifiedKey |
rustgate::tls |
make_tls_acceptor, connect_tls_upstream |
rustgate::handler |
RequestHandler trait, LoggingHandler, BoxBody |
rustgate::error |
ProxyError, Result |
File layout
src/
├── lib.rs # Library entry point (exports modules)
├── main.rs # CLI entry point
├── proxy.rs # Proxy handlers (HTTP forward + CONNECT + MITM)
├── cert.rs # CA management and dynamic certificate generation
├── tls.rs # TLS termination and upstream TLS connection
├── handler.rs # RequestHandler trait definition
└── error.rs # Error type definitions
tests/
└── integration_test.rs # Integration tests
Notes
- Use MITM features only with consent from all parties involved. Unauthorized interception may violate laws.
- Authentication and access control are not implemented. Binding to non-loopback addresses (
0.0.0.0,::, LAN IP, public IP, etc.) can expose the proxy on your network. RustGate warns at startup when binding to non-loopback addresses. Use trusted networks only, or restrict access with firewalls. - This tool is intended for security testing, debugging, and educational use.