diff --git a/v2/examples/main.go b/v2/examples/main.go index d6baf9d91..8edf7ea72 100644 --- a/v2/examples/main.go +++ b/v2/examples/main.go @@ -30,8 +30,9 @@ func main() { } output := &bytes.Buffer{} + var sourceMap map[string]map[string]struct{} // To run subdomain enumeration on a single domain - if err = subfinder.EnumerateSingleDomainWithCtx(context.Background(), "hackerone.com", []io.Writer{output}); err != nil { + if sourceMap, err = subfinder.EnumerateSingleDomainWithCtx(context.Background(), "hackerone.com", []io.Writer{output}); err != nil { log.Fatalf("failed to enumerate single domain: %v", err) } @@ -47,4 +48,13 @@ func main() { // print the output log.Println(output.String()) + + // Or use sourceMap to access the results in your application + for subdomain, sources := range sourceMap { + sourcesList := make([]string, 0, len(sources)) + for source := range sources { + sourcesList = append(sourcesList, source) + } + log.Printf("%s %s (%d)\n", subdomain, sourcesList, len(sources)) + } } diff --git a/v2/pkg/runner/enumerate.go b/v2/pkg/runner/enumerate.go index 727359f50..7a708f45c 100644 --- a/v2/pkg/runner/enumerate.go +++ b/v2/pkg/runner/enumerate.go @@ -25,12 +25,12 @@ var replacer = strings.NewReplacer( ) // EnumerateSingleDomain wraps EnumerateSingleDomainWithCtx with an empty context -func (r *Runner) EnumerateSingleDomain(domain string, writers []io.Writer) error { +func (r *Runner) EnumerateSingleDomain(domain string, writers []io.Writer) (map[string]map[string]struct{}, error) { return r.EnumerateSingleDomainWithCtx(context.Background(), domain, writers) } // EnumerateSingleDomainWithCtx performs subdomain enumeration against a single domain -func (r *Runner) EnumerateSingleDomainWithCtx(ctx context.Context, domain string, writers []io.Writer) error { +func (r *Runner) EnumerateSingleDomainWithCtx(ctx context.Context, domain string, writers []io.Writer) (map[string]map[string]struct{}, error) { gologger.Info().Msgf("Enumerating subdomains for %s\n", domain) // Check if the user has asked to remove wildcards explicitly. @@ -145,7 +145,7 @@ func (r *Runner) EnumerateSingleDomainWithCtx(ctx context.Context, domain string } if err != nil { gologger.Error().Msgf("Could not write results for %s: %s\n", domain, err) - return err + return nil, err } } @@ -186,7 +186,7 @@ func (r *Runner) EnumerateSingleDomainWithCtx(ctx context.Context, domain string printStatistics(statistics) } - return nil + return sourceMap, nil } func (r *Runner) filterAndMatchSubdomain(subdomain string) bool { diff --git a/v2/pkg/runner/runner.go b/v2/pkg/runner/runner.go index e5cb3740b..3a79f637f 100644 --- a/v2/pkg/runner/runner.go +++ b/v2/pkg/runner/runner.go @@ -136,7 +136,7 @@ func (r *Runner) EnumerateMultipleDomainsWithCtx(ctx context.Context, reader io. return err } - err = r.EnumerateSingleDomainWithCtx(ctx, domain, append(writers, file)) + _, err = r.EnumerateSingleDomainWithCtx(ctx, domain, append(writers, file)) file.Close() } else if r.options.OutputDirectory != "" { @@ -154,11 +154,11 @@ func (r *Runner) EnumerateMultipleDomainsWithCtx(ctx context.Context, reader io. return err } - err = r.EnumerateSingleDomainWithCtx(ctx, domain, append(writers, file)) + _, err = r.EnumerateSingleDomainWithCtx(ctx, domain, append(writers, file)) file.Close() } else { - err = r.EnumerateSingleDomainWithCtx(ctx, domain, writers) + _, err = r.EnumerateSingleDomainWithCtx(ctx, domain, writers) } if err != nil { return err