From 5a2eef143784d0edadb85a99b379c909ddad8187 Mon Sep 17 00:00:00 2001 From: Ice3man543 Date: Thu, 25 Jun 2020 21:40:20 +0530 Subject: [PATCH] Added single target support with target flag --- internal/runner/options.go | 2 ++ internal/runner/runner.go | 14 ++++++++++++-- internal/runner/validate.go | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/runner/options.go b/internal/runner/options.go index d030eb81..16b755fd 100644 --- a/internal/runner/options.go +++ b/internal/runner/options.go @@ -13,6 +13,7 @@ import ( type Options struct { Debug bool // Debug mode allows debugging request/responses for the engine Templates string // Signature specifies the template/templates to use + Target string // Target is a single URL/Domain to scan usng a template Targets string // Targets specifies the targets to scan using templates. Threads int // Thread controls the number of concurrent requests to make. Timeout int // Timeout is the seconds to wait for a response from the server. @@ -35,6 +36,7 @@ type Options struct { func ParseOptions() *Options { options := &Options{} + flag.StringVar(&options.Target, "target", "", "Target is a single target to scan using template") flag.StringVar(&options.Templates, "t", "", "Template input file/files to run on host") flag.StringVar(&options.Targets, "l", "", "List of URLs to run templates on") flag.StringVar(&options.Output, "o", "", "File to write output to (optional)") diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 4fcbde33..47960b46 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -39,7 +39,7 @@ func New(options *Options) (*Runner, error) { if err := runner.updateTemplates(); err != nil { return nil, err } - if (options.Templates == "" || options.Targets == "" && !options.Stdin) && options.UpdateTemplates { + if (options.Templates == "" || (options.Targets == "" && !options.Stdin && options.Target == "")) && options.UpdateTemplates { os.Exit(0) } @@ -55,6 +55,16 @@ func New(options *Options) (*Runner, error) { runner.tempFile = tempInput.Name() tempInput.Close() } + // If we have single target, write it to a new file + if options.Target != "" { + tempInput, err := ioutil.TempFile("", "stdin-input-*") + if err != nil { + return nil, err + } + tempInput.WriteString(options.Target) + runner.tempFile = tempInput.Name() + tempInput.Close() + } // Create the output file if asked if options.Output != "" { @@ -205,7 +215,7 @@ func (r *Runner) processTemplateRequest(template *templates.Template, request in // Handle a list of hosts as argument if r.options.Targets != "" { file, err = os.Open(r.options.Targets) - } else if r.options.Stdin { + } else if r.options.Stdin || r.options.Target != "" { file, err = os.Open(r.tempFile) } if err != nil { diff --git a/internal/runner/validate.go b/internal/runner/validate.go index 37855c34..a3fb0a04 100644 --- a/internal/runner/validate.go +++ b/internal/runner/validate.go @@ -19,7 +19,7 @@ func (options *Options) validateOptions() error { return errors.New("no template/templates provided") } - if options.Targets == "" && !options.Stdin && !options.UpdateTemplates { + if options.Targets == "" && !options.Stdin && options.Target == "" && !options.UpdateTemplates { return errors.New("no target input provided") }