implement `TargetsFile` and change logic of `Targets`

dev
TheSecEng 2021-07-28 17:48:26 -07:00
parent c227e6ca8e
commit 34fb629138
No known key found for this signature in database
GPG Key ID: 4D98046FE19FF417
4 changed files with 19 additions and 6 deletions

View File

@ -43,7 +43,8 @@ on extensive configurability, massive extensibility and ease of use.`)
createGroup(flagSet, "input", "Target", createGroup(flagSet, "input", "Target",
flagSet.StringVarP(&options.Target, "target", "u", "", "target URL/host to scan"), flagSet.StringVarP(&options.Target, "target", "u", "", "target URL/host to scan"),
flagSet.StringVarP(&options.Targets, "list", "l", "", "path to file containing a list of target URLs/hosts to scan (one per line)"), 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)"),
) )
createGroup(flagSet, "templates", "Templates", createGroup(flagSet, "templates", "Templates",

View File

@ -125,7 +125,7 @@ func New(options *types.Options) (*Runner, error) {
os.Exit(0) os.Exit(0)
} }
if (len(options.Templates) == 0 || !options.NewTemplates || (options.Targets == "" && !options.Stdin && options.Target == "")) && options.UpdateTemplates { if (len(options.Templates) == 0 || !options.NewTemplates || (len(options.Targets) == 0 && !options.Stdin && options.Target == "" && options.TargetsFile == "")) && options.UpdateTemplates {
os.Exit(0) os.Exit(0)
} }
hm, err := hybrid.New(hybrid.DefaultDiskOptions) hm, err := hybrid.New(hybrid.DefaultDiskOptions)
@ -144,6 +144,15 @@ func New(options *types.Options) (*Runner, error) {
runner.hostMap.Set(options.Target, nil) runner.hostMap.Set(options.Target, nil)
} }
// Handle multiple targets
if len(options.Targets) != 0 {
for _, target := range options.Targets {
runner.inputCount++
// nolint:errcheck // ignoring error
runner.hostMap.Set(target, nil)
}
}
// Handle stdin // Handle stdin
if options.Stdin { if options.Stdin {
scanner := bufio.NewScanner(os.Stdin) scanner := bufio.NewScanner(os.Stdin)
@ -163,8 +172,8 @@ func New(options *types.Options) (*Runner, error) {
} }
// Handle taget file // Handle taget file
if options.Targets != "" { if options.TargetsFile != "" {
input, inputErr := os.Open(options.Targets) input, inputErr := os.Open(options.TargetsFile)
if inputErr != nil { if inputErr != nil {
return nil, errors.Wrap(inputErr, "could not open targets file") return nil, errors.Wrap(inputErr, "could not open targets file")
} }

View File

@ -46,7 +46,8 @@ var DefaultOptions = &types.Options{
ProjectPath: "", ProjectPath: "",
Severity: []string{}, Severity: []string{},
Target: "", Target: "",
Targets: "", Targets: []string{},
TargetsFile: "",
Output: "", Output: "",
ProxyURL: "", ProxyURL: "",
ProxySocksURL: "", ProxySocksURL: "",

View File

@ -35,7 +35,9 @@ type Options struct {
// Target is a single URL/Domain to scan using a template // Target is a single URL/Domain to scan using a template
Target string Target string
// Targets specifies the targets to scan using templates. // Targets specifies the targets to scan using templates.
Targets string Targets goflags.StringSlice
// TargetsFile specifies the targets in a file to scan using templates.
TargetsFile string
// Output is the file to write found results to. // Output is the file to write found results to.
Output string Output string
// ProxyURL is the URL for the proxy server // ProxyURL is the URL for the proxy server