-
Notifications
You must be signed in to change notification settings - Fork 23
/
bruteforce.go
70 lines (56 loc) · 1.19 KB
/
bruteforce.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
package sonar
import (
"fmt"
"net"
"sort"
"sync"
)
func BruteForce(threads int, wordlist <-chan string, domain string) Results {
results := make(Results, 0)
fmt.Println("[+] Detecting wildcard")
wildcard, responses, err := detectWildcard(domain)
if err != nil {
// TODO: Fail loudly
}
if wildcard {
fmt.Println("[+] Wildcard detected for domain")
wildcardResult := Result{
Domain: "*." + domain,
Addrs: keys(responses),
}
results = append(results, wildcardResult)
}
fmt.Println("[+] Beginning brute force attempt")
var wg sync.WaitGroup
for i := 0; i < threads; i++ {
wg.Add(1)
go func(wordlist <-chan string) {
nextWord:
for {
word, ok := <-wordlist
if !ok {
break
}
guess := word + "." + domain
answers, err := net.LookupHost(word + "." + domain)
if err != nil {
continue
}
if wildcard {
for _, answer := range answers {
if _, ok := responses[answer]; ok {
// it's a wildcard response
continue nextWord
}
}
}
result := Result{Domain: guess, Addrs: answers}
results = append(results, result)
}
wg.Done()
}(wordlist)
}
wg.Wait()
sort.Sort(results)
return results
}