Merge pull request #210 from projectdiscovery/fix-nw-output

Fix nW flag output format issue
master
Ice3man 2020-01-10 02:09:12 -08:00 committed by GitHub
commit 1bf8af4778
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -139,7 +139,11 @@ func (r *Runner) EnumerateSingleDomain(domain, output string) error {
} else if r.options.JSON {
err = WriteJSONOutput(foundResults, file)
} else {
err = WriteHostOutput(uniqueMap, file)
if r.options.RemoveWildcard {
err = WriteHostOutputNoWildcard(foundResults, file)
} else {
err = WriteHostOutput(uniqueMap, file)
}
}
if err != nil {
log.Errorf("Could not write results to file %s for %s: %s\n", output, domain, err)

View File

@ -33,6 +33,25 @@ func WriteHostOutput(results map[string]struct{}, writer io.Writer) error {
return bufwriter.Flush()
}
// WriteHostOutputNoWildcard writes the output list of subdomain with nW flag to an io.Writer
func WriteHostOutputNoWildcard(results map[string]string, writer io.Writer) error {
bufwriter := bufio.NewWriter(writer)
sb := &strings.Builder{}
for host := range results {
sb.WriteString(host)
sb.WriteString("\n")
_, err := bufwriter.WriteString(sb.String())
if err != nil {
bufwriter.Flush()
return err
}
sb.Reset()
}
return bufwriter.Flush()
}
// WriteJSONOutput writes the output list of subdomain in JSON to an io.Writer
func WriteJSONOutput(results map[string]string, writer io.Writer) error {
encoder := jsoniter.NewEncoder(writer)