Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Subfinder SDK Usability #1466

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion v2/examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Dismissed Show dismissed Hide dismissed
log.Fatalf("failed to enumerate single domain: %v", err)
}

Expand All @@ -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))
}
}
8 changes: 4 additions & 4 deletions v2/pkg/runner/enumerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions v2/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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
Expand Down
Loading