MetaCubeX / mihomo

A simple Python Pydantic model for Honkai: Star Rail parsed data from the Mihomo API.
https://wiki.metacubex.one
MIT License
15.16k stars 2.52k forks source link

[Bug] Windows 环境下 mihomo 启用 Tun 模式无法劫持 IPv6 DNS 解析 #854

Closed Magic989 closed 9 months ago

Magic989 commented 9 months ago

Verify steps

Mihomo version

1.17.0

What OS are you seeing the problem on?

Windows

Mihomo config

port: 7890         # HTTP(s) 代理端口
socks-port: 7891   # SOCKS4/4a/5 代理端口
redir-port: 7892   # redirect 透明代理端口,仅能代理 TCP 流量, Linux macOS 使用
tproxy-port: 7893  # tproxy 透明代理端口,可代理 TCP 与 UDP 流量,仅 Linux 使用
mixed-port: 7894   # 同时支持 HTTP(s) 和 SOCKS5

allow-lan: true     # 允许局域网的连接
bind-address: "*"   # 仅当 `allow-lan` 为 `true` 时有效, '*': 绑定所有 IP 地址

mode: rule
log-level: error
ipv6: true
hosts:
  # sharepoint.com: 
external-controller: 0.0.0.0:9090
secret: ''

# 静态网页资源 (如 mihomo-dashboard) 放置在一个目录中, mihomo 将会服务于 `RESTful API/ui`
# 参数应填写配置目录的相对路径或绝对路径。
#external-ui: ./ui     # 将ui放到C:\Users\用户名\.config\mihomo目录下

clash-for-android:
  append-system-dns: false

profile:
  store-selected: true
  store-fake-ip: false

tcp-concurrent: true
unified-delay: true

sniffer:
  enable: true
  override-destination: true
  force-dns-mapping: true
  sniff:
    TLS:
      ports: [443, 853]
    #QUIC:
    #  ports: [443, 784, 853, 8853]
    HTTP:
      ports: [80, 8080-8880]

tun:
  enable: true
  stack: System
  device: Meta_Tun
  auto-detect-interface: true
  auto-route: true
  #strict-route: true         # 启用会导致 Windows 部分应用无法使用, 但是物理网卡没有任何 DNS 泄漏
  dns-hijack:
    - any:53
    - tcp://any:53

geodata-mode: true    # 开启 geodata 模式, 则可支持 V2Ray 的 .dat 文件
geox-url:             # 来源为 Loyalsoldier 整理的数据库
  geoip: "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geoip.dat"
  geosite: "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geosite.dat"
  mmdb: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/Country.mmdb"

dns:
  enable: true
  ipv6: true
  prefer-h3: true
  listen: 0.0.0.0:55553
  enhanced-mode: fake-ip
  fake-ip-filter:
    - "*.lan"
    - "*.localdomain"
    - "*.example"
    - "*.invalid"
    - "*.localhost"
    - "*.test"
    - "*.local"
    - "*.home.arpa"
    - time.*.com
    - time.*.gov
    - time.*.edu.cn
    - time.*.apple.com
    - time1.*.com
    - time2.*.com
    - time3.*.com
    - time4.*.com
    - time5.*.com
    - time6.*.com
    - time7.*.com
    - ntp.*.com
    - ntp1.*.com
    - ntp2.*.com
    - ntp3.*.com
    - ntp4.*.com
    - ntp5.*.com
    - ntp6.*.com
    - ntp7.*.com
    - "*.time.edu.cn"
    - "*.ntp.org.cn"
    - +.pool.ntp.org
    - time1.cloud.tencent.com
    - music.163.com
    - "*.music.163.com"
    - "*.126.net"
    - musicapi.taihe.com
    - music.taihe.com
    - songsearch.kugou.com
    - trackercdn.kugou.com
    - "*.kuwo.cn"
    - api-jooxtt.sanook.com
    - api.joox.com
    - joox.com
    - y.qq.com
    - "*.y.qq.com"
    - streamoc.music.tc.qq.com
    - mobileoc.music.tc.qq.com
    - isure.stream.qqmusic.qq.com
    - dl.stream.qqmusic.qq.com
    - aqqmusic.tc.qq.com
    - amobile.music.tc.qq.com
    - "*.xiami.com"
    - "*.music.migu.cn"
    - music.migu.cn
    - +.msftconnecttest.com
    - +.msftncsi.com
    - msftconnecttest.com
    - msftncsi.com
    - localhost.ptlogin2.qq.com
    - localhost.sec.qq.com
    - +.srv.nintendo.net
    - +.stun.playstation.net
    - xbox.*.microsoft.com
    - xnotify.xboxlive.com
    - +.ipv6.microsoft.com
    - +.battlenet.com.cn
    - +.wotgame.cn
    - +.wggames.cn
    - +.wowsgame.cn
    - +.wargaming.net
    - proxy.golang.org
    - stun.*.*
    - stun.*.*.*
    - +.stun.*.*
    - +.stun.*.*.*
    - +.stun.*.*.*.*
    - heartbeat.belkin.com
    - "*.linksys.com"
    - "*.linksyssmartwifi.com"
    - "*.router.asus.com"
    - mesu.apple.com
    - swscan.apple.com
    - swquery.apple.com
    - swdownload.apple.com
    - swcdn.apple.com
    - swdist.apple.com
    - lens.l.google.com
    - stun.l.google.com
    - "*.square-enix.com"
    - "*.finalfantasyxiv.com"
    - "*.ffxiv.com"
    - "*.ff14.sdo.com"
    - ff.dorado.sdo.com
    - "*.mcdn.bilivideo.cn"
    - +.media.dssott.com
    - +.pvp.net

  use-hosts: true

  nameserver:
    - 'https://223.5.5.5/dns-query'               # 阿里
    - 'https://1.12.12.12/dns-query'              # 腾讯
    - dhcp://en0
  proxy-server-nameserver:
    - 'https://223.5.5.5/dns-query'
    - 'https://1.12.12.12/dns-query'
  fallback:
    - 'https://cloudflare-dns.com/dns-query#📕 DNS'
    - 'https://dns.google/dns-query#📕 DNS'
    - 'https://cloudflare-dns.com/dns-query#🚀 节点选择'
    - 'https://dns.google/dns-query#🚀 节点选择'
  fallback-filter:
    geoip: true
    geoip-code: CN
    geosite: ['!cn']
    ipcidr:
      - 240.0.0.0/4
      - 0.0.0.0/32
      - 127.0.0.1/32
    domain:
      - '+.google.com'
      - '+.facebook.com'
      - '+.youtube.com'
      - '+.telegram.org'

Mihomo log

No response

Description

首先非常感谢大佬们恢复更新 mihomo, 这个工具对我来说非常重要, 这段日子我非常担心 mihomo 就此断更。

不设置系统代理,直接使用 powershell 在 Windows11 22H2 22621.2506 环境下运行内核,并且禁用 Windows 智能多宿主名称解析。 本地网络下发了 IPv6 地址 若将 tun.strict-route 设置为 true, 则不会发生 DNS 泄漏, 但会导致部分应用无法正常使用。 若不设置 tun.strict-route , 使用 wireshark 抓包, 发现应用程序往路由器设置的公共 IPv6 DNS 服务器发起大量 DNS 解析,如下图所示(本次抓包向 cf dns 发起请求, 有时候是阿里)。

另外我还有一个可有可无的功能请求:设置定时自动更新 geosite.dat Country.mmdb geoip.dat 只需更新数据库即可,不需要更新后重载配置文件,保证下次内核启动的时候数据库是最新的。 或者增加一个默认为 false 的配置项,设置为 true 后能在每次内核重启前重新下载 IP/domain 地理位置数据库(体验相对来说没有前一种好)。

感谢开发者们在百忙之中抽出时间听取我的建议😄。

sxnpu commented 9 months ago

”定时自动更新 geosite.dat Country.mmdb geoip.dat“ +1

dyhkwong commented 9 months ago

这是不启用 strict route 的预期行为,禁用智能多宿主名称解析在 Windows 10 之后不会起作用,可接受(但不完全可靠)的方法是阻止外部接口上的所有 UDP 53 端口流量。虽然会造成一些非期望的行为,strict route 被设计以 WFP 方式阻止 DNS 查询通过智能多宿主名称解析暴露给 ISP。如果不愿意启用 strict route,尝试把所有网络接口的 DNS 修改为公共 DNS。

Magic989 commented 9 months ago

这是不启用 strict route 的预期行为,禁用智能多宿主名称解析在 Windows 10 之后不会起作用,可接受(但不完全可靠)的方法是阻止外部接口上的所有 UDP 53 端口流量。虽然会造成一些非期望的行为,strict route 被设计以 WFP 方式阻止 DNS 查询通过智能多宿主名称解析暴露给 ISP。如果不愿意启用 strict route,尝试把所有网络接口的 DNS 修改为公共 DNS。

也就是说,禁用智能多宿主名称解析只对 IPv4 的 DNS 解析有效。如果设备有 IPv6 地址,那么应用程序还是会向所有网卡发出解析请求,这是 Windows 的硬伤。 我尝试过开关智能多宿主名称解析,发现开启前物理网卡有公共 IPv4 DNS 请求和公共 IPv6 DNS 请求;关闭后物理网卡的 IPv4 DNS 请求消失了,但公共 IPv6 DNS 请求还在。 修改物理接口的 IPv6 DNS 为公共 DNS,但物理网卡依旧检测到了请求。 目前看来想要在 Windows 上无泄漏使用 Tun 模式,必须有以下操作:

  1. 禁用智能多宿主名称解析
  2. 禁止 Windows 物理网卡获取 IPv6 地址
Kuingsmile commented 9 months ago

I have submitted a pull request for automatic geo file updates, and it has been merged.

Magic989 commented 9 months ago

I have submitted a pull request for automatic geo file updates, and it has been merged.

Thank you very much for your help. 😊