Skip to content

Commit

Permalink
Added -templates-version flag to list template version
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice3man543 committed Oct 19, 2020
1 parent f607878 commit fefb028
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion v2/internal/runner/config.go
Expand Up @@ -27,7 +27,7 @@ const nucleiConfigFilename = ".nuclei-config.json"
var reVersion = regexp.MustCompile(`\d+\.\d+\.\d+`)

// readConfiguration reads the nuclei configuration file from disk.
func (r *Runner) readConfiguration() (*nucleiConfig, error) {
func readConfiguration() (*nucleiConfig, error) {
home, err := os.UserHomeDir()
if err != nil {
return nil, err
Expand Down
10 changes: 10 additions & 0 deletions v2/internal/runner/options.go
Expand Up @@ -22,6 +22,7 @@ type Options struct {
JSON bool // JSON writes json output to files
JSONRequests bool // write requests/responses for matches in JSON output
EnableProgressBar bool // Enable progrss bar
TemplatesVersion bool // Show the templates installed version
TemplateList bool // List available templates
Stdin bool // Stdin specifies whether stdin input was given to the process
StopAtFirstMatch bool // Stop processing template at first full match (this may break chained requests)
Expand Down Expand Up @@ -84,6 +85,7 @@ func ParseOptions() *Options {
flag.BoolVar(&options.StopAtFirstMatch, "stop-at-first-match", false, "Stop processing http requests at first match (this may break template/workflow logic)")
flag.IntVar(&options.BulkSize, "bulk-size", 150, "Number of hosts analyzed in parallel per template")
flag.BoolVar(&options.NoMeta, "no-meta", false, "Don't display metadata for the matches")
flag.BoolVar(&options.TemplatesVersion, "templates-version", false, "Shows the installed nuclei-templates version")
flag.Parse()

// Check if stdin pipe was given
Expand All @@ -99,6 +101,14 @@ func ParseOptions() *Options {
gologger.Infof("Current Version: %s\n", Version)
os.Exit(0)
}
if options.TemplatesVersion {
config, err := readConfiguration()
if err != nil {
gologger.Fatalf("Could not read template configuration: %s\n", err)
}
gologger.Infof("Current nuclei-templates version: %s (%s)\n", config.CurrentVersion, config.TemplatesDirectory)
os.Exit(0)
}

// Validate the options passed by the user and if any
// invalid options have been used, exit.
Expand Down
10 changes: 4 additions & 6 deletions v2/internal/runner/update.go
Expand Up @@ -38,13 +38,11 @@ func (r *Runner) updateTemplates() error {
}

templatesConfigFile := path.Join(home, nucleiConfigFilename)
if _, statErr := os.Stat(templatesConfigFile); !os.IsNotExist(statErr) {
config, readErr := r.readConfiguration()

if readErr != nil {
return readErr
if _, err := os.Stat(templatesConfigFile); !os.IsNotExist(err) {
config, err := readConfiguration()
if err != nil {
return err
}

r.templatesConfig = config
}

Expand Down

0 comments on commit fefb028

Please sign in to comment.