mirror of https://github.com/daffainfo/nuclei.git
Added validate flag to validate templates
parent
063fede82c
commit
94365a58dc
|
@ -96,6 +96,7 @@ based on templates offering massive extensibility and ease of use.`)
|
|||
set.IntVar(&options.InteractionsPollDuration, "interactions-poll-duration", 5, "Number of seconds before each interaction poll request")
|
||||
set.IntVar(&options.InteractionsColldownPeriod, "interactions-cooldown-period", 5, "Extra time for interaction polling before exiting")
|
||||
set.BoolVar(&options.VerboseVerbose, "vv", false, "Display Extra Verbose Information")
|
||||
set.BoolVar(&options.Validate, "validate", false, "Validate the passed templates to nuclei")
|
||||
_ = set.Parse()
|
||||
|
||||
if cfgFile != "" {
|
||||
|
|
|
@ -289,6 +289,14 @@ func (r *Runner) RunEnumeration() {
|
|||
if err != nil {
|
||||
gologger.Fatal().Msgf("Could not load templates from config: %s\n", err)
|
||||
}
|
||||
if r.options.Validate {
|
||||
if !store.ValidateTemplates(r.options.Templates) {
|
||||
gologger.Fatal().Msgf("An Error occured during templates validation\n")
|
||||
} else {
|
||||
gologger.Info().Msgf("All templates validated successfully\n")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
store.Load()
|
||||
|
||||
builder := &strings.Builder{}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package loader
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/projectdiscovery/gologger"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/catalog"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/loader/filter"
|
||||
|
@ -81,6 +83,40 @@ func (s *Store) Load() {
|
|||
s.workflows = s.LoadWorkflows(s.config.Workflows)
|
||||
}
|
||||
|
||||
// ValidateTemplates takes a list of templates and validates them
|
||||
// erroring out on discovering any faulty templates.
|
||||
func (s *Store) ValidateTemplates(templatesList []string) bool {
|
||||
includedTemplates := s.config.Catalog.GetTemplatesPath(templatesList)
|
||||
templatesMap := s.pathFilter.Match(includedTemplates)
|
||||
|
||||
notErrored := true
|
||||
for k := range templatesMap {
|
||||
_, err := s.loadTemplate(k, false)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "cannot create template executer") {
|
||||
continue
|
||||
}
|
||||
if err == filter.ErrExcluded {
|
||||
continue
|
||||
}
|
||||
notErrored = false
|
||||
gologger.Error().Msgf("Error occured loading template %s: %s\n", k, err)
|
||||
}
|
||||
_, err = templates.Parse(k, s.config.ExecutorOptions)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "cannot create template executer") {
|
||||
continue
|
||||
}
|
||||
if err == filter.ErrExcluded {
|
||||
continue
|
||||
}
|
||||
notErrored = false
|
||||
gologger.Error().Msgf("Error occured parsing template %s: %s\n", k, err)
|
||||
}
|
||||
}
|
||||
return notErrored
|
||||
}
|
||||
|
||||
// LoadTemplates takes a list of templates and returns paths for them
|
||||
func (s *Store) LoadTemplates(templatesList []string) []*templates.Template {
|
||||
includedTemplates := s.config.Catalog.GetTemplatesPath(templatesList)
|
||||
|
|
|
@ -104,6 +104,8 @@ type Options struct {
|
|||
Silent bool
|
||||
// Version specifies if we should just show version and exit
|
||||
Version bool
|
||||
// Validate validates the templates passed to nuclei.
|
||||
Validate bool
|
||||
// Verbose flag indicates whether to show verbose output or not
|
||||
Verbose bool
|
||||
VerboseVerbose bool
|
||||
|
|
Loading…
Reference in New Issue