-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
235 lines (190 loc) · 5.37 KB
/
config.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
// 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 amass
import (
"bufio"
"errors"
"io"
"io/ioutil"
"log"
"net"
"strings"
"sync"
"time"
"github.com/caffix/amass/amass/internal/utils"
)
const (
defaultWordlistURL = "https://raw.githubusercontent.com/caffix/amass/master/wordlists/namelist.txt"
)
// AmassConfig - Passes along optional configurations
type AmassConfig struct {
sync.Mutex
Graph *Graph
// The channel that will receive the results
Output chan *AmassOutput
// Logger for error messages
Log *log.Logger
// The ASNs that the enumeration will target
ASNs []int
// The CIDRs that the enumeration will target
CIDRs []*net.IPNet
// The IPs that the enumeration will target
IPs []net.IP
// The ports that will be checked for certificates
Ports []int
// Will whois info be used to add additional domains?
Whois bool
// The list of words to use when generating names
Wordlist []string
// Will the enumeration including brute forcing techniques
BruteForcing bool
// Will recursive brute forcing be performed?
Recursive bool
// Minimum number of subdomain discoveries before performing recursive brute forcing
MinForRecursive int
// Will discovered subdomain name alterations be generated?
Alterations bool
// Only access the data sources for names and return results?
NoDNS bool
// Determines if active information gathering techniques will be used
Active bool
// A blacklist of subdomain names that will not be investigated
Blacklist []string
// Sets the maximum number of DNS queries per minute
Frequency time.Duration
// Preferred DNS resolvers identified by the user
Resolvers []string
// The Neo4j URL used by the bolt driver to connect with the database
Neo4jPath string
// The root domain names that the enumeration will target
domains []string
}
func (c *AmassConfig) AddDomains(names []string) {
c.Lock()
defer c.Unlock()
c.domains = utils.UniqueAppend(c.domains, names...)
}
func (c *AmassConfig) Domains() []string {
c.Lock()
defer c.Unlock()
return c.domains
}
func (c *AmassConfig) IsDomainInScope(name string) bool {
var discovered bool
for _, d := range c.Domains() {
if name == d || strings.HasSuffix(name, "."+d) {
discovered = true
break
}
}
return discovered
}
func (c *AmassConfig) Blacklisted(name string) bool {
var resp bool
for _, bl := range c.Blacklist {
if match := strings.HasSuffix(name, bl); match {
resp = true
break
}
}
return resp
}
func CheckConfig(config *AmassConfig) error {
if config.Output == nil {
return errors.New("The configuration did not have an output channel")
}
if config.NoDNS && config.BruteForcing {
return errors.New("Brute forcing cannot be performed without DNS resolution")
}
if config.NoDNS && config.Active {
return errors.New("Active enumeration cannot be performed without DNS resolution")
}
if config.BruteForcing && len(config.Wordlist) == 0 {
return errors.New("The configuration contains no word list for brute forcing")
}
if config.Frequency < DefaultConfig().Frequency {
return errors.New("The configuration contains a invalid frequency")
}
if config.NoDNS && config.Neo4jPath != "" {
return errors.New("Data cannot be provided to Neo4j without DNS resolution")
}
return nil
}
// DefaultConfig returns a config with values that have been tested
func DefaultConfig() *AmassConfig {
config := &AmassConfig{
Log: log.New(ioutil.Discard, "", 0),
Ports: []int{80, 443},
Recursive: true,
Alterations: true,
Frequency: 10 * time.Millisecond,
MinForRecursive: 1,
}
return config
}
// Ensures that all configuration elements have valid values
func CustomConfig(ac *AmassConfig) *AmassConfig {
var err error
config := DefaultConfig()
if len(ac.Domains()) > 0 {
config.AddDomains(ac.Domains())
}
if len(config.Resolvers) > 0 {
SetCustomResolvers(config.Resolvers)
}
if ac.Log != nil {
config.Log = ac.Log
}
if len(ac.Ports) > 0 {
config.Ports = ac.Ports
}
if ac.BruteForcing && len(ac.Wordlist) == 0 {
if config.Wordlist, err = GetDefaultWordlist(); err != nil {
config.Log.Printf("Configuration error: %v", err)
return nil
}
} else {
config.Wordlist = ac.Wordlist
}
// Check that the config values have been set appropriately
if ac.Frequency > config.Frequency {
config.Frequency = ac.Frequency
}
if ac.MinForRecursive > config.MinForRecursive {
config.MinForRecursive = ac.MinForRecursive
}
config.ASNs = ac.ASNs
config.CIDRs = ac.CIDRs
config.IPs = ac.IPs
config.Whois = ac.Whois
config.BruteForcing = ac.BruteForcing
config.Recursive = ac.Recursive
config.Alterations = ac.Alterations
config.NoDNS = ac.NoDNS
config.Output = ac.Output
config.Resolvers = ac.Resolvers
config.Blacklist = ac.Blacklist
config.Active = ac.Active
config.Neo4jPath = ac.Neo4jPath
return config
}
func GetDefaultWordlist() ([]string, error) {
var list []string
var wordlist io.Reader
page, err := utils.GetWebPage(defaultWordlistURL, nil)
if err != nil {
return list, err
}
wordlist = strings.NewReader(page)
scanner := bufio.NewScanner(wordlist)
// Once we have used all the words, we are finished
for scanner.Scan() {
// Get the next word in the list
word := scanner.Text()
if word != "" {
// Add the word to the list
list = append(list, word)
}
}
return list, nil
}