From 075cd7e37778ccbc6287f104ee66cb031a529372 Mon Sep 17 00:00:00 2001 From: Ice3man543 Date: Wed, 4 Dec 2019 15:01:15 +0530 Subject: [PATCH] Added passive with runner --- pkg/passive/passive.go | 43 +++++++++++++++++++ pkg/passive/sources.go | 94 +++++++++++++++++++++--------------------- 2 files changed, 90 insertions(+), 47 deletions(-) create mode 100644 pkg/passive/passive.go diff --git a/pkg/passive/passive.go b/pkg/passive/passive.go new file mode 100644 index 0000000..e33241c --- /dev/null +++ b/pkg/passive/passive.go @@ -0,0 +1,43 @@ +package passive + +import ( + "context" + "fmt" + "sync" + "time" + + "github.com/subfinder/subfinder/pkg/subscraping" +) + +// EnumerateSubdomains enumerates all the subdomains for a given domain +func (a *Agent) EnumerateSubdomains(domain string, keys subscraping.Keys, timeout, maxEnumTime int) chan subscraping.Result { + results := make(chan subscraping.Result) + + go func() { + session, err := subscraping.NewSession(domain, keys, timeout) + if err != nil { + results <- subscraping.Result{Type: subscraping.Error, Error: fmt.Errorf("could not init passive session for %s: %s", domain, err)} + } + + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(maxEnumTime)*time.Second) + + wg := &sync.WaitGroup{} + // Run each source in parallel on the target domain + for _, runner := range a.sources { + wg.Add(1) + + go func(runner subscraping.Source) { + for resp := range runner.Run(ctx, domain, session) { + results <- resp + } + wg.Done() + }(runner) + } + wg.Wait() + + close(results) + cancel() + }() + + return results +} diff --git a/pkg/passive/sources.go b/pkg/passive/sources.go index 8a64886..bcf6ba6 100644 --- a/pkg/passive/sources.go +++ b/pkg/passive/sources.go @@ -57,63 +57,63 @@ type Agent struct { sources map[string]subscraping.Source } -// NewAgent creates a new agent for passive subdomain discovery -func New(sources []string, exclusions []string) *Agent { +// New creates a new agent for passive subdomain discovery +func New(sources []string, exclusions []string) *Agent { // Create the agent, insert the sources and remove the excluded sources agent := &Agent{sources: make(map[string]subscraping.Source)} - agent.insertSources(sources) + agent.addSources(sources) agent.removeSources(exclusions) return agent -} +} // addSources adds the given list of sources to the source array func (a *Agent) addSources(sources []string) { for _, source := range sources { switch source { - case "archiveis": - a.sources[source] = &archiveis.Source{}, - case "binaryedge": - a.sources[source] = &binaryedge.Source{}, - case "bufferover": - a.sources[source] = &bufferover.Source{}, - case "certspotter": - a.sources[source] = &certspotter.Source{}, - case "certspotterold": - a.sources[source] = &certspotterold.Source{}, - case "commoncrawl": - a.sources[source] = &commoncrawl.Source{}, - case "crtsh": - a.sources[source] = &crtsh.Source{}, - case "digicert": - a.sources[source] = &digicert.Source{}, - case "dnsdumpster": - a.sources[source] = &dnsdumpster.Source{}, - case "entrust": - a.sources[source] = &entrust.Source{}, - case "googleter": - a.sources[source] = &googleter.Source{}, - case "hackertarget": - a.sources[source] = &hackertarget.Source{}, - case "ipv4info": - a.sources[source] = &ipv4info.Source{}, - case "passivetotal": - a.sources[source] = &passivetotal.Source{}, - case "securitytrails": - a.sources[source] = &securitytrails.Source{}, - case "sitedossier": - a.sources[source] = &sitedossier.Source{}, - case "threatcrowd": - a.sources[source] = &threatcrowd.Source{}, - case "threatminer": - a.sources[source] = &threatminer.Source{}, - case "urlscan": - a.sources[source] = &urlscan.Source{}, - case "virustotal": - a.sources[source] = &virustotal.Source{}, - case "waybackarchive": - a.sources[source] = &waybackarchive.Source{}, + case "archiveis": + a.sources[source] = &archiveis.Source{} + case "binaryedge": + a.sources[source] = &binaryedge.Source{} + case "bufferover": + a.sources[source] = &bufferover.Source{} + case "certspotter": + a.sources[source] = &certspotter.Source{} + case "certspotterold": + a.sources[source] = &certspotterold.Source{} + case "commoncrawl": + a.sources[source] = &commoncrawl.Source{} + case "crtsh": + a.sources[source] = &crtsh.Source{} + case "digicert": + a.sources[source] = &digicert.Source{} + case "dnsdumpster": + a.sources[source] = &dnsdumpster.Source{} + case "entrust": + a.sources[source] = &entrust.Source{} + case "googleter": + a.sources[source] = &googleter.Source{} + case "hackertarget": + a.sources[source] = &hackertarget.Source{} + case "ipv4info": + a.sources[source] = &ipv4info.Source{} + case "passivetotal": + a.sources[source] = &passivetotal.Source{} + case "securitytrails": + a.sources[source] = &securitytrails.Source{} + case "sitedossier": + a.sources[source] = &sitedossier.Source{} + case "threatcrowd": + a.sources[source] = &threatcrowd.Source{} + case "threatminer": + a.sources[source] = &threatminer.Source{} + case "urlscan": + a.sources[source] = &urlscan.Source{} + case "virustotal": + a.sources[source] = &virustotal.Source{} + case "waybackarchive": + a.sources[source] = &waybackarchive.Source{} } } } @@ -123,4 +123,4 @@ func (a *Agent) removeSources(sources []string) { for _, source := range sources { delete(a.sources, source) } -} \ No newline at end of file +}