惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
D
Docker
B
Blog
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
G
Google Developers Blog
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42

Posts on mitmproxy.org

Mitmproxy 12: Interactive Contentviews Intercepting Linux Applications Mitmproxy 11: Full HTTP/3 Support Mitmproxy 10.4: Mitmweb Capture Tab Intercepting Windows Applications Intercepting macOS Applications Mitmproxy 10.1: HAR Support Mitmproxy 10: First Bits of HTTP/3! Mitmproxy 9 Mitmproxy 8 Google Summer of Code 2021 Mitmproxy 7 A New Proxy Core, Sans I/O Mitmproxy 6 Mitmproxy 5.3 Mitmproxy 5.2 Mitmproxy 5 Mitmproxy 4 Google Summer of Code 2018 Mitmproxy 3
A more user-friendly transparent mode, based on WireGuard
Fabio Valentini · 2022-10-28 · via Posts on mitmproxy.org
28 Oct 2022,

mitmproxy 9 ships with a new experimental proxy mode based on WireGuard®. This new mode makes it incredibly easy to set up proxying for other devices in your network, and allows you to only proxy specific apps on Android.

Connecting another device and routing its traffic through mitmproxy becomes as simple as connecting to a WireGuard VPN — either by using the WireGuard configuration file generated by mitmproxy, or by scanning the QR code that is shown in the mitmweb interface:

Setting up an Android smartphone (right) to use mitmweb (left).
The mitmproxy CA certificate has been preinstalled for this demo.

How it works

The core of this feature is implemented in the mitmproxy-wireguard Python package, which provides a user space implementation of a WireGuard server. It is a new dependency of mitmproxy and ships with the latest release.

Because the WireGuard protocol operates by transmitting IP packets, this also involves running a network stack in user space to parse incoming IP packets, construct outgoing IP packets, handle TCP connections, and process UDP datagrams.


Architecture of the WireGuard server implemented in mitmproxy_wireguard

Architecture of the WireGuard server implemented in mitmproxy_wireguard

The interfaces which are provided by mitmproxy_wireguard were designed to match the APIs in the Python standard library’s asyncio module as closely as possible. In particular, the TcpStream provided by the package implements all methods of asyncio.StreamReader and asyncio.StreamWriter which are expected by mitmproxy, and can be used as a drop-in replacement.

Oh, and did I mention this already? The mitmproxy_wireguard project is written in Rust, utilizing some great Rust libraries to implement this functionality — most notably:

  • Tokio, an asynchronous runtime for Rust.
  • boringtun, an implementation of the WireGuard protocol.
  • smoltcp, a standalone, user space TCP/IP stack.
  • PyO3, a project that provides Python ↔ Rust interoperability, including support for bridging async runtimes of the two languages.
  • Maturin, a build tool for Python packages that are implemented in Rust.

How to use it

In contrast to the existing transparent mode, the wireguard mode requires little to no manual configuration. Running mitmproxy in this mode should be as simple as specifying --mode wireguard. By default, mitmproxy will try to load existing WireGuard encryption keys from ~/.mitmproxy and generate new keys if they don’t exist yet. As most WireGuard servers, it will listen on 51820/udp by default.

For example, running mitmweb with the new wireguard mode and using default settings is as simple as running:

The mitmweb interface then shows the configuration file and QR code that can be used to connect clients to mitmproxy via the WireGuard tunnel:

WireGuard configuration and scannable QR code as shown by mitmweb

WireGuard configuration and scannable QR code as shown by mitmweb

What’s next?

Support for this WireGuard mode is still very new, and there are likely still bugs, but it should already work for basic use cases. We’re still collecting feedback (unless you’re reading this in the far future).

There’s also a few things that do not work yet in this mode — in particular, the support for IPv6 is still incomplete, which is why the provided configuration for WireGuard clients will only route IPv4 traffic to mitmproxy.

Acknowledgments

This project would not have been possible if not for the great ecosystem of existing Rust libraries for asynchronous programming (tokio), low-level networking functionality (boringtun, smoltcp), and bridging the gap between Rust and Python (pyo3, pyo3-log, pyo3-asyncio, maturin).

I would also like to thank Maximilian Hils for his mentorship and for supervising my Bachelor thesis — which, coincidentally, will be about “Implementing a WireGuard frontend for mitmproxy”. 🙃


“WireGuard” and the “WireGuard” logo are registered trademarks of Jason A. Donenfeld.