fixes #123 - properly handle ConnectionSpecificDomain requests

fixes 117
This commit is contained in:
dovholuknf
2020-10-07 17:21:21 -04:00
parent 4e8466853d
commit 17fb8f7cfd
2 changed files with 11 additions and 10 deletions
+5 -7
View File
@@ -58,14 +58,12 @@ func processDNSquery(packet []byte, p *net.UDPAddr, s *net.UDPConn) {
if ip == nil {
// no direct hit. need to now check to see if the dns query used a connection-specific local domain
for _, d := range domains {
if strings.HasSuffix(dnsName, d) {
dnsNameTrimmed := strings.Trim(dnsName, d)
domain := d
if strings.HasSuffix(dnsName, domain) {
dnsNameTrimmed := strings.TrimRight(dnsName, domain)
// dns request has domain appended - removing and resolving
ip = DNS.Resolve(dnsNameTrimmed)
if ip != nil {
log.Debugf("DNS %s failed at first but succeeded by looking up %s", dnsName, dnsNameTrimmed)
break
}
break
}
}
}
@@ -282,7 +280,7 @@ func runDNSproxy(dnsServers []string) {
log.Tracef("proxy resolved %v from %v", reply.Question[0].Name, req.s.RemoteAddr())
req.s.WriteMsgUDP(rep, nil, req.peer)
} else {
log.Tracef("matching request was not found for ",
log.Tracef("matching request was not found for %s %s",
dns.Type(reply.Question[0].Qtype), reply.Question[0].Name)
}
}
+6 -3
View File
@@ -44,13 +44,14 @@ func ResetDNS() {
}
func GetConnectionSpecificDomains() []string {
script := `Get-DnsClient | Select-Object ConnectionSpecificSuffix | Get-Unique | ForEach-Object { $_.ConnectionSpecificSuffix }`
script := `Get-DnsClient | Select-Object ConnectionSpecificSuffix -Unique | ForEach-Object { $_.ConnectionSpecificSuffix }`
cmd := exec.Command("powershell", "-Command", script)
cmd.Stderr = os.Stdout
output := new(bytes.Buffer)
cmd.Stdout = output
log.Tracef("running powershell command to get ConnectionSpecificSuffixes: %s", script)
err := cmd.Run()
if err != nil {
@@ -64,8 +65,10 @@ func GetConnectionSpecificDomains() []string {
break
}
domain = strings.TrimSpace(domain)
if !strings.HasSuffix(domain, ".") {
names = append(names, domain + ".")
if "" != domain {
if !strings.HasSuffix(domain, ".") {
names = append(names, domain+".")
}
}
}
return names