Mitmproxy WireGuard

0.1.23 · maintenance · verified Thu Apr 09

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

Install

Imports

Quickstart

The primary way to use mitmproxy-wireguard's functionality is through the `mitmproxy` CLI tools (mitmproxy, mitmweb, or mitmdump) using the `--mode wireguard` option. This starts a WireGuard VPN server. Clients then connect using a standard WireGuard application, importing the configuration (often via a QR code or a file at `~/.mitmproxy/wireguard.conf`) provided by mitmproxy. After connecting, the mitmproxy CA certificate must be installed on the client device by navigating to `http://mitm.it`.

# 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.

view raw JSON →