Repository: mitmproxy/mitmproxy

Issue:
mitmproxy: 10.2: WireGuard Mode Does Not Receive Connections
#### Problem Description
It looks like commit 6e38a56f4 Thu Jan 4 10:53:13 2024 +0100   implement UDP streams (and all future commits) has changed/broken something in the wireguard proxy mode.  Prior commits work as expected.

#### Steps to reproduce the behavior:
1. Build 6e38a56f4     or tag 10.2.0
2. ./mitmdump --set block_global=false --mode 'wireguard:/home/admin/.mitmproxy/wireguard.conf'
3. Then curl or visit web page from client running wireguard client , mitmproxy server does not accept the request

When mitmdump (version 6e38a56f4  or tag 10.2.0) starts the following is printed

```
./mitmdump --set block_global=false --mode 'wireguard:/home/admin/.mitmproxy/wireguard.conf'
[23:47:56.530] ------------------------------------------------------------
[Interface]
PrivateKey = ...
Address = 10.0.0.1/32
DNS = 10.0.0.53

[Peer]
PublicKey = ...
AllowedIPs = 0.0.0.0/0
Endpoint = a.b.c.d:60000
------------------------------------------------------------
[23:47:56.530] WireGuard server listening at 127.0.0.1:60000.
```

#### System Information
./mitmdump --version                                                         Mitmproxy: 11.0.0.dev (+9, commit 6e38a56)
Python:    3.11.2
OpenSSL:   OpenSSL 3.1.2 1 Aug 2023
Platform:  Linux-6.1.0-15-cloud-arm64-aarch64-with-glibc2.36


When commit ed532e927 is run the following is logged - this is the expected output and in this case mitmproxy works as expected in wg mode.

```
./mitmdump --set block_global=false --mode 'wireguard:/home/admin/.mitmproxy/wireguard.conf'
[23:45:25.620] Initializing WireGuard server ...
[23:45:25.621] WireGuard server listening for UDP connections on 0.0.0.0:60000 and [::]:60000 ...
[23:45:25.621] WireGuard server successfully initialized.
[23:45:25.622] ------------------------------------------------------------
[Interface]
PrivateKey = ...
Address = 10.0.0.1/32
DNS = 10.0.0.53

[Peer]
PublicKey = ...
AllowedIPs = 0.0.0.0/0
Endpoint = a.b.c.d:60000
------------------------------------------------------------
[23:45:25.622] WireGuard server listening at *:60000.
[23:45:26.335][10.0.0.2:52756] client connect
...usual logs...
```

#### System Information 
Mitmproxy: 11.0.0.dev (+8, commit ed532e9)
Python:    3.11.2
OpenSSL:   OpenSSL 3.1.2 1 Aug 2023
Platform:  Linux-6.1.0-15-cloud-arm64-aarch64-with-glibc2.36



Discussion:
Thanks! It looks like I accidentally changed the default listening address to `127.0.0.1` instead of binding to all interfaces. The workaround is to specify it explicitly:
```
mitmweb --mode wireguard@0.0.0.0:51820
```

Let's ship a patch release for this...

Resolving patch:
diff --git a/mitmproxy/proxy/mode_servers.py b/mitmproxy/proxy/mode_servers.py
--- a/mitmproxy/proxy/mode_servers.py
+++ b/mitmproxy/proxy/mode_servers.py
@@ -372,7 +372,7 @@ async def _start(self) -> None:
         _ = mitmproxy_rs.pubkey(self.server_key)
 
         self._server = await mitmproxy_rs.start_wireguard_server(
-            host or "127.0.0.1",
+            host or "0.0.0.0",
             port,
             self.server_key,
             [p],


Test patch: