From be571ae5679d8ab032dc1cfb780038fb50ec915f Mon Sep 17 00:00:00 2001 From: Ice3man543 Date: Fri, 10 Jan 2020 15:45:54 +0530 Subject: [PATCH] Fixed single file output --- pkg/runner/enumerate.go | 10 ++++++++-- pkg/runner/runner.go | 14 +++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pkg/runner/enumerate.go b/pkg/runner/enumerate.go index e0e4a8b..eee8012 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, append bool) error { log.Infof("Enumerating subdomains for %s\n", domain) // Get the API keys for sources from the configuration @@ -127,7 +127,13 @@ func (r *Runner) EnumerateSingleDomain(domain, output string) error { } } - file, err := os.Create(output) + var file *os.File + var err error + if append { + file, err = os.OpenFile(output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + } else { + file, err = os.Create(output) + } if err != nil { log.Errorf("Could not create file %s for %s: %s\n", output, domain, err) return err diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 2dbfaa2..0536d6c 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, false) } // If we have multiple domains as input, @@ -71,8 +71,16 @@ func (r *Runner) EnumerateMultipleDomains(reader io.Reader) error { continue } - outputFile := path.Join(r.options.OutputDirectory, domain) - err := r.EnumerateSingleDomain(domain, outputFile) + var err error + // If the user has specifed an output file, use that output file instead + // of creating a new output file for each domain. Else create a new file + // for each domain in the directory. + if r.options.Output != "" { + err = r.EnumerateSingleDomain(domain, r.options.Output, true) + } else { + outputFile := path.Join(r.options.OutputDirectory, domain) + err = r.EnumerateSingleDomain(domain, outputFile, false) + } if err != nil { return err }