forked from manasmbellani/subjack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns.go
110 lines (91 loc) · 2.04 KB
/
dns.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package subjack
import (
"fmt"
"net"
"strings"
"github.com/haccer/available"
"github.com/miekg/dns"
)
func (s *Subdomain) dns(o *Options) {
config := o.Fingerprints
if o.All {
detect(s.Url, o.Output, o.Ssl, o.Verbose, o.Manual, o.Timeout, config)
} else {
if VerifyCNAME(s.Url, config) {
detect(s.Url, o.Output, o.Ssl, o.Verbose, o.Manual, o.Timeout, config)
}
if o.Verbose {
result := fmt.Sprintf("[Not Vulnerable] %s\n", s.Url)
c := "\u001b[31;1mNot Vulnerable\u001b[0m"
out := strings.Replace(result, "Not Vulnerable", c, -1)
fmt.Printf(out)
if o.Output != "" {
if chkJSON(o.Output) {
writeJSON("", s.Url, o.Output)
} else {
write(result, o.Output)
}
}
}
}
}
func resolve(url string) (cname string) {
cname = ""
d := new(dns.Msg)
d.SetQuestion(url+".", dns.TypeCNAME)
ret, err := dns.Exchange(d, "8.8.8.8:53")
if err != nil {
return
}
for _, a := range ret.Answer {
if t, ok := a.(*dns.CNAME); ok {
cname = t.Target
}
}
return cname
}
func nslookup(domain string) (nameservers []string) {
m := new(dns.Msg)
m.SetQuestion(dotDomain(domain), dns.TypeNS)
ret, err := dns.Exchange(m, "8.8.8.8:53")
if err != nil {
return
}
nameservers = []string{}
for _, a := range ret.Answer {
if t, ok := a.(*dns.NS); ok {
nameservers = append(nameservers, t.Ns)
}
}
return nameservers
}
func nxdomain(nameserver string) bool {
if _, err := net.LookupHost(nameserver); err != nil {
if strings.Contains(fmt.Sprintln(err), "no such host") {
return true
}
}
return false
}
func NS(domain, output string, verbose bool) {
nameservers := nslookup(domain)
for _, ns := range nameservers {
if verbose {
msg := fmt.Sprintf("[*] %s: Nameserver is %s\n", domain, ns)
fmt.Printf(msg)
if output != "" {
write(msg, output)
}
}
if nxdomain(ns) {
av := available.Domain(ns)
if av {
msg := fmt.Sprintf("[!] %s's nameserver: %s is available for purchase!\n", domain, ns)
fmt.Printf(msg)
if output != "" {
write(msg, output)
}
}
}
}
}