2020-04-03 22:15:39 +00:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/gologger"
|
2020-07-01 10:47:24 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/requests"
|
2020-04-03 22:15:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Options contains the configuration options for tuning
|
|
|
|
// the template requesting process.
|
|
|
|
type Options struct {
|
2020-06-24 22:23:37 +00:00
|
|
|
Debug bool // Debug mode allows debugging request/responses for the engine
|
2020-07-13 22:01:46 +00:00
|
|
|
Templates multiStringFlag // Signature specifies the template/templates to use
|
2020-06-25 16:10:20 +00:00
|
|
|
Target string // Target is a single URL/Domain to scan usng a template
|
2020-06-24 22:23:37 +00:00
|
|
|
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.
|
|
|
|
Retries int // Retries is the number of times to retry the request
|
|
|
|
Output string // Output is the file to write found subdomains to.
|
|
|
|
ProxyURL string // ProxyURL is the URL for the proxy server
|
|
|
|
ProxySocksURL string // ProxySocksURL is the URL for the proxy socks server
|
|
|
|
Silent bool // Silent suppresses any extra text and only writes found URLs on screen.
|
|
|
|
Version bool // Version specifies if we should just show version and exit
|
|
|
|
Verbose bool // Verbose flag indicates whether to show verbose output or not
|
|
|
|
NoColor bool // No-Color disables the colored output.
|
|
|
|
CustomHeaders requests.CustomHeaders // Custom global headers
|
|
|
|
UpdateTemplates bool // UpdateTemplates updates the templates installed at startup
|
|
|
|
TemplatesDirectory string // TemplatesDirectory is the directory to use for storing templates
|
2020-06-27 14:49:43 +00:00
|
|
|
JSON bool // JSON writes json output to files
|
2020-04-03 22:15:39 +00:00
|
|
|
|
|
|
|
Stdin bool // Stdin specifies whether stdin input was given to the process
|
|
|
|
}
|
|
|
|
|
2020-07-13 22:01:46 +00:00
|
|
|
type multiStringFlag []string
|
|
|
|
|
|
|
|
func (m *multiStringFlag) String() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *multiStringFlag) Set(value string) error {
|
|
|
|
*m = append(*m, value)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-03 22:15:39 +00:00
|
|
|
// ParseOptions parses the command line flags provided by a user
|
|
|
|
func ParseOptions() *Options {
|
|
|
|
options := &Options{}
|
|
|
|
|
2020-06-25 16:10:20 +00:00
|
|
|
flag.StringVar(&options.Target, "target", "", "Target is a single target to scan using template")
|
2020-07-13 22:01:46 +00:00
|
|
|
flag.Var(&options.Templates, "t","Template input file/files to run on host. Can be used multiple times.")
|
2020-04-04 11:54:31 +00:00
|
|
|
flag.StringVar(&options.Targets, "l", "", "List of URLs to run templates on")
|
2020-04-03 22:15:39 +00:00
|
|
|
flag.StringVar(&options.Output, "o", "", "File to write output to (optional)")
|
2020-04-27 18:19:53 +00:00
|
|
|
flag.StringVar(&options.ProxyURL, "proxy-url", "", "URL of the proxy server")
|
2020-04-28 02:01:25 +00:00
|
|
|
flag.StringVar(&options.ProxySocksURL, "proxy-socks-url", "", "URL of the proxy socks server")
|
2020-04-04 11:54:31 +00:00
|
|
|
flag.BoolVar(&options.Silent, "silent", false, "Show only results in output")
|
|
|
|
flag.BoolVar(&options.Version, "version", false, "Show version of nuclei")
|
2020-04-03 22:15:39 +00:00
|
|
|
flag.BoolVar(&options.Verbose, "v", false, "Show Verbose output")
|
|
|
|
flag.BoolVar(&options.NoColor, "nC", false, "Don't Use colors in output")
|
2020-04-04 12:40:26 +00:00
|
|
|
flag.IntVar(&options.Threads, "c", 10, "Number of concurrent requests to make")
|
|
|
|
flag.IntVar(&options.Timeout, "timeout", 5, "Time to wait in seconds before timeout")
|
|
|
|
flag.IntVar(&options.Retries, "retries", 1, "Number of times to retry a failed request")
|
2020-05-21 22:23:38 +00:00
|
|
|
flag.Var(&options.CustomHeaders, "H", "Custom Header.")
|
2020-06-22 14:00:01 +00:00
|
|
|
flag.BoolVar(&options.Debug, "debug", false, "Allow debugging of request/responses")
|
2020-06-24 22:23:37 +00:00
|
|
|
flag.BoolVar(&options.UpdateTemplates, "update-templates", false, "Update Templates updates the installed templates (optional)")
|
2020-06-27 15:22:54 +00:00
|
|
|
flag.StringVar(&options.TemplatesDirectory, "update-directory", "", "Directory to use for storing nuclei-templates")
|
2020-06-27 14:49:43 +00:00
|
|
|
flag.BoolVar(&options.JSON, "json", false, "Write json output to files")
|
2020-04-03 22:15:39 +00:00
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
// Check if stdin pipe was given
|
|
|
|
options.Stdin = hasStdin()
|
|
|
|
|
|
|
|
// Read the inputs and configure the logging
|
|
|
|
options.configureOutput()
|
|
|
|
|
|
|
|
// Show the user the banner
|
|
|
|
showBanner()
|
|
|
|
|
|
|
|
if options.Version {
|
|
|
|
gologger.Infof("Current Version: %s\n", Version)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2020-04-26 01:18:10 +00:00
|
|
|
|
2020-04-03 22:15:39 +00:00
|
|
|
// Validate the options passed by the user and if any
|
|
|
|
// invalid options have been used, exit.
|
|
|
|
err := options.validateOptions()
|
|
|
|
if err != nil {
|
|
|
|
gologger.Fatalf("Program exiting: %s\n", err)
|
|
|
|
}
|
|
|
|
return options
|
|
|
|
}
|
|
|
|
|
|
|
|
func hasStdin() bool {
|
|
|
|
fi, err := os.Stdin.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if fi.Mode()&os.ModeNamedPipe == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|