-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
165 lines (129 loc) · 4.42 KB
/
main.go
File metadata and controls
165 lines (129 loc) · 4.42 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main
import (
"errors"
"flag"
"log"
"os"
"submonitor/bots"
"submonitor/scanners"
"submonitor/utils"
)
/*
Subdomain monitor v1.0.6
by: xpl0ited1 (Bastian Muhlhauser)
24-02-2022
Last updated: 13-12-2022
*/
var (
targetsFilePath = utils.GetCurrentUserHome() + "/.config/submonitor/targets.txt"
configFilePath = utils.GetCurrentUserHome() + "/.config/submonitor/config.yaml"
subdomainsBrutePath = utils.GetCurrentUserHome() + "/.config/submonitor/brute.txt"
dnsTimeout = 5000
reportToARF = false
)
func main() {
currentUserHome := utils.GetCurrentUserHome()
targetsFilePathFlag := flag.String("t",
currentUserHome+"/.config/submonitor/targets.txt",
"path to the targets.txt file ",
)
configFilePathFlag := flag.String("c",
currentUserHome+"/.config/submonitor/config.yaml",
"path to the config.yaml file",
)
resolverFlag := flag.String("r", "", "dns server using for resolving subdomains. ex.: 8.8.8.8:53")
subdomainsBruteFlag := flag.String("w",
currentUserHome+"/.config/submonitor/brute.txt",
"path to the wordlists that will be used to bruteforce subdomains ")
bruteForceFlag := flag.Bool("b", false, "if specified the tool will try to bruteforce subdomains")
dnsTimeoutFlag := flag.Int("dt", 5000, "timeout for dns queries when bruteforcing")
reportToARFFlag := flag.Bool("arf", false, "if specified the tool will report the subdomains to ARF API")
flag.Parse()
targetsFilePath = *targetsFilePathFlag
configFilePath = *configFilePathFlag
subdomainsBrutePath = *subdomainsBruteFlag
dnsTimeout = *dnsTimeoutFlag
reportToARF = *reportToARFFlag
utils.Init(configFilePath)
checkFileExists(*bruteForceFlag, reportToARF)
doScan(*bruteForceFlag, *resolverFlag)
}
func checkFileExists(isBruteForcing, reportToARF bool) {
if !reportToARF {
if _, err := os.Stat(targetsFilePath); errors.Is(err, os.ErrNotExist) {
// path/to/whatever does not exist
log.Fatalf("%s does not exist", targetsFilePath)
}
}
if _, err := os.Stat(configFilePath); errors.Is(err, os.ErrNotExist) {
// path/to/whatever does not exist
log.Fatalf("%s does not exist", configFilePath)
}
if isBruteForcing {
if _, err := os.Stat(subdomainsBrutePath); errors.Is(err, os.ErrNotExist) {
// path/to/whatever does not exist
log.Fatalf("%s does not exist", subdomainsBrutePath)
}
}
}
func doScan(isBruteForcing bool, resolver string) {
//var wgDomains sync.WaitGroup
if reportToARF {
for _, domain := range utils.GetTargetsFromARF() {
scanWorker(isBruteForcing, resolver, domain.DomainName, domain)
}
} else {
for _, domain := range utils.ReadFile(targetsFilePath) {
// wgDomains.Add(1)
// go func() {
// defer wgDomains.Done()
scanWorker(isBruteForcing, resolver, domain, utils.ARFTarget{})
// }()
}
//wgDomains.Wait()
}
log.Println("[+] Done!")
}
func scanWorker(isBruteForcing bool, resolver string, domain string, arfTarget utils.ARFTarget) {
var subs []string
var resultsFilename = utils.GenerateFileName(domain)
//Scan for subdomains
subs = append(subs, scanners.GetHackertarget(domain)...)
if utils.GetConfig().SHODAN_APIKEY != "" {
subs = append(subs, scanners.GetShodan(domain)...)
}
if utils.GetConfig().SECTRAILS_APIKEY != "" {
subs = append(subs, scanners.GetSectrails(domain)...)
}
if isBruteForcing {
subs = append(subs, scanners.BruteForce(utils.ReadFile(subdomainsBrutePath), resolver, domain, dnsTimeout)...)
}
if utils.GetConfig().CENSYS_SECRET != "" && utils.GetConfig().CENSYS_API_ID != "" {
subs = append(subs, scanners.GetCensys(domain)...)
}
//--- Added on 23-Nov-2022 ---
subs = append(subs, scanners.GetDNSDumpster(domain)...)
//--- End of comment ---
//--- Added on 13-Dec-2022 ---
subs = append(subs, scanners.GetCrtSh(domain)...)
//--- End of comment ---
subs = utils.StripWithNoDomain(utils.Unique(utils.LowerSubs(subs)), domain)
//Load last results
last_results := utils.ReadResults(utils.GenerateFileNameAll(domain))
diff := utils.Difference(subs, last_results)
//Append last with new to make a whole file
allSubs := append(last_results, diff...)
allSubs = utils.Unique(allSubs)
//Replace last results with last+new
utils.SaveResults(utils.GenerateFileNameAll(domain), allSubs)
//Save new results
utils.SaveResults(resultsFilename, diff)
//Report with the bots
bots.Report(diff, domain)
if len(diff) > 0 {
bots.SendAttachments(resultsFilename)
}
if reportToARF {
utils.ExportResultsToArf(diff, domain, arfTarget.ID)
}
}