-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdnsbrute.go
98 lines (79 loc) · 1.92 KB
/
dnsbrute.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
/*
subdomain 0-4 chars bruteforce for discovering subdomains
*/
package main
import (
"bufio"
"context"
"flag"
"fmt"
"net"
"os"
"strconv"
"time"
)
func queryNS(subdomain, nameserver string, port int) ([]string, error) {
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10000),
}
return d.DialContext(ctx, network, nameserver+":"+strconv.Itoa(port))
},
}
return r.LookupHost(context.Background(), subdomain)
}
func process(c <-chan string, domain, nameserver string, port int) {
for dns := range c {
var addr []string
var err error
subd := dns + "." + domain
if nameserver == "" {
addr, err = net.LookupHost(subd)
} else {
addr, err = queryNS(subd, nameserver, port)
}
if err == nil {
fmt.Printf("%s %s\n", subd, addr)
} else {
fmt.Printf("%s \r", subd)
f := bufio.NewWriter(os.Stdout)
f.Write([]byte(subd + " "))
f.Write([]byte("\r"))
f.Flush()
}
}
}
func main() {
domain := flag.String("dom", "", "domain name ie: -dom test.com")
gorountines := flag.Int("go", 2, "number of concurrent goroutines")
nameserver := flag.String("ns", "", "specify the nameserver to query")
port := flag.Int("p", 53, "name-server port")
flag.Parse()
if *domain == "" {
fmt.Println("use -dom domain.com or -h")
os.Exit(1)
}
ch := make(chan string, 6)
for i := 0; i < *gorountines; i++ {
go process(ch, *domain, *nameserver, *port)
}
for a := int('a'); a <= int('z'); a++ {
ch <- string(a)
for b := int('a'); b <= int('z'); b++ {
ch <- string(a) + string(b)
for c := int('a'); c <= int('z'); c++ {
ch <- string(a) + string(b) + string(c)
for d := int('a'); d <= int('z'); d++ {
ch <- string(a) + string(b) + string(c) + string(d)
}
}
}
}
close(ch)
var i int
for {
fmt.Scanf("%d", &i)
}
}