Added passive with runner

master
Ice3man543 2019-12-04 15:01:15 +05:30
parent 5ad40427a3
commit 075cd7e377
2 changed files with 90 additions and 47 deletions

43
pkg/passive/passive.go Normal file
View File

@ -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
}

View File

@ -57,63 +57,63 @@ type Agent struct {
sources map[string]subscraping.Source sources map[string]subscraping.Source
} }
// NewAgent creates a new agent for passive subdomain discovery // New creates a new agent for passive subdomain discovery
func New(sources []string, exclusions []string) *Agent { func New(sources []string, exclusions []string) *Agent {
// Create the agent, insert the sources and remove the excluded sources // Create the agent, insert the sources and remove the excluded sources
agent := &Agent{sources: make(map[string]subscraping.Source)} agent := &Agent{sources: make(map[string]subscraping.Source)}
agent.insertSources(sources) agent.addSources(sources)
agent.removeSources(exclusions) agent.removeSources(exclusions)
return agent return agent
} }
// addSources adds the given list of sources to the source array // addSources adds the given list of sources to the source array
func (a *Agent) addSources(sources []string) { func (a *Agent) addSources(sources []string) {
for _, source := range sources { for _, source := range sources {
switch source { switch source {
case "archiveis": case "archiveis":
a.sources[source] = &archiveis.Source{}, a.sources[source] = &archiveis.Source{}
case "binaryedge": case "binaryedge":
a.sources[source] = &binaryedge.Source{}, a.sources[source] = &binaryedge.Source{}
case "bufferover": case "bufferover":
a.sources[source] = &bufferover.Source{}, a.sources[source] = &bufferover.Source{}
case "certspotter": case "certspotter":
a.sources[source] = &certspotter.Source{}, a.sources[source] = &certspotter.Source{}
case "certspotterold": case "certspotterold":
a.sources[source] = &certspotterold.Source{}, a.sources[source] = &certspotterold.Source{}
case "commoncrawl": case "commoncrawl":
a.sources[source] = &commoncrawl.Source{}, a.sources[source] = &commoncrawl.Source{}
case "crtsh": case "crtsh":
a.sources[source] = &crtsh.Source{}, a.sources[source] = &crtsh.Source{}
case "digicert": case "digicert":
a.sources[source] = &digicert.Source{}, a.sources[source] = &digicert.Source{}
case "dnsdumpster": case "dnsdumpster":
a.sources[source] = &dnsdumpster.Source{}, a.sources[source] = &dnsdumpster.Source{}
case "entrust": case "entrust":
a.sources[source] = &entrust.Source{}, a.sources[source] = &entrust.Source{}
case "googleter": case "googleter":
a.sources[source] = &googleter.Source{}, a.sources[source] = &googleter.Source{}
case "hackertarget": case "hackertarget":
a.sources[source] = &hackertarget.Source{}, a.sources[source] = &hackertarget.Source{}
case "ipv4info": case "ipv4info":
a.sources[source] = &ipv4info.Source{}, a.sources[source] = &ipv4info.Source{}
case "passivetotal": case "passivetotal":
a.sources[source] = &passivetotal.Source{}, a.sources[source] = &passivetotal.Source{}
case "securitytrails": case "securitytrails":
a.sources[source] = &securitytrails.Source{}, a.sources[source] = &securitytrails.Source{}
case "sitedossier": case "sitedossier":
a.sources[source] = &sitedossier.Source{}, a.sources[source] = &sitedossier.Source{}
case "threatcrowd": case "threatcrowd":
a.sources[source] = &threatcrowd.Source{}, a.sources[source] = &threatcrowd.Source{}
case "threatminer": case "threatminer":
a.sources[source] = &threatminer.Source{}, a.sources[source] = &threatminer.Source{}
case "urlscan": case "urlscan":
a.sources[source] = &urlscan.Source{}, a.sources[source] = &urlscan.Source{}
case "virustotal": case "virustotal":
a.sources[source] = &virustotal.Source{}, a.sources[source] = &virustotal.Source{}
case "waybackarchive": case "waybackarchive":
a.sources[source] = &waybackarchive.Source{}, a.sources[source] = &waybackarchive.Source{}
} }
} }
} }
@ -123,4 +123,4 @@ func (a *Agent) removeSources(sources []string) {
for _, source := range sources { for _, source := range sources {
delete(a.sources, source) delete(a.sources, source)
} }
} }