From c6df7fbd43b37c0502fc7ee64b12a48ee3a3e43d Mon Sep 17 00:00:00 2001 From: Manuel Bua Date: Sun, 2 Aug 2020 13:49:16 +0200 Subject: [PATCH] Refactor template resolution logic for reusability --- v2/internal/runner/runner.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/v2/internal/runner/runner.go b/v2/internal/runner/runner.go index c675c20d3..d70902886 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -189,15 +189,14 @@ func isNewPath(path string, pathMap map[string]bool) bool { return true } -// RunEnumeration sets up the input layer for giving input nuclei. -// binary and runs the actual enumeration -func (r *Runner) RunEnumeration() { +// getTemplatesFor parses the specified input template definitions and returns a list of unique, absolute template paths. +func (r *Runner) getTemplatesFor(definitions []string) []string { // keeps track of processed dirs and files processed := make(map[string]bool) allTemplates := []string{} // parses user input, handle file/directory cases and produce a list of unique templates - for _, t := range r.options.Templates { + for _, t := range definitions { var absPath string var err error @@ -293,6 +292,15 @@ func (r *Runner) RunEnumeration() { } } + return allTemplates +} + +// RunEnumeration sets up the input layer for giving input nuclei. +// binary and runs the actual enumeration +func (r *Runner) RunEnumeration() { + // resolves input templates + allTemplates := r.getTemplatesFor(r.options.Templates) + // 0 matches means no templates were found in directory if len(allTemplates) == 0 { gologger.Fatalf("Error, no templates were found.\n")