diff --git a/v2/pkg/passive/sources.go b/v2/pkg/passive/sources.go index 948a5c8a9..43b048f65 100644 --- a/v2/pkg/passive/sources.go +++ b/v2/pkg/passive/sources.go @@ -42,6 +42,7 @@ import ( "github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/securitytrails" "github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/shodan" "github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/sitedossier" + "github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/subdomaincenter" "github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/threatbook" "github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/virustotal" "github.com/projectdiscovery/subfinder/v2/pkg/subscraping/sources/waybackarchive" @@ -93,6 +94,7 @@ var AllSources = [...]subscraping.Source{ // &threatminer.Source{}, // failing api // &reconcloud.Source{}, // failing due to cloudflare bot protection &builtwith.Source{}, + &subdomaincenter.Source{}, } var sourceWarnings = mapsutil.NewSyncLockMap[string, string]( diff --git a/v2/pkg/passive/sources_test.go b/v2/pkg/passive/sources_test.go index e7e69214a..c99716d58 100644 --- a/v2/pkg/passive/sources_test.go +++ b/v2/pkg/passive/sources_test.go @@ -53,6 +53,7 @@ var ( // "threatminer", // "reconcloud", "builtwith", + "subdomaincenter", } expectedDefaultSources = []string{ @@ -88,6 +89,7 @@ var ( // "threatminer", // "reconcloud", "builtwith", + "subdomaincenter", } expectedDefaultRecursiveSources = []string{ diff --git a/v2/pkg/runner/options.go b/v2/pkg/runner/options.go index 30f5cfc57..ad1b105f2 100644 --- a/v2/pkg/runner/options.go +++ b/v2/pkg/runner/options.go @@ -257,4 +257,5 @@ var defaultRateLimits = []string{ "netlas=1/s", // "gitlab=2/s", "github=83/m", + "subdomaincenter=2/m", } diff --git a/v2/pkg/subscraping/sources/subdomaincenter/subdomaincenter.go b/v2/pkg/subscraping/sources/subdomaincenter/subdomaincenter.go new file mode 100644 index 000000000..40873f32a --- /dev/null +++ b/v2/pkg/subscraping/sources/subdomaincenter/subdomaincenter.go @@ -0,0 +1,87 @@ +// Package subdomaincenter logic +package subdomaincenter + +import ( + "context" + "fmt" + "time" + + jsoniter "github.com/json-iterator/go" + + "github.com/projectdiscovery/subfinder/v2/pkg/subscraping" +) + +// Source is the passive scraping agent +type Source struct { + timeTaken time.Duration + errors int + results int +} + +// Run function returns all subdomains found with the service +func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Session) <-chan subscraping.Result { + results := make(chan subscraping.Result) + s.errors = 0 + s.results = 0 + + go func() { + defer func(startTime time.Time) { + s.timeTaken = time.Since(startTime) + close(results) + }(time.Now()) + + resp, err := session.SimpleGet(ctx, fmt.Sprintf("https://api.subdomain.center/?domain=%s", domain)) + if err != nil { + results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} + s.errors++ + session.DiscardHTTPResponse(resp) + return + } + + var subdomains []string + err = jsoniter.NewDecoder(resp.Body).Decode(&subdomains) + if err != nil { + results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} + s.errors++ + resp.Body.Close() + return + } + resp.Body.Close() + + for _, subdomain := range subdomains { + results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain} + s.results++ + } + }() + + return results +} + +// Name returns the name of the source +func (s *Source) Name() string { + return "subdomaincenter" +} + +func (s *Source) IsDefault() bool { + return true +} + +func (s *Source) HasRecursiveSupport() bool { + return false +} + +func (s *Source) NeedsKey() bool { + return false +} + +func (s *Source) AddApiKeys(_ []string) { + // no key needed +} + +func (s *Source) Statistics() subscraping.Statistics { + return subscraping.Statistics{ + Errors: s.errors, + Results: s.results, + TimeTaken: s.timeTaken, + } +}