Skip to content

Commit

Permalink
introduce SetWithExclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Nov 22, 2023
1 parent a5d9b6f commit 8225a0b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func (r *Runner) RunEnumeration() error {
}
ret := uncover.GetUncoverTargetsFromMetadata(context.TODO(), store.Templates(), r.options.UncoverField, uncoverOpts)
for host := range ret {
r.hmapInputProvider.Set(host)
r.hmapInputProvider.SetWithExclusions(host)
}
}
// list all templates
Expand Down
32 changes: 32 additions & 0 deletions pkg/core/inputs/hybrid/hmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ type Input struct {
inputCount int64
excludedCount int64
dupeCount int64
skippedCount int64
hostMap *hybrid.HybridMap
excludedHosts map[string]struct{}
hostMapStream *filekv.FileDB
hostMapStreamOnce sync.Once
sync.Once
Expand Down Expand Up @@ -95,6 +97,9 @@ func New(opts *Options) (*Input, error) {
if input.dupeCount > 0 {
gologger.Info().Msgf("Supplied input was automatically deduplicated (%d removed).", input.dupeCount)
}
if input.skippedCount > 0 {
gologger.Info().Msgf("Number of hosts skipped from input due to exclusion: %d", input.skippedCount)
}
return input, nil
}

Expand Down Expand Up @@ -282,6 +287,32 @@ func (i *Input) Set(value string) {
}
}

// SetWithExclusions normalizes and stores passed input values if not excluded
func (i *Input) SetWithExclusions(value string) {
URL := strings.TrimSpace(value)
if URL == "" {
return
}
if i.isExcluded(URL) {
i.skippedCount++
return
}
i.Set(URL)
}

// isExcluded checks if a URL is in the exclusion list
func (i *Input) isExcluded(URL string) bool {
metaInput := &contextargs.MetaInput{Input: URL}
key, err := metaInput.MarshalString()
if err != nil {
gologger.Warning().Msgf("%s\n", err)
return false
}

_, exists := i.excludedHosts[key]
return exists
}

func (i *Input) Del(value string) {
URL := strings.TrimSpace(value)
if URL == "" {
Expand Down Expand Up @@ -407,6 +438,7 @@ func (i *Input) delItem(metaInput *contextargs.MetaInput) {

if tmpUrl.Host == targetUrl.Host {
_ = i.hostMap.Del(tmpKey)
i.excludedHosts[tmpKey] = struct{}{}
i.excludedCount++
i.inputCount--
}
Expand Down

0 comments on commit 8225a0b

Please sign in to comment.