diff --git a/pkg/runner/enumerate.go b/pkg/runner/enumerate.go index f6ad34b63..0ba58b4e8 100644 --- a/pkg/runner/enumerate.go +++ b/pkg/runner/enumerate.go @@ -12,7 +12,7 @@ import ( ) // EnumerateSingleDomain performs subdomain enumeration against a single domain -func (r *Runner) EnumerateSingleDomain(domain, output string) error { +func (r *Runner) EnumerateSingleDomain(domain, output string, overwrite bool) error { log.Infof("Enumerating subdomains for %s\n", domain) // Get the API keys for sources from the configuration @@ -127,10 +127,21 @@ func (r *Runner) EnumerateSingleDomain(domain, output string) error { } } - file, err := os.Create(output) - if err != nil { - log.Errorf("Could not create file %s for %s: %s\n", output, domain, err) - return err + var file *os.File + var err error + + if overwrite { + file, err = os.Create(output) + if err != nil { + log.Errorf("Could not create file %s for %s: %s\n", output, domain, err) + return err + } + } else { + file, err = os.OpenFile(output, os.O_APPEND | os.O_CREATE | os.O_WRONLY, 0644) + if err != nil { + log.Errorf("Could not open file %s for %s: %s\n", output, domain, err) + return err + } } // Write the output to the file depending upon user requirement diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 2dbfaa229..630857702 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -40,7 +40,7 @@ func NewRunner(options *Options) (*Runner, error) { func (r *Runner) RunEnumeration() error { // Check if only a single domain is sent as input. Process the domain now. if r.options.Domain != "" { - return r.EnumerateSingleDomain(r.options.Domain, r.options.Output) + return r.EnumerateSingleDomain(r.options.Domain, r.options.Output, true) } // If we have multiple domains as input, @@ -65,17 +65,27 @@ func (r *Runner) RunEnumeration() error { // We keep enumerating subdomains for a given domain until we reach an error func (r *Runner) EnumerateMultipleDomains(reader io.Reader) error { scanner := bufio.NewScanner(reader) + var scanned int = 0 for scanner.Scan() { + var isFirstRun bool = (scanned == 0) + domain := scanner.Text() if domain == "" { continue } - outputFile := path.Join(r.options.OutputDirectory, domain) - err := r.EnumerateSingleDomain(domain, outputFile) + outputFile := "" + if r.options.Output != "" { + outputFile = path.Join(r.options.OutputDirectory, r.options.Output) + } + + // the first enumeration will overwrite the output file, + // successive enumerations will append the results. + err := r.EnumerateSingleDomain(domain, outputFile, isFirstRun) if err != nil { return err } + scanned++ } return nil }