From 0295555c709d5fb429d33fde23356d7e0016e1b9 Mon Sep 17 00:00:00 2001 From: TheSecEng Date: Thu, 29 Jul 2021 08:14:44 -0700 Subject: [PATCH] switch back to file based input for `Targets` and switch `Target` to receive a goflags.StringSlice (`[]string`) as an argument --- README.md | 2 +- v2/cmd/nuclei/main.go | 5 ++--- v2/internal/runner/runner.go | 17 +++++------------ v2/internal/testutils/testutils.go | 5 ++--- v2/pkg/types/types.go | 6 ++---- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index a93490c9..1e6a3874 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Usage: Flags: TARGET: - -u, -target string target URL/host to scan + -u, -target string target URLs/hosts to scan -l, -list string path to file containing a list of target URLs/hosts to scan (one per line) TEMPLATES: diff --git a/v2/cmd/nuclei/main.go b/v2/cmd/nuclei/main.go index 53a822c5..bc70f3b1 100644 --- a/v2/cmd/nuclei/main.go +++ b/v2/cmd/nuclei/main.go @@ -42,9 +42,8 @@ func readConfig() { on extensive configurability, massive extensibility and ease of use.`) createGroup(flagSet, "input", "Target", - flagSet.StringVarP(&options.Target, "target", "u", "", "target URL/host to scan"), - flagSet.StringSliceVarP(&options.Targets, "list", "l", []string{}, "list of target URL/hosts to scan"), - flagSet.StringVarP(&options.TargetsFile, "file", "f", "", "path to file containing a list of target URLs/hosts to scan (one per line)"), + flagSet.StringSliceVarP(&options.Target, "target", "u", []string{}, "target URLs/hosts to scan"), + flagSet.StringVarP(&options.Targets, "list", "l", "", "path to file containing a list of target URLs/hosts to scan (one per line)"), ) createGroup(flagSet, "templates", "Templates", diff --git a/v2/internal/runner/runner.go b/v2/internal/runner/runner.go index 2d9afd88..609594da 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -125,7 +125,7 @@ func New(options *types.Options) (*Runner, error) { os.Exit(0) } - if (len(options.Templates) == 0 || !options.NewTemplates || (len(options.Targets) == 0 && !options.Stdin && options.Target == "" && options.TargetsFile == "")) && options.UpdateTemplates { + if (len(options.Templates) == 0 || !options.NewTemplates || (len(options.Targets) == 0 && !options.Stdin && len(options.Target) == 0)) && options.UpdateTemplates { os.Exit(0) } hm, err := hybrid.New(hybrid.DefaultDiskOptions) @@ -138,15 +138,8 @@ func New(options *types.Options) (*Runner, error) { dupeCount := 0 // Handle single target - if options.Target != "" { - runner.inputCount++ - // nolint:errcheck // ignoring error - runner.hostMap.Set(options.Target, nil) - } - - // Handle multiple targets - if len(options.Targets) != 0 { - for _, target := range options.Targets { + if len(options.Target) != 0 { + for _, target := range options.Target { runner.inputCount++ // nolint:errcheck // ignoring error runner.hostMap.Set(target, nil) @@ -172,8 +165,8 @@ func New(options *types.Options) (*Runner, error) { } // Handle taget file - if options.TargetsFile != "" { - input, inputErr := os.Open(options.TargetsFile) + if options.Targets != "" { + input, inputErr := os.Open(options.Targets) if inputErr != nil { return nil, errors.Wrap(inputErr, "could not open targets file") } diff --git a/v2/internal/testutils/testutils.go b/v2/internal/testutils/testutils.go index 5296a8f8..d8305044 100644 --- a/v2/internal/testutils/testutils.go +++ b/v2/internal/testutils/testutils.go @@ -45,9 +45,8 @@ var DefaultOptions = &types.Options{ RateLimit: 150, ProjectPath: "", Severity: []string{}, - Target: "", - Targets: []string{}, - TargetsFile: "", + Target: []string{}, + Targets: "", Output: "", ProxyURL: "", ProxySocksURL: "", diff --git a/v2/pkg/types/types.go b/v2/pkg/types/types.go index c87f66f7..f049b813 100644 --- a/v2/pkg/types/types.go +++ b/v2/pkg/types/types.go @@ -33,11 +33,9 @@ type Options struct { // InteractshURL is the URL for the interactsh server. InteractshURL string // Target is a single URL/Domain to scan using a template - Target string + Target goflags.StringSlice // Targets specifies the targets to scan using templates. - Targets goflags.StringSlice - // TargetsFile specifies the targets in a file to scan using templates. - TargetsFile string + Targets string // Output is the file to write found results to. Output string // ProxyURL is the URL for the proxy server