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,12 +57,12 @@ type Agent struct {
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 {
// 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
@ -73,47 +73,47 @@ func (a *Agent) addSources(sources []string) {
for _, source := range sources {
switch source {
case "archiveis":
a.sources[source] = &archiveis.Source{},
a.sources[source] = &archiveis.Source{}
case "binaryedge":
a.sources[source] = &binaryedge.Source{},
a.sources[source] = &binaryedge.Source{}
case "bufferover":
a.sources[source] = &bufferover.Source{},
a.sources[source] = &bufferover.Source{}
case "certspotter":
a.sources[source] = &certspotter.Source{},
a.sources[source] = &certspotter.Source{}
case "certspotterold":
a.sources[source] = &certspotterold.Source{},
a.sources[source] = &certspotterold.Source{}
case "commoncrawl":
a.sources[source] = &commoncrawl.Source{},
a.sources[source] = &commoncrawl.Source{}
case "crtsh":
a.sources[source] = &crtsh.Source{},
a.sources[source] = &crtsh.Source{}
case "digicert":
a.sources[source] = &digicert.Source{},
a.sources[source] = &digicert.Source{}
case "dnsdumpster":
a.sources[source] = &dnsdumpster.Source{},
a.sources[source] = &dnsdumpster.Source{}
case "entrust":
a.sources[source] = &entrust.Source{},
a.sources[source] = &entrust.Source{}
case "googleter":
a.sources[source] = &googleter.Source{},
a.sources[source] = &googleter.Source{}
case "hackertarget":
a.sources[source] = &hackertarget.Source{},
a.sources[source] = &hackertarget.Source{}
case "ipv4info":
a.sources[source] = &ipv4info.Source{},
a.sources[source] = &ipv4info.Source{}
case "passivetotal":
a.sources[source] = &passivetotal.Source{},
a.sources[source] = &passivetotal.Source{}
case "securitytrails":
a.sources[source] = &securitytrails.Source{},
a.sources[source] = &securitytrails.Source{}
case "sitedossier":
a.sources[source] = &sitedossier.Source{},
a.sources[source] = &sitedossier.Source{}
case "threatcrowd":
a.sources[source] = &threatcrowd.Source{},
a.sources[source] = &threatcrowd.Source{}
case "threatminer":
a.sources[source] = &threatminer.Source{},
a.sources[source] = &threatminer.Source{}
case "urlscan":
a.sources[source] = &urlscan.Source{},
a.sources[source] = &urlscan.Source{}
case "virustotal":
a.sources[source] = &virustotal.Source{},
a.sources[source] = &virustotal.Source{}
case "waybackarchive":
a.sources[source] = &waybackarchive.Source{},
a.sources[source] = &waybackarchive.Source{}
}
}
}