🔎 MITM Proxies
-
/examples/src/http_mitm_proxy_boring.rs: The recommended starting point for a MITM proxy. It is built from the Relay/Peek services: the CONNECT target is established before success is returned, TLS is mirrored and HTTP is relayed over that one egress connection. Also shows WebSocket relaying and inspection of decoded bodies.
- Similar to /examples/src/http_connect_proxy.rs but with MITM capabilities for both HTTP and HTTPS requests.
-
/examples/src/http_mitm_relay_proxy_boring.rs: A smaller version of /examples/src/http_mitm_proxy_boring.rs on the same Relay/Peek services, without WebSocket or body handling. It marks each request and prints the final egress headers, which makes it the shortest way into this design.
-
/examples/src/http_mitm_proxy_emulate_boring.rs: Unlike the relays above, which mirror the client, this proxy terminates TLS and sends each request through its own client that emulates a captured browser profile (TLS ClientHello, HTTP/2 settings and headers). Each client chooses the profile with proxy-auth username labels, such as
john-ua_chrome-ua_macos. -
/examples/src/tls_mitm_relay_client_auth.rs: A self-contained mTLS relay that authenticates an ingress client and maps it to a different upstream identity. Also demonstrates independent ingress admission and rejection of missing, untrusted or unmapped client certificates.
-
/examples/src/mitm_ocsp_relay_gate.rs: Test harness behind the MITM OCSP-stapling gate: a local upstream TLS server plus the boring relay proxy, exercising the mirror -> issue -> staple flow so an external client (
curl --cert-status/openssl s_client -status) can validate the stapled leaf. Driven byscripts/ocsp-relay-gate.sh(just test-ocsp-gate). -
/examples/src/http_mitm_proxy_rustls.rs: A Rustls compatibility example that terminates ingress TLS by hand and connects egress per decrypted request, because a paired Rustls TLS relay is not available yet. Its CONNECT success does not prove egress reachability. Prefer /examples/src/http_mitm_proxy_boring.rs for a new proxy.
The http_mitm_* examples above accept HTTP/1.1 and HTTP/2 over TCP. A client that tunnels
through CONNECT cannot carry HTTP/3 to its target, so none of them speak QUIC. To intercept
HTTP/3 see /examples/src/quic_h3_mitm_proxy.rs, which listens on
UDP, peeks the QUIC ClientHello and terminates HTTP/3 for the server names you choose.
Its QuicMitmRelay publishes the peeked ClientHello and QUIC first flight
on the terminated client connection, as the TLS relay publishes the
ClientHello it peeked, so HTTP/3 requests
carry the same TLS facts as requests over TCP. rama serve proxy --mitm uses them to capture,
export and replay HTTP/3 that clients tunnel through its MASQUE (CONNECT-UDP) ingress.
For proxying UDP through an HTTP proxy see
/examples/src/masque_connect_udp_proxy.rs, which serves
CONNECT-UDP (RFC 9298, one of the MASQUE protocols) next to ordinary CONNECT on one port.
The principles stay the same across transports, so these examples can be combined:
- the Relay/Peek design of
http_mitm_proxy_boringandhttp_mitm_relay_proxy_boringis whatquic_h3_mitm_proxyapplies to QUIC: peek the ClientHello, mirror TLS, then relay HTTP through your own HTTP middleware. A proxy can run both, with CONNECT-UDP as the way in for clients that only know an HTTP proxy; - the terminate and re-send design of
http_mitm_proxy_emulate_boringapplies to HTTP/3 too, as captured profiles describe HTTP/3 as well. The egress client then needs an HTTP/3 connector and the proxy a UDP ingress, both adapted to carry the selected profile.
Upgrades and CONNECT tunnels
HttpMitmRelay (HTTP/1 and HTTP/2) and Http3MitmRelay (HTTP/3) both
accept a caller-supplied stack through with_http_middleware.
Use HttpUpgradeMitmRelayLayer in that stack to select a handler for a
specific upgrade, such as a WebSocket.
An explicit match takes precedence when it claims the upgrade carried by the final response.
For an accepted, unclaimed byte tunnel, each relay runs its configured fallback.
The built-in fallback forwards bytes in both directions. Use with_upgrade_fallback(service) to replace it.
The custom service owns the client and origin streams as
BridgeIo<Upgraded, Upgraded> after the handshake response is sent.
The relay decides once, after response middleware has run. It requires a successful CONNECT response or a valid HTTP/1.1
101 Switching Protocols response that agrees with the request. The final response must carry its own origin upgrade.
To reject a tunnel with an HTTP response, return that response from middleware before the relay accepts the upgrade.
For CONNECT-UDP on HTTP/1.1, HTTP/2, or HTTP/3, install
ConnectUdpRelayRequestMatcher in
HttpUpgradeMitmRelayLayer to select a handler. The matcher marks the outgoing request and the accepted response
for HTTP Datagrams. Use HttpUpgradeMitmRelayExtensions on either message
to pass selected metadata to its upgraded stream.
Custom handlers can call handle_upgrade on the request or response to express interest in its stream before polling.
This keeps the stream available for that handler during fallback selection.
Cloning OnUpgrade alone leaves it available
for fallback. The first polling consumer has exclusive access, and dropping it while pending lets another consumer try.
Dropping all interested handles before the final response decision makes fallback eligible again.
HTTP/3 datagram fallback
For unclaimed HTTP/3 Extended CONNECT tunnels, an HttpDatagrams marker on
the final acceptance response selects the
datagram fallback. ConnectUdpMitmLayer marks CONNECT-UDP handshakes while
leaving the tunnel for this fallback.
Use Http3MitmRelay::with_datagram_fallback(service) to apply a common policy, such as metering both CONNECT-UDP
and CONNECT-IP tunnels that middleware has marked. An explicit upgrade handler still takes precedence.
The default datagram relay preserves reliable DATAGRAM Capsules and can forward native QUIC DATAGRAM frames when both hops negotiate support. See MASQUE for carrier details.
Description
An MITM proxy is typically set up as an HTTP Proxy, but it can alternatively be configured as a SOCKS5 proxy.
Transparent Proxies
MITM proxies that only wish to inspect traffic without destructive modification can attempt to mirror the incoming client across various network layers (TCP, TLS, and HTTP). This approach is a form of User-Agent emulation, but it operates based on the original User-Agent rather than emulating a popular one with significant market share.
These proxies are often referred to as transparent proxies, and you may notice network inspection software offering options labeled as “transparent mode” or “hidden.” If such software can still inspect your HTTPS traffic, it’s likely operating as a “transparent proxy.”
Reusable inspection and programmatic control
rama-inspect provides protocol-independent lifecycle, typed interception waits,
streamed record storage, and subscriptions for custom interfaces. HTTP, TLS,
profile, WebSocket, and encryption adapters live in their owning crates. Combine
inspect with the protocol and crypto features you use. See the
rama-inspect guide.
The CLI inspector also exposes a machine API on the same authenticated web server.
Start rama serve proxy --mitm --inspect-json for JSON readiness information, or
use the token in the normal startup link. Send Authorization: Bearer <token> to
GET /api for operation discovery and /api/help for the observe -> select hosts ->
intercept -> export workflow. No browser session or MCP server is required. A human
can continue using the GUI while an agent queries traffic or operates the controls.
ECH on TLS relay egress
The Boring TLS relay can offer real ECH to the upstream server while mirroring
an ingress ClientHello. It needs a configuration bound to the target endpoint.
Supply one directly or use DNS discovery after reading the ClientHello and
before starting the relay. Discovery needs the rama-tls/dns feature, a
resolver, and a backend that supports ECH. See the endpoint configuration,
discovery layer, and TLS relay.
Discovery uses the visible SNI for an IP-dialed destination and binds the result
to the existing ConnectorTarget. It does not change that destination or
resolve its addresses again. Install discovery only where the dialed address
serves that SNI name; a stale or unrelated address can reject ECH and fail the
relay flow.
Mirroring preserves the source’s ECH intent; explicit caller policy overrides it. Without target configuration, an ECH-offering source uses
GREASE. This does not decrypt or forward an ingress client’s real ECH payload:
when the source used real ECH, the visible SNI is its public name, not the hidden
origin.
EchRequirement::Required requires verified upstream authentication and real ECH
acceptance. Configure upstream verification explicitly: the relay’s usual
verification-disabled setting does not satisfy that policy. A relay already owns
one connected egress stream; ECH rejection fails that flow without redial or a
clear-SNI retry. Ordinary reconnecting TLS connectors retain their authenticated,
one-retry recovery path.