Merge pull request #495 from projectdiscovery/issue-487-input-with-tab

Improving input items sanitization
dnsrepo-source
Sandeep Singh 2022-02-02 23:24:21 +05:30 committed by GitHub
commit c7e0e320b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

View File

@ -118,6 +118,8 @@ func ParseOptions() *Options {
os.Exit(0)
}
options.preProcessOptions()
// Validate the options passed by the user and if any
// invalid options have been used, exit.
err = options.validateOptions()
@ -160,3 +162,7 @@ func listSources(options *Options) {
gologger.Silent().Msgf(message, source)
}
}
func (options *Options) preProcessOptions() {
options.Domain, _ = sanitize(options.Domain)
}

View File

@ -7,6 +7,7 @@ import (
"os"
"path"
"github.com/pkg/errors"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/subfinder/v2/pkg/passive"
"github.com/projectdiscovery/subfinder/v2/pkg/resolve"
@ -83,12 +84,11 @@ func (r *Runner) RunEnumeration(ctx context.Context) error {
func (r *Runner) EnumerateMultipleDomains(ctx context.Context, reader io.Reader, outputs []io.Writer) error {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
domain := scanner.Text()
if domain == "" {
domain, err := sanitize(scanner.Text())
if errors.Is(err, ErrEmptyInput) {
continue
}
var err error
var file *os.File
// If the user has specified an output file, use that output file instead
// of creating a new output file for each domain. Else create a new file

View File

@ -3,6 +3,9 @@ package runner
import (
"bufio"
"os"
"strings"
"github.com/pkg/errors"
)
func loadFromFile(file string) ([]string, error) {
@ -14,11 +17,24 @@ func loadFromFile(file string) ([]string, error) {
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
text := scanner.Text()
if text == "" {
text, err := sanitize(scanner.Text())
if errors.Is(err, ErrEmptyInput) {
continue
}
items = append(items, text)
}
return items, scanner.Err()
}
var (
ErrEmptyInput = errors.New("empty data")
)
func sanitize(data string) (string, error) {
data = strings.Trim(data, "\n\t\"' ")
if data == "" {
return "", ErrEmptyInput
}
return data, nil
}