-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
168 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package sonar | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/hex" | ||
"fmt" | ||
"net" | ||
) | ||
|
||
func detectWildcard(domain string) (bool, map[string]struct{}, error) { | ||
bytes := make([]byte, 12) | ||
_, err := rand.Read(bytes) | ||
if err != nil { | ||
return false, nil, err | ||
} | ||
|
||
domain = fmt.Sprintf("%s.%s", hex.EncodeToString(bytes), domain) | ||
|
||
answers, err := net.LookupHost(domain) | ||
if err != nil { | ||
if asserted, ok := err.(*net.DNSError); ok && asserted.Err == "no such host" { | ||
return false, nil, nil | ||
} | ||
|
||
return false, nil, err | ||
} | ||
|
||
responses := make(map[string]struct{}) | ||
|
||
for _, answer := range answers { | ||
responses[answer] = struct{}{} | ||
} | ||
|
||
return true, responses, nil | ||
} | ||
|
||
func keys(set map[string]struct{}) []string { | ||
keys := make([]string, 0, len(set)) | ||
for key, _ := range set { | ||
keys = append(keys, key) | ||
} | ||
|
||
return keys | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package sonar | ||
|
||
import ( | ||
"log" | ||
"net" | ||
"strings" | ||
|
||
"github.com/miekg/dns" | ||
) | ||
|
||
func ZoneTransfer(domain string) Results { | ||
results := NewResultSet() | ||
fqdn := dns.Fqdn(domain) | ||
|
||
servers, err := net.LookupNS(domain) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for _, server := range servers { | ||
msg := new(dns.Msg) | ||
msg.SetAxfr(fqdn) | ||
|
||
transfer := new(dns.Transfer) | ||
answerChan, err := transfer.In(msg, net.JoinHostPort(server.Host, "53")) | ||
if err != nil { | ||
log.Println(err) | ||
continue | ||
} | ||
|
||
for envelope := range answerChan { | ||
if envelope.Error != nil { | ||
log.Println(envelope.Error) | ||
break | ||
} | ||
|
||
for _, rr := range envelope.RR { | ||
switch v := rr.(type) { | ||
case *dns.A: | ||
results.Add(strings.TrimRight(v.Header().Name, "."), v.A.String()) | ||
case *dns.AAAA: | ||
results.Add(strings.TrimRight(v.Header().Name, "."), v.AAAA.String()) | ||
default: | ||
} | ||
} | ||
} | ||
} | ||
|
||
return results.Results() | ||
} |