-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
130 lines (98 loc) · 2.44 KB
/
main.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net"
"os"
"strconv"
"strings"
"sync"
"time"
)
const (
version = "v1.0"
)
var (
domainFlag, fileNameListFlag, outputFileFlag string
currentTLDs []string
outputFile *os.File
err error
)
func init() {
flag.StringVar(&domainFlag, "d", "", "Domain")
flag.StringVar(&fileNameListFlag, "l", "", "TLD list json file (ex: cctld.json,tld.json)")
flag.StringVar(&outputFileFlag, "o", "out.txt", "Output file name")
}
func banner(totalTLD string) {
var str = `
| | | | | |
| |_| | __| |___ ___ __ _ _ __
| __| |/ _ / __|/ __/ _ | '_ \
| |_| | (_| \__ \ (_| (_| | | | |
\__|_|\__,_|___/\___\__,_|_| |_| ` + version
str += "\n\n Total TLDs to scan: " + totalTLD
str += "\n-------------------------------------"
fmt.Println(str)
}
func main() {
flag.Parse()
if len(domainFlag) <= 1 {
log.Fatal("Domain must be not empty")
}
fileNames := strings.Split(fileNameListFlag, ",")
for _, fileName := range fileNames {
list, err := openList(fileName)
if err != nil {
log.Fatal(err)
}
currentTLDs = append(currentTLDs, list...)
}
outputFile, err = os.OpenFile(outputFileFlag, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
log.Fatalf("output file opening error: %s", err)
}
totalTLDs := strconv.FormatInt(int64(len(currentTLDs)), 10)
banner(totalTLDs)
start := time.Now()
foundCount := 0
var wg sync.WaitGroup
wg.Add(len(currentTLDs))
for _, tld := range currentTLDs {
domain := domainFlag + "." + tld
go func() {
defer wg.Done()
_, err := net.LookupCNAME(domain)
if err == nil {
foundCount++
logFound(domain)
}
}()
}
wg.Wait()
elapsed := time.Since(start)
pwd, _ := os.Getwd()
outputFilePath := pwd + "/" + outputFileFlag
result := "Scan finished, scanner took %s, founded %d domain, output saved to %s\n"
fmt.Printf(result, elapsed, foundCount, outputFilePath)
}
func logFound(domain string) {
fmt.Printf("\033[1;32m[FOUND]\033[0m %s\n", domain)
_, err := outputFile.WriteString(domain + "\n")
if err != nil {
log.Fatalf("failed writing to file: %s", err)
}
}
func openList(fileName string) (list []string, err error) {
data, err := ioutil.ReadFile(fileName)
if err != nil {
return
}
err = json.Unmarshal(data, &list)
if err != nil {
return
}
return
}