diff --git a/infra/conf/tun.go b/infra/conf/tun.go index cc0388ae0..aabddb980 100644 --- a/infra/conf/tun.go +++ b/infra/conf/tun.go @@ -39,7 +39,7 @@ func (v *TunConfig) Build() (proto.Message, error) { } for _, leak := range v.AutoSystemWfpBlockLeak { switch leak := strings.ToLower(leak); leak { - case "dns", "misconfig": + case "dns", "misconfigtun": config.AutoSystemWfpBlockLeak = append(config.AutoSystemWfpBlockLeak, leak) default: return nil, errors.New("unknown autoSystemWfpBlockLeak value: ", leak) diff --git a/infra/conf/tun_test.go b/infra/conf/tun_test.go index 648d4d8ce..697e0fdf0 100644 --- a/infra/conf/tun_test.go +++ b/infra/conf/tun_test.go @@ -25,9 +25,9 @@ func TestTunConfigAutoSystem(t *testing.T) { Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, AutoSystemDnsToGateway: true}, }, { - Input: `{"name": "xray0", "autoSystemWfpBlockLeak": ["dns", "misconfig"]}`, + Input: `{"name": "xray0", "autoSystemWfpBlockLeak": ["dns", "misconfigtun"]}`, Parser: loadJSON(creator), - Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, AutoSystemWfpBlockLeak: []string{"dns", "misconfig"}}, + Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, AutoSystemWfpBlockLeak: []string{"dns", "misconfigtun"}}, }, { Input: `{"name": "xray0", "autoSystemWfpBlockLeak": ["DNS"]}`, diff --git a/proxy/tun/README.md b/proxy/tun/README.md index dc3bb34b7..4f4c4226b 100644 --- a/proxy/tun/README.md +++ b/proxy/tun/README.md @@ -201,9 +201,9 @@ After the start network adapter with the name you chose in the config will be cr When `dns` is set, those servers are applied to the adapter. Windows is kept from registering the TUN's addresses in DNS, and its DNS cache is flushed when the TUN starts and stops. -With `autoSystemWfpBlockLeak` and `autoSystemRoutingTable` set, Xray also adds Windows Filtering Platform filters that keep two kinds of traffic of every program but Xray itself from leaving outside the TUN, each chosen by a value in the list, e.g. `"autoSystemWfpBlockLeak": ["dns", "misconfig"]`: +With `autoSystemWfpBlockLeak` and `autoSystemRoutingTable` set, Xray also adds Windows Filtering Platform filters that keep two kinds of traffic of every program but Xray itself from leaving outside the TUN, each chosen by a value in the list, e.g. `"autoSystemWfpBlockLeak": ["dns", "misconfigtun"]`: - `"dns"`: with `dns` set, DNS (port 53) only goes through the TUN. Windows keeps sending name queries to the DNS servers of the other interfaces as well, out through those interfaces whatever the routes say, and other programs reach a resolver on the local network (e.g. `192.168.1.1` handed out by DHCP) through its more specific LAN route instead of the TUN. On Windows 11 and Server 2022 and later, where those queries may also go over HTTPS or TLS, Windows' DNS Client service cannot connect outside the TUN at all, except for name resolution on the local network (LLMNR, mDNS). The `dns` servers therefore have to lie within `gateway` or `autoSystemRoutingTable` (a warning is logged otherwise), and DNS servers that should be reached directly belong in Xray's own `dns` settings. -- `"misconfig"`: an IP version without routes in `autoSystemRoutingTable`, IPv4 or IPv6, is blocked entirely, in both directions, as it would bypass the TUN. Only loopback and what Windows itself needs on the local link (DHCP, and for IPv6 neighbor and multicast listener discovery) remain allowed. An address of that version in `gateway` is not needed: without one, Windows gives the TUN link-local addresses itself, an IPv6 one at once and an IPv4 one from `169.254.0.0/16` after some seconds (until then, IPv4 routed to the TUN is unreachable), and what is routed to the TUN goes through it with those. +- `"misconfigtun"`: an IP version without routes in `autoSystemRoutingTable`, IPv4 or IPv6, is blocked entirely, in both directions, as it would bypass the TUN. Only loopback and what Windows itself needs on the local link (DHCP, and for IPv6 neighbor and multicast listener discovery) remain allowed. An address of that version in `gateway` is not needed: without one, Windows gives the TUN link-local addresses itself, an IPv6 one at once and an IPv4 one from `169.254.0.0/16` after some seconds (until then, IPv4 routed to the TUN is unreachable), and what is routed to the TUN goes through it with those. With the filters in place, Xray's own connections out also get past Windows Firewall's block rules (other firewalls may still block them), while connections to Xray's inbounds stay subject to them. @@ -211,7 +211,7 @@ Names that Xray resolves through the system resolver, such as an outbound's serv If the filters cannot be added, the TUN does not start (on Windows 10 and later; older versions only log a warning). They are removed when Xray exits. Not covered is name resolution on the local network (LLMNR, mDNS, NetBIOS), except over an IP version that is blocked. -`autoSystemWfpBlockLeak` (Windows only) is empty by default, as the filters break some setups: with `"dns"`, a local DNS resolver other programs use (e.g. on `127.0.0.1:53`), the DNS of another VPN on its own interface, virtual machines whose NAT resolves names on the host, or signing in to a captive portal; with `"misconfig"`, IPv4 or IPv6 on the local network while no route of that version leads to the TUN. Without the filters, DNS may leak as described above. To keep an IP version out of the TUN on purpose while still blocking DNS leaks, use only `["dns"]`. +`autoSystemWfpBlockLeak` (Windows only) is empty by default, as the filters break some setups: with `"dns"`, a local DNS resolver other programs use (e.g. on `127.0.0.1:53`), the DNS of another VPN on its own interface, virtual machines whose NAT resolves names on the host, or signing in to a captive portal; with `"misconfigtun"`, IPv4 or IPv6 on the local network while no route of that version leads to the TUN. Without the filters, DNS may leak as described above. To keep an IP version out of the TUN on purpose while still blocking DNS leaks, use only `["dns"]`. You can give the adapter ip address manually, you can live Windows to give it autogenerated ip address (which take few seconds), it doesn't matter, the traffic going _through_ the interface will be forwarded into the app for proxying. \ Minimal configuration that will work for local machine is routing passing the traffic on-link through the interface. diff --git a/proxy/tun/tun_windows.go b/proxy/tun/tun_windows.go index 0251293be..9c7ce9f37 100644 --- a/proxy/tun/tun_windows.go +++ b/proxy/tun/tun_windows.go @@ -248,13 +248,13 @@ startOver: // With autoSystemWfpBlockLeak, once the system routes lead to the TUN, // keep DNS ("dns", if dns is set), and an IP version no route of which - // leads to the TUN ("misconfig"), from leaving through the other + // leads to the TUN ("misconfigtun"), from leaving through the other // interfaces. Addresses do not matter: without one of a version in // gateway, Windows gives the TUN a link-local one. leaks := t.options.AutoSystemWfpBlockLeak blockDNS := slices.Contains(leaks, "dns") && len(dns) > 0 - blockIPv4 := slices.Contains(leaks, "misconfig") && !route4 - blockIPv6 := slices.Contains(leaks, "misconfig") && !route6 + blockIPv4 := slices.Contains(leaks, "misconfigtun") && !route4 + blockIPv6 := slices.Contains(leaks, "misconfigtun") && !route6 if (route4 || route6) && (blockDNS || blockIPv4 || blockIPv6) { if t.wfp, err = blockLeaks(t.luid, blockDNS, blockIPv4, blockIPv6); err != nil { var blocked []string