From 3a07fa9c228783f8ba6586a2b86e48d3233f7380 Mon Sep 17 00:00:00 2001 From: Dwi Siswanto <25837540+dwisiswant0@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:07:59 +0700 Subject: [PATCH] feat: add `-enable-global-matchers` flag (#5857) * feat: add `-enable-global-matchers` flag Signed-off-by: Dwi Siswanto * refactor(templates): use embedded `types.Options` in `Template` Signed-off-by: Dwi Siswanto * feat(lib): add `EnableGlobalMatchersTemplates` SDK opt Signed-off-by: Dwi Siswanto --------- Signed-off-by: Dwi Siswanto --- cmd/nuclei/main.go | 1 + lib/config.go | 8 ++++++++ pkg/templates/compile.go | 7 ++++++- pkg/types/types.go | 4 +++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/nuclei/main.go b/cmd/nuclei/main.go index ae9fd8812..a4ba02ddd 100644 --- a/cmd/nuclei/main.go +++ b/cmd/nuclei/main.go @@ -264,6 +264,7 @@ on extensive configurability, massive extensibility and ease of use.`) flagSet.BoolVar(&options.EnableCodeTemplates, "code", false, "enable loading code protocol-based templates"), flagSet.BoolVarP(&options.DisableUnsignedTemplates, "disable-unsigned-templates", "dut", false, "disable running unsigned templates or templates with mismatched signature"), flagSet.BoolVarP(&options.EnableSelfContainedTemplates, "enable-self-contained", "esc", false, "enable loading self-contained templates"), + flagSet.BoolVarP(&options.EnableGlobalMatchersTemplates, "enable-global-matchers", "egm", false, "enable loading global matchers templates"), flagSet.BoolVar(&options.EnableFileTemplates, "file", false, "enable loading file templates"), ) diff --git a/lib/config.go b/lib/config.go index 97df0a2fb..f2decdc14 100644 --- a/lib/config.go +++ b/lib/config.go @@ -393,6 +393,14 @@ func EnableSelfContainedTemplates() NucleiSDKOptions { } } +// EnableGlobalMatchersTemplates allows loading/executing global-matchers templates +func EnableGlobalMatchersTemplates() NucleiSDKOptions { + return func(e *NucleiEngine) error { + e.opts.EnableGlobalMatchersTemplates = true + return nil + } +} + // EnableFileTemplates allows loading/executing file protocol templates func EnableFileTemplates() NucleiSDKOptions { return func(e *NucleiEngine) error { diff --git a/pkg/templates/compile.go b/pkg/templates/compile.go index b4005afe8..af83d071a 100644 --- a/pkg/templates/compile.go +++ b/pkg/templates/compile.go @@ -112,7 +112,8 @@ func Parse(filePath string, preprocessor Preprocessor, options protocols.Executo // isGlobalMatchersEnabled checks if any of requests in the template // have global matchers enabled. It iterates through all requests and // returns true if at least one request has global matchers enabled; -// otherwise, it returns false. +// otherwise, it returns false. If global matchers templates are not +// enabled in the options, the method will immediately return false. // // Note: This method only checks the `RequestsHTTP` // field of the template, which is specific to http-protocol-based @@ -120,6 +121,10 @@ func Parse(filePath string, preprocessor Preprocessor, options protocols.Executo // // TODO: support all protocols. func (template *Template) isGlobalMatchersEnabled() bool { + if !template.Options.Options.EnableGlobalMatchersTemplates { + return false + } + for _, request := range template.RequestsHTTP { if request.GlobalMatchers { return true diff --git a/pkg/types/types.go b/pkg/types/types.go index 42674ebe3..976e16b26 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -383,8 +383,10 @@ type Options struct { EnableCodeTemplates bool // DisableUnsignedTemplates disables processing of unsigned templates DisableUnsignedTemplates bool - // EnableSelfContainedTemplates disables processing of self-contained templates + // EnableSelfContainedTemplates enables processing of self-contained templates EnableSelfContainedTemplates bool + // EnableGlobalMatchersTemplates enables processing of global-matchers templates + EnableGlobalMatchersTemplates bool // EnableFileTemplates enables file templates EnableFileTemplates bool // Disables cloud upload