mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
fix: resolve DNS hijacking issues in redirect and tproxy modes
- Fix routing rule order: move specific dns-in:53→dns-out rule before the generic dns-in→direct rule to ensure DNS queries hit dns-out first - Fix transparent inbound DNS routing: change from direct+geoip:private to unconditional dns-out for port 53 in tproxy mode - Add warning log when CouldLocalDnsListen() fails (port 53 conflict)
This commit is contained in:
1 parent
186a463ea4
commit
d5ea5e41b2
1 file changed
+13
-6
@@ -413,14 +413,12 @@ func (t *Template) setDNSRouting(routing []coreObj.RoutingRule, supportUDP map[s
|
||||
isTinyTunMode := t.Setting != nil && t.Setting.TransparentType == configure.TransparentTun && IsTransparentOn(t.Setting)
|
||||
if !isTinyTunMode {
|
||||
t.Routing.Rules = append(t.Routing.Rules, routing...)
|
||||
t.Routing.Rules = append(t.Routing.Rules,
|
||||
coreObj.RoutingRule{Type: "field", InboundTag: []string{"dns-in"}, OutboundTag: "direct"},
|
||||
)
|
||||
}
|
||||
setting := t.Setting
|
||||
// DNS is always active: hijack port-53 traffic into dns-out
|
||||
if ShouldLocalDnsListen() {
|
||||
if couldListenLocalhost, _ := CouldLocalDnsListen(); couldListenLocalhost {
|
||||
// 先添加特定规则:DNS 端口 53 优先匹配 dns-out
|
||||
t.Routing.Rules = append(t.Routing.Rules, coreObj.RoutingRule{
|
||||
Type: "field",
|
||||
InboundTag: []string{"dns-in"},
|
||||
@@ -429,6 +427,12 @@ func (t *Template) setDNSRouting(routing []coreObj.RoutingRule, supportUDP map[s
|
||||
})
|
||||
}
|
||||
}
|
||||
// 后添加通用规则,排除 DNS 端口(避免通用规则抢在特定规则之前匹配)
|
||||
if !isTinyTunMode {
|
||||
t.Routing.Rules = append(t.Routing.Rules,
|
||||
coreObj.RoutingRule{Type: "field", InboundTag: []string{"dns-in"}, OutboundTag: "direct"},
|
||||
)
|
||||
}
|
||||
if !supportUDP[firstOutboundTag] {
|
||||
// find an outbound that supports UDP and redirect all leaky UDP traffic to it
|
||||
var found bool
|
||||
@@ -457,15 +461,16 @@ func (t *Template) setDNSRouting(routing []coreObj.RoutingRule, supportUDP map[s
|
||||
}
|
||||
} else {
|
||||
if IsTransparentOn(setting) {
|
||||
// TProxy 模式下,将透明代理入站的 DNS 流量无条件路由到 dns-out
|
||||
// 此规则在 setDNSRouting 中添加,早于 setTransparentRouting 的其他规则,因此优先匹配
|
||||
t.Routing.Rules = append(t.Routing.Rules,
|
||||
coreObj.RoutingRule{
|
||||
Type: "field",
|
||||
OutboundTag: "direct",
|
||||
OutboundTag: "dns-out",
|
||||
InboundTag: []string{
|
||||
"transparent",
|
||||
},
|
||||
Port: "53",
|
||||
IP: []string{"geoip:private"},
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1352,7 +1357,7 @@ func (t *Template) setInbound(setting *configure.Setting) error {
|
||||
|
||||
}
|
||||
if ShouldLocalDnsListen() {
|
||||
if couldListenLocalhost, _ := CouldLocalDnsListen(); couldListenLocalhost {
|
||||
if couldListenLocalhost, err := CouldLocalDnsListen(); couldListenLocalhost {
|
||||
// set up a solo dokodemo-door for dns
|
||||
t.Inbounds = append(t.Inbounds, coreObj.Inbound{
|
||||
Port: 53,
|
||||
@@ -1368,6 +1373,8 @@ func (t *Template) setInbound(setting *configure.Setting) error {
|
||||
},
|
||||
Tag: "dns-in",
|
||||
})
|
||||
} else {
|
||||
log.Warn("DNS hijack may be unavailable: cannot listen on port 53: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user