[go: up one dir, main page]

Skip to content

Commit

Permalink
Fixed the OTX provider that did not return proper data when a hostnam…
Browse files Browse the repository at this point in the history
…e (not a top domain) is submitted as target
  • Loading branch information
BastienFaure committed Nov 25, 2020
1 parent 4846cd1 commit e22629c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions providers/otx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"strings"
"github.com/bobesa/go-domain-util/domainutil"
)

type OTXProvider struct {
Expand Down Expand Up @@ -31,9 +32,19 @@ func NewOTXProvider(config *Config) Provider {
}

func (o *OTXProvider) formatURL(domain string, page int) string {
return fmt.Sprintf("https://otx.alienvault.com/api/v1/indicators/domain/%s/url_list?limit=%d&page=%d",
domain, otxResultsLimit, page,
)
if !domainutil.HasSubdomain(domain) {
return fmt.Sprintf("https://otx.alienvault.com/api/v1/indicators/domain/%s/url_list?limit=%d&page=%d",
domain, otxResultsLimit, page,
)
} else if domainutil.HasSubdomain(domain) && o.IncludeSubdomains {
return fmt.Sprintf("https://otx.alienvault.com/api/v1/indicators/domain/%s/url_list?limit=%d&page=%d",
domain, otxResultsLimit, page,
)
} else {
return fmt.Sprintf("https://otx.alienvault.com/api/v1/indicators/hostname/%s/url_list?limit=%d&page=%d",
domain, otxResultsLimit, page,
)
}
}

func (o *OTXProvider) Fetch(domain string, results chan<- string) error {
Expand All @@ -53,7 +64,13 @@ func (o *OTXProvider) Fetch(domain string, results chan<- string) error {

for _, entry := range result.URLList {
if o.IncludeSubdomains {
results <- entry.URL
if !domainutil.HasSubdomain(domain) {
results <- entry.URL
} else {
if strings.Contains(strings.ToLower(entry.Hostname), strings.ToLower(domain)) {
results <- entry.URL
}
}
} else {
if strings.EqualFold(domain, entry.Hostname) {
results <- entry.URL
Expand Down

0 comments on commit e22629c

Please sign in to comment.