/
dns_grabber.go
34 lines (29 loc) · 776 Bytes
/
dns_grabber.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package syn_scan
import (
"fmt"
"regexp"
"github.com/miekg/dns"
)
var chaosParser = regexp.MustCompile(`.*"([^"]+)".*`)
func grabChaos(addr string, q string) string {
c := new(dns.Client)
m := new(dns.Msg)
m.Question = make([]dns.Question, 1)
m.Question[0] = dns.Question{q, dns.TypeTXT, dns.ClassCHAOS}
if in, _, _ := c.Exchange(m, addr); in != nil && len(in.Answer) > 0 {
s := in.Answer[0].String()
if match := chaosParser.FindStringSubmatch(s); len(match) > 0 {
return match[1]
}
}
return ""
}
func dnsGrabber(mod *SynScanner, ip string, port int) string {
addr := fmt.Sprintf("%s:%d", ip, port)
if v := grabChaos(addr, "version.bind."); v != "" {
return v
} else if v := grabChaos(addr, "hostname.bind."); v != "" {
return v
}
return ""
}