WireGuard interface for mitmproxy
Project description
mitmproxy_wireguard
Transparently proxy any device that can be configured as a WireGuard client!
Work-In-Progress.
Architecture
DONE
- multi-threaded / 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
- basic TCP/IPv4 functionality, IPv6 only partially supported
- basic UDP functionality
- Python interface similar to the one provided by
asyncio.start_server
- basic support for reading WireGuard configuration files
TODO
- better and more complete IPv6 support
- better and more helpful logging
- unit tests
- mitmproxy Integration
- various other
TODO
andFIXME
items (documented in the code)
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
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
when using
a debug build of the native module:
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.toml
. Some used configuration
options are only available on nightly Rust. To apply the formatting rules, use:
cargo +nightly 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for mitmproxy_wireguard-0.1.0a7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cbc5a530327517025e7eb1eb8304ae414b365dabd6285b78ebb5599ffa18a65 |
|
MD5 | 7820fd489b5f47f5a8671c15cec55afa |
|
BLAKE2b-256 | cae37264b83c784577bcc0750f76adf46f782b44e5e9f7d1c0540afe4f930836 |
Hashes for mitmproxy_wireguard-0.1.0a7-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 087ee9a13e9c2622a267a98c729045514d175f9b78f4026a4ff76189d0e560e4 |
|
MD5 | 2719ce29c21a9c145b7e6dea4b3b51b7 |
|
BLAKE2b-256 | a275132293172e64f1c0f33e0d810229ed2d5abcd760909ba0b781c0b400885f |
Hashes for mitmproxy_wireguard-0.1.0a7-cp37-abi3-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2a8e472cd5a15c27fbd83d5fc5ce1980c3a2df4b1e812b19ded15cbb1837a68 |
|
MD5 | d63a94f5ce3c6eb3c612f4c55763e518 |
|
BLAKE2b-256 | ccfee6cf41bcd4e4496bf9cabe5346a020ca4191bbb6d264b4dfa55d109d9d4e |
Hashes for mitmproxy_wireguard-0.1.0a7-cp37-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bfb827518a10af12535a744b0218fa4be2fa82199822712689ef45ad92b5e72 |
|
MD5 | 83e552fcda78287e8b3657665fafd117 |
|
BLAKE2b-256 | b3f20587061542c8525756261947833af7d91f549b7323b60bd5d95b0105b28b |
Hashes for mitmproxy_wireguard-0.1.0a7-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdc55e9f0cbf6c81e74a64883e405bf72164bd9d1557fcefda4d6dcae6a3f627 |
|
MD5 | 03c34201ca37bc9b2a0c086c0dfa54cd |
|
BLAKE2b-256 | 106cd3af8af9b981431279c18f3b8accf5cdefa4c5c58c67d71cd5fa7220a90d |
Hashes for mitmproxy_wireguard-0.1.0a7-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 646a2f2336afa75cfc6e850a1e624465a99c1ef708b84d9bb3df6e2c5cf6ae72 |
|
MD5 | f8f4f5d6a7014639de094679c63966e1 |
|
BLAKE2b-256 | 5f9f9b33e6c67cb4196ce5e8d4658e359f724e3825445d29cbb34f9271fb17ff |
Hashes for mitmproxy_wireguard-0.1.0a7-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd6fb43b50b136f5c800f6cf4cb46eb0822b27c9c75f10a9dfffc2989d35b7f6 |
|
MD5 | a4ee63515c30ef197a15d23701e5c403 |
|
BLAKE2b-256 | cad6ffbb6d85da1660e880bc9c1ce8f3fb25d7b72a7abbc00975dc5aef8ee998 |