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

Fix #199 #209

Closed
wants to merge 4 commits into from
Closed
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
21 changes: 16 additions & 5 deletions pkg/runner/enumerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}