mirror of https://github.com/daffainfo/nuclei.git
Merge pull request #1654 from projectdiscovery/duplicate-id-detect-validate
Added duplicate ID detection to validate + misc fixesdev
commit
c8b67b3fd5
|
@ -60,7 +60,11 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := nucleiRunner.RunEnumeration(); err != nil {
|
if err := nucleiRunner.RunEnumeration(); err != nil {
|
||||||
gologger.Fatal().Msgf("Could not run nuclei: %s\n", err)
|
if options.Validate {
|
||||||
|
gologger.Fatal().Msgf("Could not validate templates: %s\n", err)
|
||||||
|
} else {
|
||||||
|
gologger.Fatal().Msgf("Could not run nuclei: %s\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nucleiRunner.Close()
|
nucleiRunner.Close()
|
||||||
// on successful execution remove the resume file in case it exists
|
// on successful execution remove the resume file in case it exists
|
||||||
|
|
|
@ -148,6 +148,12 @@ func (store *Store) Load() {
|
||||||
store.workflows = store.LoadWorkflows(store.finalWorkflows)
|
store.workflows = store.LoadWorkflows(store.finalWorkflows)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var templateIDPathMap map[string]string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
templateIDPathMap = make(map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
// ValidateTemplates takes a list of templates and validates them
|
// ValidateTemplates takes a list of templates and validates them
|
||||||
// erroring out on discovering any faulty templates.
|
// erroring out on discovering any faulty templates.
|
||||||
func (store *Store) ValidateTemplates(templatesList, workflowsList []string) error {
|
func (store *Store) ValidateTemplates(templatesList, workflowsList []string) error {
|
||||||
|
@ -164,7 +170,7 @@ func (store *Store) ValidateTemplates(templatesList, workflowsList []string) err
|
||||||
if areTemplatesValid(store, filteredTemplatePaths) && areWorkflowsValid(store, filteredWorkflowPaths) {
|
if areTemplatesValid(store, filteredTemplatePaths) && areWorkflowsValid(store, filteredWorkflowPaths) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.New("an error occurred during templates validation")
|
return errors.New("errors occured during template validation")
|
||||||
}
|
}
|
||||||
|
|
||||||
func areWorkflowsValid(store *Store, filteredWorkflowPaths map[string]struct{}) bool {
|
func areWorkflowsValid(store *Store, filteredWorkflowPaths map[string]struct{}) bool {
|
||||||
|
@ -181,6 +187,7 @@ func areTemplatesValid(store *Store, filteredTemplatePaths map[string]struct{})
|
||||||
|
|
||||||
func areWorkflowOrTemplatesValid(store *Store, filteredTemplatePaths map[string]struct{}, isWorkflow bool, load func(templatePath string, tagFilter *filter.TagFilter) (bool, error)) bool {
|
func areWorkflowOrTemplatesValid(store *Store, filteredTemplatePaths map[string]struct{}, isWorkflow bool, load func(templatePath string, tagFilter *filter.TagFilter) (bool, error)) bool {
|
||||||
areTemplatesValid := true
|
areTemplatesValid := true
|
||||||
|
|
||||||
for templatePath := range filteredTemplatePaths {
|
for templatePath := range filteredTemplatePaths {
|
||||||
if _, err := load(templatePath, store.tagFilter); err != nil {
|
if _, err := load(templatePath, store.tagFilter); err != nil {
|
||||||
if isParsingError("Error occurred loading template %s: %s\n", templatePath, err) {
|
if isParsingError("Error occurred loading template %s: %s\n", templatePath, err) {
|
||||||
|
@ -195,8 +202,14 @@ func areWorkflowOrTemplatesValid(store *Store, filteredTemplatePaths map[string]
|
||||||
areTemplatesValid = false
|
areTemplatesValid = false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if existingTemplatePath, found := templateIDPathMap[template.ID]; !found {
|
||||||
|
templateIDPathMap[template.ID] = templatePath
|
||||||
|
} else {
|
||||||
|
areTemplatesValid = false
|
||||||
|
gologger.Warning().Msgf("Found duplicate template ID during validation '%s' => '%s': %s\n", templatePath, existingTemplatePath, template.ID)
|
||||||
|
}
|
||||||
if !isWorkflow && len(template.Workflows) > 0 {
|
if !isWorkflow && len(template.Workflows) > 0 {
|
||||||
return true
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isWorkflow {
|
if isWorkflow {
|
||||||
|
|
Loading…
Reference in New Issue