-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
main.go
266 lines (245 loc) · 7.83 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// Copyright 2017 Jeff Foley. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
"os/signal"
"path"
//"runtime"
//"runtime/pprof"
"strings"
"syscall"
"time"
"github.com/OWASP/Amass/amass"
"github.com/OWASP/Amass/amass/utils"
"github.com/fatih/color"
)
var (
// Colors used to ease the reading of program output
y = color.New(color.FgHiYellow)
g = color.New(color.FgHiGreen)
r = color.New(color.FgHiRed)
b = color.New(color.FgHiBlue)
yellow = color.New(color.FgHiYellow).SprintFunc()
green = color.New(color.FgHiGreen).SprintFunc()
blue = color.New(color.FgHiBlue).SprintFunc()
// Command-line switches and provided parameters
help = flag.Bool("h", false, "Show the program usage message")
version = flag.Bool("version", false, "Print the version number of this amass binary")
ips = flag.Bool("ip", false, "Show the IP addresses for discovered names")
brute = flag.Bool("brute", false, "Execute brute forcing after searches")
active = flag.Bool("active", false, "Turn on active information gathering methods")
norecursive = flag.Bool("norecursive", false, "Turn off recursive brute forcing")
minrecursive = flag.Int("min-for-recursive", 0, "Number of subdomain discoveries before recursive brute forcing")
nodns = flag.Bool("nodns", false, "Disable DNS resolution of names and dependent features")
noalts = flag.Bool("noalts", false, "Disable generation of altered names")
verbose = flag.Bool("v", false, "Print the data source and summary information")
whois = flag.Bool("whois", false, "Include domains discoverd with reverse whois")
list = flag.Bool("l", false, "List all domains to be used in an enumeration")
freq = flag.Int64("freq", 0, "Sets the number of max DNS queries per minute")
wordlist = flag.String("w", "", "Path to a different wordlist file")
allpath = flag.String("oA", "", "Path prefix used for naming all output files")
logpath = flag.String("log", "", "Path to the log file where errors will be written")
outpath = flag.String("o", "", "Path to the text output file")
jsonpath = flag.String("json", "", "Path to the JSON output file")
visjspath = flag.String("visjs", "", "Path to the Visjs output HTML file")
graphistrypath = flag.String("graphistry", "", "Path to the Graphistry JSON file")
gexfpath = flag.String("gexf", "", "Path to the Gephi Graph Exchange XML Format (GEXF) file")
d3path = flag.String("d3", "", "Path to the D3 v4 force simulation HTML file")
domainspath = flag.String("df", "", "Path to a file providing root domain names")
resolvepath = flag.String("rf", "", "Path to a file providing preferred DNS resolvers")
blacklistpath = flag.String("blf", "", "Path to a file providing blacklisted subdomains")
neo4j = flag.String("neo4j", "", "URL in the format of user:password@address:port")
)
func main() {
var domains, resolvers, blacklist parseStrings
defaultBuf := new(bytes.Buffer)
flag.CommandLine.SetOutput(defaultBuf)
flag.Var(&domains, "d", "Domain names separated by commas (can be used multiple times)")
flag.Var(&resolvers, "r", "IP addresses of preferred DNS resolvers (can be used multiple times)")
flag.Var(&blacklist, "bl", "Blacklist of subdomain names that will not be investigated")
flag.Parse()
// Some input validation
if *help {
PrintBanner()
g.Printf("Usage: %s [options] <-d domain>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
g.Println(defaultBuf.String())
return
}
if *version {
fmt.Printf("version %s\n", amass.Version)
return
}
if *nodns && *ips {
r.Println("IP addresses cannot be provided without DNS resolution")
return
}
var words []string
// Obtain parameters from provided files
if *wordlist != "" {
words = GetLinesFromFile(*wordlist)
}
if *domainspath != "" {
domains = utils.UniqueAppend(domains, GetLinesFromFile(*domainspath)...)
}
if *resolvepath != "" {
resolvers = utils.UniqueAppend(resolvers, GetLinesFromFile(*resolvepath)...)
}
if *blacklistpath != "" {
blacklist = utils.UniqueAppend(blacklist, GetLinesFromFile(*blacklistpath)...)
}
// Prepare output files
logfile := *logpath
txt := *outpath
jsonfile := *jsonpath
d3 := *d3path
visjs := *visjspath
gexf := *gexfpath
graphistry := *graphistrypath
if *allpath != "" {
logfile = *allpath + ".log"
txt = *allpath + ".txt"
jsonfile = *allpath + ".json"
d3 = *allpath + "_d3.html"
visjs = *allpath + "_visjs.html"
gexf = *allpath + ".gexf"
graphistry = *allpath + "_graphistry.json"
}
// Seed the default pseudo-random number generator
rand.Seed(time.Now().UTC().UnixNano())
done := make(chan struct{})
results := make(chan *amass.AmassOutput, 100)
// Execute the signal handler
go CatchSignals(results, done)
// Setup the amass configuration
alts := true
recursive := true
if *noalts {
alts = false
}
if *norecursive {
recursive = false
}
enum := &amass.Enumeration{
Log: log.New(ioutil.Discard, "", 0),
Whois: *whois,
Wordlist: words,
BruteForcing: *brute,
Recursive: recursive,
MinForRecursive: *minrecursive,
Active: *active,
Alterations: alts,
NoDNS: *nodns,
Frequency: FreqToDuration(*freq),
Resolvers: resolvers,
Blacklist: blacklist,
Neo4jPath: *neo4j,
Output: results,
}
for _, domain := range domains {
enum.AddDomain(domain)
}
// Setup the log file for saving error messages
if logfile != "" {
fileptr, err := os.OpenFile(logfile, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
r.Printf("Failed to open the log file: %v", err)
return
}
defer func() {
fileptr.Sync()
fileptr.Close()
}()
enum.Log = log.New(fileptr, "", log.Lmicroseconds)
}
enum.ObtainAdditionalDomains()
if *list {
ListDomains(enum, txt)
return
}
// Can an enumeration be performed with the provided parameters?
if len(enum.Domains()) == 0 {
r.Println("No root domain names were provided or discovered")
return
}
go ManageOutput(&OutputParams{
Enum: enum,
Verbose: *verbose,
PrintIPs: *ips,
FileOut: txt,
JSONOut: jsonfile,
VisjsOut: visjs,
GraphistryOut: graphistry,
GEXFOut: gexf,
D3Out: d3,
Done: done,
})
err := enum.Start()
if err != nil {
r.Println(err)
return
}
//profFile, _ := os.Create("amass_mem.prof")
//defer profFile.Close()
//runtime.GC()
//pprof.WriteHeapProfile(profFile)
// Wait for output manager to finish
<-done
}
// If the user interrupts the program, print the summary information
func CatchSignals(output chan *amass.AmassOutput, done chan struct{}) {
sigs := make(chan os.Signal, 2)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
// Wait for a signal
<-sigs
// Start final output operations
close(output)
// Wait for the broadcast indicating completion
<-done
os.Exit(1)
}
func GetLinesFromFile(path string) []string {
var lines []string
// Open the file
file, err := os.Open(path)
if err != nil {
fmt.Printf("Error opening the file %s: %v\n", path, err)
return lines
}
defer file.Close()
// Get each line from the file
scanner := bufio.NewScanner(file)
for scanner.Scan() {
// Get the next line
text := scanner.Text()
if text != "" {
lines = append(lines, strings.TrimSpace(text))
}
}
return lines
}
func FreqToDuration(freq int64) time.Duration {
if freq > 0 {
d := time.Duration(freq)
if d < 60 {
// We are dealing with number of seconds
return (60 / d) * time.Second
}
// Make it times per second
d = d / 60
m := 1000 / d
if d < 1000 && m > 1 {
return m * time.Millisecond
}
}
// Use the default rate
return amass.DefaultFrequency
}