Avoid hijack DNS requests send to loopback
This commit is contained in:
parent
625ac412bb
commit
c01b403a44
1 changed files with 61 additions and 42 deletions
|
|
@ -537,10 +537,7 @@ func (r *autoRedirect) nftablesCreateDNSHijackRulesForFamily(
|
|||
dnsServer = r.tunOptions.Inet6Address[0].Addr().Next()
|
||||
}
|
||||
}
|
||||
nft.AddRule(&nftables.Rule{
|
||||
Table: table,
|
||||
Chain: chain,
|
||||
Exprs: []expr.Any{
|
||||
exprs := []expr.Any{
|
||||
&expr.Meta{
|
||||
Key: expr.MetaKeyNFPROTO,
|
||||
Register: 1,
|
||||
|
|
@ -550,6 +547,24 @@ func (r *autoRedirect) nftablesCreateDNSHijackRulesForFamily(
|
|||
Register: 1,
|
||||
Data: []byte{uint8(family)},
|
||||
},
|
||||
}
|
||||
if chain.Hooknum == nftables.ChainHookOutput {
|
||||
// It looks like we can't hijack DNS requests sent to loopback.
|
||||
// https://serverfault.com/questions/363899/iptables-dnat-from-loopback
|
||||
// and tproxy is not available in output
|
||||
exprs = append(exprs,
|
||||
&expr.Meta{
|
||||
Key: expr.MetaKeyOIFNAME,
|
||||
Register: 1,
|
||||
},
|
||||
&expr.Cmp{
|
||||
Op: expr.CmpOpNeq,
|
||||
Register: 1,
|
||||
Data: nftablesIfname("lo"),
|
||||
},
|
||||
)
|
||||
}
|
||||
exprs = append(exprs,
|
||||
&expr.Meta{
|
||||
Key: expr.MetaKeyL4PROTO,
|
||||
Register: 1,
|
||||
|
|
@ -571,7 +586,6 @@ func (r *autoRedirect) nftablesCreateDNSHijackRulesForFamily(
|
|||
Register: 1,
|
||||
Data: binaryutil.BigEndian.PutUint16(53),
|
||||
},
|
||||
&expr.Counter{},
|
||||
&expr.Immediate{
|
||||
Register: 1,
|
||||
Data: dnsServer.AsSlice(),
|
||||
|
|
@ -581,7 +595,12 @@ func (r *autoRedirect) nftablesCreateDNSHijackRulesForFamily(
|
|||
Family: uint32(family),
|
||||
RegAddrMin: 1,
|
||||
},
|
||||
},
|
||||
&expr.Counter{},
|
||||
)
|
||||
nft.AddRule(&nftables.Rule{
|
||||
Table: table,
|
||||
Chain: chain,
|
||||
Exprs: exprs,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue