forked from owasp-amass/amass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum.go
749 lines (673 loc) · 23.1 KB
/
enum.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
// 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"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
"os/signal"
"path/filepath"
"regexp"
"strings"
"sync"
"syscall"
"time"
"github.com/OWASP/Amass/v3/config"
"github.com/OWASP/Amass/v3/datasrcs"
"github.com/OWASP/Amass/v3/enum"
"github.com/OWASP/Amass/v3/format"
"github.com/OWASP/Amass/v3/requests"
"github.com/OWASP/Amass/v3/stringfilter"
"github.com/OWASP/Amass/v3/stringset"
"github.com/OWASP/Amass/v3/systems"
"github.com/fatih/color"
)
const (
enumUsageMsg = "enum [options] -d DOMAIN"
)
var interrupted bool
type enumArgs struct {
Addresses format.ParseIPs
ASNs format.ParseInts
CIDRs format.ParseCIDRs
AltWordList stringset.Set
AltWordListMask stringset.Set
BruteWordList stringset.Set
BruteWordListMask stringset.Set
Blacklist stringset.Set
Domains stringset.Set
Excluded stringset.Set
Included stringset.Set
MaxDNSQueries int
MinForRecursive int
Names stringset.Set
Ports format.ParseInts
Resolvers stringset.Set
Timeout int
Options struct {
Active bool
BruteForcing bool
DemoMode bool
IPs bool
IPv4 bool
IPv6 bool
ListSources bool
MonitorResolverRate bool
NoAlts bool
NoColor bool
NoLocalDatabase bool
NoRecursive bool
Passive bool
Silent bool
Sources bool
Verbose bool
}
Filepaths struct {
AllFilePrefix string
AltWordlist format.ParseStrings
Blacklist string
BruteWordlist format.ParseStrings
ConfigFile string
Directory string
Domains format.ParseStrings
ExcludedSrcs string
IncludedSrcs string
JSONOutput string
LogFile string
Names format.ParseStrings
Resolvers format.ParseStrings
TermOut string
}
}
func defineEnumArgumentFlags(enumFlags *flag.FlagSet, args *enumArgs) {
enumFlags.Var(&args.Addresses, "addr", "IPs and ranges (192.168.1.1-254) separated by commas")
enumFlags.Var(&args.AltWordListMask, "awm", "\"hashcat-style\" wordlist masks for name alterations")
enumFlags.Var(&args.ASNs, "asn", "ASNs separated by commas (can be used multiple times)")
enumFlags.Var(&args.CIDRs, "cidr", "CIDRs separated by commas (can be used multiple times)")
enumFlags.Var(&args.Blacklist, "bl", "Blacklist of subdomain names that will not be investigated")
enumFlags.Var(&args.BruteWordListMask, "wm", "\"hashcat-style\" wordlist masks for DNS brute forcing")
enumFlags.Var(&args.Domains, "d", "Domain names separated by commas (can be used multiple times)")
enumFlags.Var(&args.Excluded, "exclude", "Data source names separated by commas to be excluded")
enumFlags.Var(&args.Included, "include", "Data source names separated by commas to be included")
enumFlags.IntVar(&args.MaxDNSQueries, "max-dns-queries", 0, "Maximum number of concurrent DNS queries")
enumFlags.IntVar(&args.MinForRecursive, "min-for-recursive", 1, "Subdomain labels seen before recursive brute forcing")
enumFlags.Var(&args.Ports, "p", "Ports separated by commas (default: 443)")
enumFlags.Var(&args.Resolvers, "r", "IP addresses of preferred DNS resolvers (can be used multiple times)")
enumFlags.IntVar(&args.Timeout, "timeout", 0, "Number of minutes to let enumeration run before quitting")
}
func defineEnumOptionFlags(enumFlags *flag.FlagSet, args *enumArgs) {
enumFlags.BoolVar(&args.Options.Active, "active", false, "Attempt zone transfers and certificate name grabs")
enumFlags.BoolVar(&args.Options.BruteForcing, "brute", false, "Execute brute forcing after searches")
enumFlags.BoolVar(&args.Options.DemoMode, "demo", false, "Censor output to make it suitable for demonstrations")
enumFlags.BoolVar(&args.Options.IPs, "ip", false, "Show the IP addresses for discovered names")
enumFlags.BoolVar(&args.Options.IPv4, "ipv4", false, "Show the IPv4 addresses for discovered names")
enumFlags.BoolVar(&args.Options.IPv6, "ipv6", false, "Show the IPv6 addresses for discovered names")
enumFlags.BoolVar(&args.Options.ListSources, "list", false, "Print the names of all available data sources")
enumFlags.BoolVar(&args.Options.MonitorResolverRate, "noresolvrate", true, "Disable resolver rate monitoring")
enumFlags.BoolVar(&args.Options.NoAlts, "noalts", false, "Disable generation of altered names")
enumFlags.BoolVar(&args.Options.NoColor, "nocolor", false, "Disable colorized output")
enumFlags.BoolVar(&args.Options.NoLocalDatabase, "nolocaldb", false, "Disable saving data into a local database")
enumFlags.BoolVar(&args.Options.NoRecursive, "norecursive", false, "Turn off recursive brute forcing")
enumFlags.BoolVar(&args.Options.Passive, "passive", false, "Disable DNS resolution of names and dependent features")
enumFlags.BoolVar(&args.Options.Silent, "silent", false, "Disable all output during execution")
enumFlags.BoolVar(&args.Options.Sources, "src", false, "Print data sources for the discovered names")
enumFlags.BoolVar(&args.Options.Verbose, "v", false, "Output status / debug / troubleshooting info")
}
func defineEnumFilepathFlags(enumFlags *flag.FlagSet, args *enumArgs) {
enumFlags.StringVar(&args.Filepaths.AllFilePrefix, "oA", "", "Path prefix used for naming all output files")
enumFlags.Var(&args.Filepaths.AltWordlist, "aw", "Path to a different wordlist file for alterations")
enumFlags.StringVar(&args.Filepaths.Blacklist, "blf", "", "Path to a file providing blacklisted subdomains")
enumFlags.Var(&args.Filepaths.BruteWordlist, "w", "Path to a different wordlist file")
enumFlags.StringVar(&args.Filepaths.ConfigFile, "config", "", "Path to the INI configuration file. Additional details below")
enumFlags.StringVar(&args.Filepaths.Directory, "dir", "", "Path to the directory containing the output files")
enumFlags.Var(&args.Filepaths.Domains, "df", "Path to a file providing root domain names")
enumFlags.StringVar(&args.Filepaths.ExcludedSrcs, "ef", "", "Path to a file providing data sources to exclude")
enumFlags.StringVar(&args.Filepaths.IncludedSrcs, "if", "", "Path to a file providing data sources to include")
enumFlags.StringVar(&args.Filepaths.JSONOutput, "json", "", "Path to the JSON output file")
enumFlags.StringVar(&args.Filepaths.LogFile, "log", "", "Path to the log file where errors will be written")
enumFlags.Var(&args.Filepaths.Names, "nf", "Path to a file providing already known subdomain names (from other tools/sources)")
enumFlags.Var(&args.Filepaths.Resolvers, "rf", "Path to a file providing preferred DNS resolvers")
enumFlags.StringVar(&args.Filepaths.TermOut, "o", "", "Path to the text file containing terminal stdout/stderr")
}
func runEnumCommand(clArgs []string) {
// Seed the default pseudo-random number generator
rand.Seed(time.Now().UTC().UnixNano())
// Extract the correct config from the user provided arguments and/or configuration file
cfg, args := argsAndConfig(clArgs)
if cfg == nil {
return
}
createOutputDirectory(cfg)
rLog, wLog := io.Pipe()
// Setup logging so that messages can be written to the file and used by the program
cfg.Log = log.New(wLog, "", log.Lmicroseconds)
logfile := filepath.Join(config.OutputDirectory(cfg.Dir), "amass.log")
if args.Filepaths.LogFile != "" {
logfile = args.Filepaths.LogFile
}
// Start handling the log messages
go writeLogsAndMessages(rLog, logfile, args.Options.Verbose)
// Create the System that will provide architecture to this enumeration
sys, err := systems.NewLocalSystem(cfg)
if err != nil {
r.Fprintf(color.Error, "%v\n", err)
os.Exit(1)
}
sys.SetDataSources(datasrcs.GetAllSources(sys))
// Setup the new enumeration
e := enum.NewEnumeration(cfg, sys)
if e == nil {
r.Fprintf(color.Error, "%s\n", "Failed to setup the enumeration")
os.Exit(1)
}
defer e.Close()
var wg sync.WaitGroup
var outChans []chan *requests.Output
// This channel sends the signal for goroutines to terminate
done := make(chan struct{})
wg.Add(1)
// This goroutine will handle printing the output
printOutChan := make(chan *requests.Output, 1000)
go printOutput(e, args, printOutChan, &wg)
outChans = append(outChans, printOutChan)
wg.Add(1)
// This goroutine will handle saving the output to the text file
txtOutChan := make(chan *requests.Output, 1000)
go saveTextOutput(e, args, txtOutChan, &wg)
outChans = append(outChans, txtOutChan)
if !args.Options.Passive {
wg.Add(1)
// This goroutine will handle saving the output to the JSON file
jsonOutChan := make(chan *requests.Output, 1000)
go saveJSONOutput(e, args, jsonOutChan, &wg)
outChans = append(outChans, jsonOutChan)
}
wg.Add(1)
go processOutput(e, outChans, done, &wg)
go signalHandler(e)
// Start the enumeration process
if err := e.Start(); err != nil {
r.Println(err)
os.Exit(1)
}
// Let all the goroutines know that the enumeration has finished
close(done)
wg.Wait()
// If necessary, handle graph database migration
if !interrupted && !cfg.Passive && len(e.Sys.GraphDatabases()) > 0 {
fmt.Fprintf(color.Error, "\n%s\n", green("The enumeration has finished"))
// Copy the graph of findings into the system graph databases
for _, g := range e.Sys.GraphDatabases() {
fmt.Fprintf(color.Error, "%s%s%s\n",
yellow("Discoveries are being migrated into the "), yellow(g.String()), yellow(" database"))
if err := e.Graph.MigrateEvent(e.Config.UUID.String(), g); err != nil {
fmt.Fprintf(color.Error, "%s%s%s%s\n",
red("The database migration to "), red(g.String()), red(" failed: "), red(err.Error()))
}
}
}
}
func argsAndConfig(clArgs []string) (*config.Config, *enumArgs) {
args := enumArgs{
AltWordList: stringset.New(),
AltWordListMask: stringset.New(),
BruteWordList: stringset.New(),
BruteWordListMask: stringset.New(),
Blacklist: stringset.New(),
Domains: stringset.New(),
Excluded: stringset.New(),
Included: stringset.New(),
Names: stringset.New(),
Resolvers: stringset.New(),
}
var help1, help2 bool
enumCommand := flag.NewFlagSet("enum", flag.ContinueOnError)
enumBuf := new(bytes.Buffer)
enumCommand.SetOutput(enumBuf)
enumCommand.BoolVar(&help1, "h", false, "Show the program usage message")
enumCommand.BoolVar(&help2, "help", false, "Show the program usage message")
defineEnumArgumentFlags(enumCommand, &args)
defineEnumOptionFlags(enumCommand, &args)
defineEnumFilepathFlags(enumCommand, &args)
if len(clArgs) < 1 {
commandUsage(enumUsageMsg, enumCommand, enumBuf)
return nil, &args
}
if err := enumCommand.Parse(clArgs); err != nil {
r.Fprintf(color.Error, "%v\n", err)
os.Exit(1)
}
if help1 || help2 {
commandUsage(enumUsageMsg, enumCommand, enumBuf)
return nil, &args
}
// Check if the user has requested the data source names
if args.Options.ListSources {
for _, name := range GetAllSourceNames() {
g.Println(name)
}
return nil, &args
}
if args.Options.NoColor {
color.NoColor = true
}
if args.Options.Silent {
color.Output = ioutil.Discard
color.Error = ioutil.Discard
}
if len(args.AltWordListMask) > 0 {
args.AltWordList.Union(args.AltWordListMask)
}
if len(args.BruteWordListMask) > 0 {
args.BruteWordList.Union(args.BruteWordListMask)
}
// Some input validation
if args.Options.Passive && (args.Options.IPs || args.Options.IPv4 || args.Options.IPv6) {
r.Fprintln(color.Error, "IP addresses cannot be provided without DNS resolution")
os.Exit(1)
}
if args.Options.Passive && args.Options.BruteForcing {
r.Fprintln(color.Error, "Brute forcing cannot be performed without DNS resolution")
os.Exit(1)
}
if (len(args.Excluded) > 0 || args.Filepaths.ExcludedSrcs != "") &&
(len(args.Included) > 0 || args.Filepaths.IncludedSrcs != "") {
commandUsage(enumUsageMsg, enumCommand, enumBuf)
os.Exit(1)
}
if err := processEnumInputFiles(&args); err != nil {
fmt.Fprintf(color.Error, "%v\n", err)
os.Exit(1)
}
cfg := config.NewConfig()
// Check if a configuration file was provided, and if so, load the settings
if err := config.AcquireConfig(args.Filepaths.Directory, args.Filepaths.ConfigFile, cfg); err == nil {
// Check if a config file was provided that has DNS resolvers specified
if len(cfg.Resolvers) > 0 && len(args.Resolvers) == 0 {
args.Resolvers = stringset.New(cfg.Resolvers...)
}
} else if args.Filepaths.ConfigFile != "" {
r.Fprintf(color.Error, "Failed to load the configuration file: %v\n", err)
os.Exit(1)
}
// Override configuration file settings with command-line arguments
if err := cfg.UpdateConfig(args); err != nil {
r.Fprintf(color.Error, "Configuration error: %v\n", err)
os.Exit(1)
}
return cfg, &args
}
func printOutput(e *enum.Enumeration, args *enumArgs, output chan *requests.Output, wg *sync.WaitGroup) {
defer wg.Done()
var total int
tags := make(map[string]int)
asns := make(map[int]*format.ASNSummaryData)
// Print all the output returned by the enumeration
for out := range output {
out.Addresses = format.DesiredAddrTypes(out.Addresses, args.Options.IPv4, args.Options.IPv6)
if !e.Config.Passive && len(out.Addresses) <= 0 {
continue
}
total++
if !args.Options.Passive {
format.UpdateSummaryData(out, tags, asns)
}
source, name, ips := format.OutputLineParts(out, args.Options.Sources,
args.Options.IPs || args.Options.IPv4 || args.Options.IPv6, args.Options.DemoMode)
if ips != "" {
ips = " " + ips
}
fmt.Fprintf(color.Output, "%s%s%s\n", blue(source), green(name), yellow(ips))
}
if total == 0 {
r.Println("No names were discovered")
} else if !args.Options.Passive {
format.PrintEnumerationSummary(total, tags, asns, args.Options.DemoMode)
}
}
func saveTextOutput(e *enum.Enumeration, args *enumArgs, output chan *requests.Output, wg *sync.WaitGroup) {
defer wg.Done()
dir := config.OutputDirectory(e.Config.Dir)
txtfile := filepath.Join(dir, "amass.txt")
if args.Filepaths.TermOut != "" {
txtfile = args.Filepaths.TermOut
}
if args.Filepaths.AllFilePrefix != "" {
txtfile = args.Filepaths.AllFilePrefix + ".txt"
}
if txtfile == "" {
return
}
outptr, err := os.OpenFile(txtfile, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
r.Fprintf(color.Error, "Failed to open the text output file: %v\n", err)
os.Exit(1)
}
defer func() {
outptr.Sync()
outptr.Close()
}()
outptr.Truncate(0)
outptr.Seek(0, 0)
// Save all the output returned by the enumeration
for out := range output {
out.Addresses = format.DesiredAddrTypes(out.Addresses, args.Options.IPv4, args.Options.IPv6)
if !e.Config.Passive && len(out.Addresses) <= 0 {
continue
}
source, name, ips := format.OutputLineParts(out, args.Options.Sources,
args.Options.IPs || args.Options.IPv4 || args.Options.IPv6, args.Options.DemoMode)
if ips != "" {
ips = " " + ips
}
// Write the line to the output file
fmt.Fprintf(outptr, "%s%s%s\n", source, name, ips)
}
}
func saveJSONOutput(e *enum.Enumeration, args *enumArgs, output chan *requests.Output, wg *sync.WaitGroup) {
defer wg.Done()
dir := config.OutputDirectory(e.Config.Dir)
jsonfile := filepath.Join(dir, "amass.json")
if args.Filepaths.JSONOutput != "" {
jsonfile = args.Filepaths.JSONOutput
}
if args.Filepaths.AllFilePrefix != "" {
jsonfile = args.Filepaths.AllFilePrefix + ".json"
}
if jsonfile == "" {
return
}
jsonptr, err := os.OpenFile(jsonfile, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
r.Fprintf(color.Error, "Failed to open the JSON output file: %v\n", err)
os.Exit(1)
}
defer func() {
jsonptr.Sync()
jsonptr.Close()
}()
jsonptr.Truncate(0)
jsonptr.Seek(0, 0)
enc := json.NewEncoder(jsonptr)
// Save all the output returned by the enumeration
for out := range output {
// Handle encoding the result as JSON
enc.Encode(out)
}
}
func processOutput(e *enum.Enumeration, outputs []chan *requests.Output, done chan struct{}, wg *sync.WaitGroup) {
defer wg.Done()
// This filter ensures that we only get new names
known := stringfilter.NewBloomFilter(1 << 24)
// The function that obtains output from the enum and puts it on the channel
extract := func() {
for _, o := range e.ExtractOutput(known) {
if !e.Config.IsDomainInScope(o.Name) {
continue
}
for _, ch := range outputs {
ch <- o
}
}
}
t := time.NewTimer(15 * time.Second)
loop:
for {
select {
case <-done:
break loop
case <-t.C:
if e.Config.Passive {
continue loop
}
started := time.Now()
extract()
next := time.Now().Sub(started) * 5
if next < 3*time.Second {
next = 3 * time.Second
}
t.Reset(next)
}
}
// Check one last time
extract()
// Signal all the other goroutines to terminate
for _, ch := range outputs {
close(ch)
}
}
// If the user interrupts the program, print the summary information
func signalHandler(e *enum.Enumeration) {
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
<-quit
interrupted = true
// Signal the enumeration to finish
e.Done()
// Wait for output operations to complete
time.Sleep(5 * time.Second)
os.Exit(1)
}
func writeLogsAndMessages(logs *io.PipeReader, logfile string, verbose bool) {
wildcard := regexp.MustCompile("DNS wildcard")
avg := regexp.MustCompile("Average DNS queries")
rScore := regexp.MustCompile("Resolver .* has a low score")
alterations := regexp.MustCompile("queries for altered names")
brute := regexp.MustCompile("queries for brute forcing")
sanity := regexp.MustCompile("SanityChecks")
queries := regexp.MustCompile("Querying")
var filePtr *os.File
if logfile != "" {
var err error
filePtr, err = os.OpenFile(logfile, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
r.Fprintf(color.Error, "Failed to open the log file: %v\n", err)
} else {
defer func() {
filePtr.Sync()
filePtr.Close()
}()
filePtr.Truncate(0)
filePtr.Seek(0, 0)
}
}
scanner := bufio.NewScanner(logs)
for scanner.Scan() {
line := scanner.Text()
if err := scanner.Err(); err != nil {
fmt.Fprintf(color.Error, "Error reading the Amass logs: %v\n", err)
break
}
if filePtr != nil {
fmt.Fprintln(filePtr, line)
}
// Remove the timestamp
parts := strings.Split(line, " ")
line = strings.Join(parts[1:], " ")
// Check for the Amass average DNS names messages
if avg.FindString(line) != "" {
fgY.Fprintln(color.Error, line)
}
// Check if a DNS resolver was lost due to its score
if rScore.FindString(line) != "" {
fgR.Fprintln(color.Error, line)
}
// Let the user know when brute forcing has started
if brute.FindString(line) != "" {
fgY.Fprintln(color.Error, line)
}
// Let the user know when name alterations have started
if alterations.FindString(line) != "" {
fgY.Fprintln(color.Error, line)
}
// Check if DNS resolvers have failed the sanity checks
if verbose && sanity.FindString(line) != "" {
fgR.Fprintln(color.Error, line)
}
// Check for Amass DNS wildcard messages
if verbose && wildcard.FindString(line) != "" {
fgR.Fprintln(color.Error, line)
}
// Let the user know when data sources are being queried
if queries.FindString(line) != "" {
fgY.Fprintln(color.Error, line)
}
}
}
// Obtain parameters from provided input files
func processEnumInputFiles(args *enumArgs) error {
if args.Options.BruteForcing && len(args.Filepaths.BruteWordlist) > 0 {
for _, f := range args.Filepaths.BruteWordlist {
list, err := config.GetListFromFile(f)
if err != nil {
return fmt.Errorf("Failed to parse the brute force wordlist file: %v", err)
}
args.BruteWordList.InsertMany(list...)
}
}
if !args.Options.NoAlts && len(args.Filepaths.AltWordlist) > 0 {
for _, f := range args.Filepaths.AltWordlist {
list, err := config.GetListFromFile(f)
if err != nil {
return fmt.Errorf("Failed to parse the alterations wordlist file: %v", err)
}
args.AltWordList.InsertMany(list...)
}
}
if args.Filepaths.Blacklist != "" {
list, err := config.GetListFromFile(args.Filepaths.Blacklist)
if err != nil {
return fmt.Errorf("Failed to parse the blacklist file: %v", err)
}
args.Blacklist.InsertMany(list...)
}
if args.Filepaths.ExcludedSrcs != "" {
list, err := config.GetListFromFile(args.Filepaths.ExcludedSrcs)
if err != nil {
return fmt.Errorf("Failed to parse the exclude file: %v", err)
}
args.Excluded.InsertMany(list...)
}
if args.Filepaths.IncludedSrcs != "" {
list, err := config.GetListFromFile(args.Filepaths.IncludedSrcs)
if err != nil {
return fmt.Errorf("Failed to parse the include file: %v", err)
}
args.Included.InsertMany(list...)
}
if len(args.Filepaths.Names) > 0 {
for _, f := range args.Filepaths.Names {
list, err := config.GetListFromFile(f)
if err != nil {
return fmt.Errorf("Failed to parse the subdomain names file: %v", err)
}
args.Names.InsertMany(list...)
}
}
if len(args.Filepaths.Domains) > 0 {
for _, f := range args.Filepaths.Domains {
list, err := config.GetListFromFile(f)
if err != nil {
return fmt.Errorf("Failed to parse the domain names file: %v", err)
}
args.Domains.InsertMany(list...)
}
}
if len(args.Filepaths.Resolvers) > 0 {
for _, f := range args.Filepaths.Resolvers {
list, err := config.GetListFromFile(f)
if err != nil {
return fmt.Errorf("Failed to parse the esolver file: %v", err)
}
args.Resolvers.InsertMany(list...)
}
}
return nil
}
// Setup the amass enumeration settings
func (e enumArgs) OverrideConfig(conf *config.Config) error {
if len(e.Addresses) > 0 {
conf.Addresses = e.Addresses
}
if len(e.ASNs) > 0 {
conf.ASNs = e.ASNs
}
if len(e.CIDRs) > 0 {
conf.CIDRs = e.CIDRs
}
if len(e.Ports) > 0 {
conf.Ports = e.Ports
}
if e.Filepaths.Directory != "" {
conf.Dir = e.Filepaths.Directory
}
if e.MaxDNSQueries > 0 {
conf.MaxDNSQueries = e.MaxDNSQueries
}
if len(e.Names) > 0 {
conf.ProvidedNames = e.Names.Slice()
}
if len(e.BruteWordList) > 0 {
conf.Wordlist = e.BruteWordList.Slice()
}
if len(e.AltWordList) > 0 {
conf.AltWordlist = e.AltWordList.Slice()
}
if e.Options.BruteForcing {
conf.BruteForcing = true
}
if e.Options.NoAlts {
conf.Alterations = false
}
if e.Options.NoLocalDatabase || e.Options.Passive {
conf.LocalDatabase = false
}
if e.Options.NoRecursive {
conf.Recursive = false
}
if e.MinForRecursive != 1 {
conf.MinForRecursive = e.MinForRecursive
}
if e.Options.Active {
conf.Active = true
}
if e.Options.Passive {
conf.Passive = true
}
if len(e.Blacklist) > 0 {
conf.Blacklist = e.Blacklist.Slice()
}
if e.Timeout > 0 {
conf.Timeout = e.Timeout
}
if e.Options.Verbose == true {
conf.Verbose = true
}
if e.Resolvers.Len() > 0 {
conf.SetResolvers(e.Resolvers.Slice())
}
if !e.Options.MonitorResolverRate {
conf.MonitorResolverRate = false
}
if len(e.Included) > 0 {
conf.SourceFilter.Include = true
conf.SourceFilter.Sources = e.Included.Slice()
} else if len(e.Excluded) > 0 {
conf.SourceFilter.Include = false
conf.SourceFilter.Sources = e.Excluded.Slice()
}
// Attempt to add the provided domains to the configuration
conf.AddDomains(e.Domains.Slice())
if len(conf.Domains()) == 0 {
return errors.New("No root domain names were provided")
}
return nil
}