Skip to content

Commit

Permalink
fixed issue #224
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Jul 25, 2019
1 parent 68b20a1 commit e36d92b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
26 changes: 14 additions & 12 deletions cmd/amass/enum.go
Expand Up @@ -162,23 +162,20 @@ func runEnumCommand(clArgs []string) {
commandUsage(enumUsageMsg, enumCommand, enumBuf)
return
}
// Check if the user has requested the data source names
if args.Options.ListSources {
for _, name := range GetAllSourceNames() {
g.Println(name)
}
return
}

if len(args.AltWordListMask) > 0 {
args.AltWordList = utils.UniqueAppend(args.AltWordList, args.AltWordListMask...)
}
if len(args.BruteWordListMask) > 0 {
args.BruteWordList = utils.UniqueAppend(args.BruteWordList, args.BruteWordListMask...)
}

// Check if the user has requested the data source names
if args.Options.ListSources {
e := enum.NewEnumeration()

for _, name := range e.GetAllSourceNames() {
g.Println(name)
}
return
}
// 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")
Expand All @@ -197,10 +194,15 @@ func runEnumCommand(clArgs []string) {
// Seed the default pseudo-random number generator
rand.Seed(time.Now().UTC().UnixNano())

rLog, wLog := io.Pipe()
e := enum.NewEnumeration()
e.Config.Log = log.New(wLog, "", log.Lmicroseconds)
if e == nil {
r.Fprintf(color.Error, "%s\n", "No DNS resolvers passed the sanity check")
os.Exit(1)
}

rLog, wLog := io.Pipe()
e.Config.Log = log.New(wLog, "", log.Lmicroseconds)

// Check if a configuration file was provided, and if so, load the settings
if f, err := config.AcquireConfig(args.Filepaths.Directory, args.Filepaths.ConfigFile, e.Config); err == nil {
// Check if a config file was provided that has DNS resolvers specified
Expand Down
9 changes: 7 additions & 2 deletions cmd/amass/intel.go
Expand Up @@ -159,10 +159,15 @@ func runIntelCommand(clArgs []string) {
os.Exit(1)
}

rLog, wLog := io.Pipe()
ic := intel.NewIntelCollection()
ic.Config.Log = log.New(wLog, "", log.Lmicroseconds)
if ic == nil {
r.Fprintf(color.Error, "%s\n", "No DNS resolvers passed the sanity check")
os.Exit(1)
}

rLog, wLog := io.Pipe()
ic.Config.Log = log.New(wLog, "", log.Lmicroseconds)

// Check if a configuration file was provided, and if so, load the settings
if f, err := config.AcquireConfig(args.Filepaths.Directory, args.Filepaths.ConfigFile, ic.Config); err == nil {
// Check if a config file was provided that has DNS resolvers specified
Expand Down
4 changes: 4 additions & 0 deletions enum/enum.go
Expand Up @@ -81,6 +81,10 @@ func NewEnumeration() *Enumeration {
filter: utils.NewStringFilter(),
outputQueue: new(utils.Queue),
}
if e.Pool == nil {
return nil
}

e.dataSources = sources.GetAllSources(e.Config, e.Bus, e.Pool)
return e
}
Expand Down
6 changes: 5 additions & 1 deletion intel/intel.go
Expand Up @@ -46,7 +46,7 @@ type IntelCollection struct {

// NewIntelCollection returns an initialized IntelCollection object that has not been started yet.
func NewIntelCollection() *IntelCollection {
return &IntelCollection{
ic := &IntelCollection{
Config: &config.Config{Log: log.New(ioutil.Discard, "", 0)},
Bus: eb.NewEventBus(),
Pool: resolvers.NewResolverPool(nil),
Expand All @@ -57,6 +57,10 @@ func NewIntelCollection() *IntelCollection {
domainChan: make(chan *requests.Output, 100),
activeChan: make(chan struct{}, 100),
}
if ic.Pool == nil {
return nil
}
return ic
}

// HostedDomains uses open source intelligence to discover root domain names in the target infrastructure.
Expand Down
27 changes: 21 additions & 6 deletions resolvers/pool.go
Expand Up @@ -76,7 +76,9 @@ func NewResolverPool(addrs []string) *ResolverPool {
addrs = DefaultPublicResolvers
}

rp.SetResolvers(addrs)
if err := rp.SetResolvers(addrs); err != nil {
return nil
}
return rp
}

Expand All @@ -91,10 +93,15 @@ func (rp *ResolverPool) Stop() {
// NextResolver returns a randomly selected Resolver from the pool that has availability.
func (rp *ResolverPool) NextResolver() *Resolver {
var attempts int
max := len(rp.Resolvers)

for {
max := len(rp.Resolvers)
if max == 0 {
break
}

rnd := rand.Int()
r := rp.Resolvers[rnd%len(rp.Resolvers)]
r := rp.Resolvers[rnd%max]

if r.currentScore() > 50 && r.Available() {
return r
Expand All @@ -113,6 +120,7 @@ func (rp *ResolverPool) NextResolver() *Resolver {
attempts = 0
time.Sleep(time.Duration(randomInt(100, 1000)) * time.Millisecond)
}
return nil
}

// SetResolvers modifies the set of resolvers.
Expand Down Expand Up @@ -206,13 +214,20 @@ func (rp *ResolverPool) Resolve(name, qtype string, priority int) ([]requests.DN
num = 3
}

var queries int
ch := make(chan *resolveVote, num)
for i := 0; i < num; i++ {
go rp.queryResolver(rp.NextResolver(), ch, name, qtype, priority)
r := rp.NextResolver()
if r == nil {
break
}

go rp.queryResolver(r, ch, name, qtype, priority)
queries++
}

var votes []*resolveVote
for i := 0; i < num; i++ {
for i := 0; i < queries; i++ {
select {
case v := <-ch:
votes = append(votes, v)
Expand Down Expand Up @@ -265,7 +280,7 @@ func (rp *ResolverPool) ReverseDNS(addr string) (string, string, error) {
func (rp *ResolverPool) performElection(votes []*resolveVote, name, qtype string) ([]requests.DNSAnswer, error) {
if len(votes) == 1 {
return votes[0].Answers, votes[0].Err
} else if votes[0].Err != nil && votes[1].Err != nil && votes[2].Err != nil {
} else if len(votes) < 3 || (votes[0].Err != nil && votes[1].Err != nil && votes[2].Err != nil) {
return []requests.DNSAnswer{}, votes[0].Err
}

Expand Down

0 comments on commit e36d92b

Please sign in to comment.