diff --git a/pkg/runner/config.go b/pkg/runner/config.go index 1751c9054..fe6a3da40 100644 --- a/pkg/runner/config.go +++ b/pkg/runner/config.go @@ -46,7 +46,7 @@ func UnmarshalFrom(file string) error { for _, source := range passive.AllSources { sourceName := strings.ToLower(source.Name()) apiKeys := sourceApiKeysMap[sourceName] - if source.NeedsKey() && apiKeys != nil && len(apiKeys) > 0 { + if len(apiKeys) > 0 { gologger.Debug().Msgf("API key(s) found for %s.", sourceName) source.AddApiKeys(apiKeys) } diff --git a/pkg/subscraping/sources/hackertarget/hackertarget.go b/pkg/subscraping/sources/hackertarget/hackertarget.go index c84957722..cac388261 100644 --- a/pkg/subscraping/sources/hackertarget/hackertarget.go +++ b/pkg/subscraping/sources/hackertarget/hackertarget.go @@ -12,9 +12,11 @@ import ( // Source is the passive scraping agent type Source struct { + apiKeys []string timeTaken time.Duration errors int results int + skipped bool } // Run function returns all subdomains found with the service @@ -29,7 +31,16 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se close(results) }(time.Now()) - resp, err := session.SimpleGet(ctx, fmt.Sprintf("https://api.hackertarget.com/hostsearch/?q=%s", domain)) + htSearchUrl := fmt.Sprintf("https://api.hackertarget.com/hostsearch/?q=%s", domain) + randomApiKey := subscraping.PickRandom(s.apiKeys, s.Name()) + if randomApiKey == "" { + s.skipped = true + return + } + + htSearchUrl = fmt.Sprintf("%s&apikey=%s", htSearchUrl, randomApiKey) + + resp, err := session.SimpleGet(ctx, htSearchUrl) if err != nil { results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} s.errors++ @@ -78,8 +89,9 @@ func (s *Source) NeedsKey() bool { return false } -func (s *Source) AddApiKeys(_ []string) { - // no key needed +// TODO: env variable will not work if NeedsKey is false, entire api key management needs to be refactored +func (s *Source) AddApiKeys(keys []string) { + s.apiKeys = keys } func (s *Source) Statistics() subscraping.Statistics { @@ -87,5 +99,6 @@ func (s *Source) Statistics() subscraping.Statistics { Errors: s.errors, Results: s.results, TimeTaken: s.timeTaken, + Skipped: s.skipped, } }