Mitmproxy WireGuard
mitmproxy-wireguard provides a user-space WireGuard VPN server implementation, allowing mitmproxy to transparently intercept traffic from WireGuard clients. While the standalone project is no longer actively maintained, its core functionality has been subsumed and is actively integrated within the mitmproxy project (version 11.x and newer). This integration offers a modern alternative to traditional transparent proxying, simplifying the setup for intercepting traffic from various devices. The current version available on PyPI is 0.1.23.
Warnings
- breaking The standalone `mitmproxy-wireguard` project is no longer maintained as a separate entity; its functionality has been subsumed into `mitmproxy_rs` and is now an integrated part of the main `mitmproxy` project. While the functionality persists, direct development on this specific PyPI package has ceased.
- gotcha IPv6 traffic support in WireGuard mode is limited. Generated client configurations may not list IPv6 addresses by default. While the server supports receiving IPv6 packets, proxying them is incomplete.
- gotcha It is not possible to proxy all traffic of the host machine where `mitmproxy` itself is running in WireGuard mode. This limitation prevents an infinite loop where outgoing WireGuard packets are sent over the WireGuard tunnel they originate from.
- gotcha Using `--allow-hosts` or `--ignore-hosts` options with `mitmproxy` in WireGuard mode can sometimes lead to issues where all traffic breaks, often related to DNS resolution.
- gotcha Chrome browsers do not trust user-added Certificate Authorities for QUIC (HTTP/3) by default, even after installing the mitmproxy CA certificate. This causes Chrome to fall back to HTTP/2.
- gotcha iOS clients may fail to trust the mitmproxy CA certificate in WireGuard mode, even after installing it as a profile and explicitly enabling 'Full Trust for Root Certificates' in iOS settings. This results in certificate errors for HTTPS sites.
Install
-
pip install mitmproxy-wireguard
Imports
- Server
from mitmproxy_wireguard import Server
- TcpStream
from mitmproxy_wireguard import TcpStream
- start_server
from mitmproxy_wireguard import start_server
Quickstart
# To run mitmproxy in WireGuard mode, install mitmproxy first.
# pip install mitmproxy
import subprocess
import time
import os
print("Starting mitmweb in WireGuard mode. This will open a browser window.")
print("Connect your WireGuard client to the displayed configuration (QR code or file in ~/.mitmproxy/wireguard.conf).")
print("Then, from the connected device, navigate to http://mitm.it to install the CA certificate.")
# Ensure mitmproxy is in the PATH or provide full path
mitmproxy_cmd = ["mitmweb", "--mode", "wireguard", "--web-host", "127.0.0.1", "--web-port", os.environ.get('MITMWEB_PORT', '8081')]
# You might need to adjust this if mitmweb doesn't start in a way that allows direct subprocess control
# For typical usage, users would run this command directly in a terminal.
# This example is illustrative of the command, not a robust programmatic launch.
try:
# Start mitmweb in a non-blocking way if possible, or instruct user to run it.
# For simplicity in a quickstart, we'll just print the command.
print(f"\nRun this command in your terminal: {' '.join(mitmproxy_cmd)}\n")
# In a real scenario, you'd use subprocess.Popen for background execution
# p = subprocess.Popen(mitmproxy_cmd)
# p.wait() # Or handle it asynchronously
except FileNotFoundError:
print("Error: 'mitmweb' command not found. Please ensure mitmproxy is installed and in your PATH.")
except Exception as e:
print(f"An error occurred: {e}")
# Example of what a user would do after starting mitmweb:
# 1. Configure WireGuard client using the QR code or ~/.mitmproxy/wireguard.conf
# 2. On the client, browse to http://mitm.it to install the CA certificate.
# 3. All traffic from the WireGuard client will now be intercepted by mitmproxy.