-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnsbrute.go
113 lines (97 loc) · 2.52 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"errors"
"fmt"
"net/http"
"os"
"os/exec"
"strings"
"time"
"github.com/fatih/color"
"github.com/miekg/dns"
)
func check_domain(testDomain string, dnsServer string, maxRetries int) (string, []string, error) {
var answer []dns.RR
var domain = ""
var ipAddress []string
m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(testDomain), dns.TypeA)
c := dns.Client{
Timeout: 10 * time.Second,
}
for i := 0; i < maxRetries; i++ {
in, _, err := c.Exchange(m, dnsServer)
answer = in.Answer
// comprueba si hay errores
if err != nil {
if strings.Contains(err.Error(), "missing") {
printError(err.Error())
os.Exit(1)
}
if strings.Contains(err.Error(), "timeout") {
continue
}
return domain, ipAddress, errors.New(err.Error())
} else {
// obtiene la direccion ip
if len(answer) > 0 {
for _, val := range answer {
// Asercion
if address, status := val.(*dns.A); status {
ipAddress = append(ipAddress, fmt.Sprint(address.A.String()))
domain = testDomain
}
}
} else {
// DOMAIN NOT EXIST
return domain, ipAddress, errors.New("NXDOMAIN")
}
}
break
}
return domain, ipAddress, nil
}
func saveFilePrint(content []string, file string) {
fmt.Printf("\n\n")
f, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
fmt.Printf("ERROR %s", err)
return
}
for i, v := range content {
var domain, ip, statusCode, pinger string
splitResult := strings.Split(v, ":")
domain, ip = splitResult[0], splitResult[1]
if len(splitResult) > 2 {
statusCode, pinger = splitResult[2], splitResult[3]
}
green := color.New(color.FgGreen).SprintFunc()
yellow := color.New(color.FgYellow).SprintFunc()
str := fmt.Sprintf("%s IP'S:[%s] StatusCode: %v Ping: %v\n", domain, ip, statusCode, pinger)
f.WriteString(str)
fmt.Printf("[ %v ] %v IP'S: [%v] StatusCode: %v Ping: %v\n", i, green(domain), yellow(ip), cyan(statusCode), cyan(pinger))
}
println()
}
func getStatusCode(domain string) (int, error) {
req, _ := http.NewRequest("GET", "http://"+domain, nil)
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0")
client := &http.Client{
Timeout: time.Second * 10,
}
resp, err := client.Do(req)
statusCode := resp.StatusCode
if err != nil {
return 0, err
} else {
return statusCode, nil
}
}
func checkPing(domain string) bool {
cmd := exec.Command("ping", "-c 1", "-W 2", domain)
_, err := cmd.Output()
if err != nil {
return false
}
return true
}