Skip to main content

WireGuard interface for mitmproxy

Project description

mitmproxy_wireguard

PyPI PyPI - License PyPI - Status PyPI - Python Version PyPI - Wheel ci

Transparently proxy any device that can be configured as a WireGuard client!

DONE

  • multithreaded / asynchronous WireGuard server using tokio:
    • one worker thread for the user-space WireGuard server
    • one worker thread for the user-space network stack
    • one worker thread for communicating with the Python runtime
  • full support for IPv4 packets (TCP and UDP)
  • partial support for IPv6 packets (TCP and UDP)
  • Python interface similar to the Python asyncio module
  • integration tests in mitmproxy

TODO

  • more complete IPv6 support
  • various other small TODO and FIXME items

Architecture support

mitmproxy_wireguard should work on most architectures / targets - including, but not limited to Windows, macOS, and Linux, running on x86_64 (x64) and aarch64 (arm64) CPUs.

Binary wheels for the following targets are available from PyPI:

  • Windows / x64 (x86_64-windows-msvc)
  • macOS / Intel (x86_64-apple-darwin)
  • macos / Apple Silicon (aarch64-apple-darwin) via "Universal 2" binaries
  • Linux / x86_64 (x86_64-unknown-linux-gnu)
  • Linux / aarch64 (aarch64-unknown-linux-gnu), i.e. for Raspberry Pi 2+ and similar devices

Requirements

mitmproxy_wireguard currently requires Python 3.7 or newer at runtime, since that is the oldest version of Python that is still supported by PyO3 v0.16. mitmproxy already requires Python 3.9 or newer, so this should not be a problem.

Additionally, mitmproxy_wireguard currently has the following requirements at build-time:

  • Python 3.7+ (range of Python versions that is supported by PyO3 v0.16)
  • Rust 1.58.0+ (the oldest supported version of Rust / MSRV is 1.58.0)
  • maturin 0.13.x

Architecture

library architecture

Interface

The API interface of the PyO3 module is documented in mitmproxy_wireguard.pyi:

  • Server class: a running WireGuard server instance, with methods for
    • graceful shutdown (close / wait_closed)
    • sending UDP packets
  • TcpStream class: an established TCP connection (provides APIs identical to Python's) asyncio.StreamReader and asyncio.StreamWriter)
  • start_server coroutine: initialize, start, and return a Server instance

Hacking

Setting up the development environment is relatively straightforward, as only a Rust toolchain and Python 3 are required:

# set up a new venv
python3 -m venv venv

# enter venv (use the activation script for your shell)
source ./venv/bin/activate

# install maturin and pdoc
pip install maturin pdoc

Compiling the native Rust module then becomes easy:

# compile native Rust module and install it in venv
maturin develop

# compile native Rust module with optimizations
maturin develop --release

Once that's done (phew! Rust sure does take a while to compile!), the test echo server should work correctly. It will print instructions for connecting to it over a WireGuard VPN:

python3 ./echo_test_server.py

The included mitm-wg-test-client binary can be used to test this echo test server, which can be built by running cargo build inside the test-client directory, and launched from target/debug/mitm-wg-test-client.

Docs

Documentation for the Python module can be built with pdoc.

The documentation is built from the mitmproxy_wireguard.pyi type stubs and the rustdoc documentation strings themselves. So to generate the documentation, the native module needs to be rebuilt, as well:

maturin develop
pdoc mitmproxy_wireguard

By default, this will build the documentation in HTML format and serve it on http://localhost:8080.

Note: This requires version >=11.2.0 of pdoc. It is the first version that supports generating documentation for "native-only" Python modules (like our mitmproxy_wireguard PyO3 module).

Introspecting the tokio runtime

The asynchronous runtime can be introspected using tokio-console if the crate was built with the tracing feature:

tokio-console http://localhost:6669

There should be no task that is busy when the program is idle, i.e. there should be no busy waiting.

Note: This requires maturin>=0.12.15, as earlier versions accidentally clobbered the RUSTFLAGS that were passed to the Rust compiler, breaking use of the console_subscriber for tokio-console, which requires using the --cfg tokio_unstable flag.

Code style

The format for Rust code is enforced by rustfmt. To apply the formatting rules, use:

cargo fmt

The format for Python code (i.e. the test echo server and the type stubs in mitmproxy_wireguard.pyi) is enforced with black and can be applied with:

black echo_test_server.py mitmproxy_wireguard.pyi benches/*.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mitmproxy_wireguard-0.1.20.tar.gz (29.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mitmproxy_wireguard-0.1.20-cp37-abi3-win_amd64.whl (721.1 kB view details)

Uploaded CPython 3.7+Windows x86-64

mitmproxy_wireguard-0.1.20-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

mitmproxy_wireguard-0.1.20-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

mitmproxy_wireguard-0.1.20-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.7 MB view details)

Uploaded CPython 3.7+macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

mitmproxy_wireguard-0.1.20-cp37-abi3-macosx_10_7_x86_64.whl (867.4 kB view details)

Uploaded CPython 3.7+macOS 10.7+ x86-64

File details

Details for the file mitmproxy_wireguard-0.1.20.tar.gz.

File metadata

  • Download URL: mitmproxy_wireguard-0.1.20.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for mitmproxy_wireguard-0.1.20.tar.gz
Algorithm Hash digest
SHA256 440edb39623110e1a5b8793a70afb3833f25dba05cf02b07b083848b31cb0523
MD5 0c9351edc148985cd64b98e2f14c18bb
BLAKE2b-256 6a48c38952d88ec284f3251952f7a1044a1c8090e2a7d949d1290a0b5072fd50

See more details on using hashes here.

File details

Details for the file mitmproxy_wireguard-0.1.20-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: mitmproxy_wireguard-0.1.20-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 721.1 kB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for mitmproxy_wireguard-0.1.20-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d808a656115c0c90c5019bce98d32fded13c8bb0d24510e13521275baebd0b42
MD5 76b5f124c751ebcb85a7a6e26eaff1e8
BLAKE2b-256 3205a9fff4742eb36160ac5e440558b7e3fd7823d205f2082522acf823fc7f95

See more details on using hashes here.

File details

Details for the file mitmproxy_wireguard-0.1.20-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: mitmproxy_wireguard-0.1.20-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.7+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for mitmproxy_wireguard-0.1.20-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 568bab7c406311109885a3746e2df874efe30c3b4a9ba9e941c908bc4e17c9f6
MD5 4330268db93dbc4b0f7b6a2bbabfcb1e
BLAKE2b-256 97812fe5527aacbe6d1225ffa147f1326abf6af9792a682256b3d0808420a544

See more details on using hashes here.

File details

Details for the file mitmproxy_wireguard-0.1.20-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: mitmproxy_wireguard-0.1.20-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.7+, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for mitmproxy_wireguard-0.1.20-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ca83ba39b0b01f4363cacbeb1bf8f5094730bd2c8591bc87aa023ccd0e643f06
MD5 256279e1f2f8d8cc2eb324f6762c15c7
BLAKE2b-256 5ad8609b5359eaa8e7c0d4492adaa6e84d3e5e40100914891204214f72ca6ea7

See more details on using hashes here.

File details

Details for the file mitmproxy_wireguard-0.1.20-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

  • Download URL: mitmproxy_wireguard-0.1.20-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.7+, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for mitmproxy_wireguard-0.1.20-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d53104a07a1f318d85b26d0a9daa9b2bd505a8c8692038b77659f33cd704a6be
MD5 595b762e6073fff8c62ac1ac96fd0ee5
BLAKE2b-256 ed53f791c2d606a79c9de343ef098a974e1a916cd067dde9154e7615afac203c

See more details on using hashes here.

File details

Details for the file mitmproxy_wireguard-0.1.20-cp37-abi3-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: mitmproxy_wireguard-0.1.20-cp37-abi3-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 867.4 kB
  • Tags: CPython 3.7+, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for mitmproxy_wireguard-0.1.20-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 9b8c90d19bd48ab29d6cbc03c775f20e0c3f6c8544c5c464b0276f7083ef5a74
MD5 3319c98fe2e988556b883629f2ab0c67
BLAKE2b-256 1aaf037bf2b9e721851cd420224563f46d0b3040a904c45780c594470c8fa05b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page