WireGuard interface for mitmproxy
Project description
mitmproxy_wireguard
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
andFIXME
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
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
- graceful shutdown (
TcpStream
class: an established TCP connection (provides APIs identical to Python's)asyncio.StreamReader
andasyncio.StreamWriter
)start_server
coroutine: initialize, start, and return aServer
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
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.23.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0f7b44ef9b0601307c122c5fe1ce57368c2fc9330097ec576984a0d640b4727 |
|
MD5 | 64cced5db1be46f1195e0480854a279e |
|
BLAKE2b-256 | 46715529c5c0eefdee81dedce09deb76578dd416deec38e10b70a111d57322fd |
Hashes for mitmproxy_wireguard-0.1.23-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2f6121dc4d2d8b692124f3d027f4c839ef764278d473fb89357841b0a4406cf |
|
MD5 | fabdbb15497562a9410e44a2b9e6d0f7 |
|
BLAKE2b-256 | 2f10aed097fa3b545ba2e910abb96b5ef997d2eccf2d8e6948992c9e788d4b65 |
Hashes for mitmproxy_wireguard-0.1.23-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23a55cd010d9d116b23101b5b8b963d10f3d38d6f9be0f58ba53288012f4fef9 |
|
MD5 | d282d960a211d30a127b8727b2482065 |
|
BLAKE2b-256 | 18ea582628aaabd790831298e11d74ce6e3f280d38e09528182dead1df26c6c8 |
Hashes for mitmproxy_wireguard-0.1.23-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82ac397bcd8ac3cfd08c91b2039b0ba5dc67edfa65fb52ab0e5df81220bdb913 |
|
MD5 | bed9a54c3399aff0028e19923be5c5d5 |
|
BLAKE2b-256 | a921693558a7fb8f9706e827599559cc16aeb07977fbcfb2553dfc5cafba0c15 |
Hashes for mitmproxy_wireguard-0.1.23-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f433fa20358ab2999ba9233819649d2a5a5c2b95eac7e95f4533de90d978d115 |
|
MD5 | 8e8a8796ef81e981c1a7eaa9adf94d58 |
|
BLAKE2b-256 | d6aacf5c3a8ab0c83654e0ab5a90c33b87a50d2bba6df1524f44cea6d4f88a05 |
Hashes for mitmproxy_wireguard-0.1.23-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 661471e8a363b16d5d871c6c6c30205b16b636574b5bc062b3f158d8b76951ad |
|
MD5 | 9ee5451afe95ddedc0c23dbcc8f1552c |
|
BLAKE2b-256 | e8503bb028f7be33ae692be32ebe95c12c52f0000af3e46bdb6375f65ab92b3e |