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