Skip to content

Commit

Permalink
feat: add -enable-global-matchers flag (#5857)
Browse files Browse the repository at this point in the history
* feat: add `-enable-global-matchers` flag

Signed-off-by: Dwi Siswanto <[email protected]>

* refactor(templates): use embedded `types.Options` in `Template`

Signed-off-by: Dwi Siswanto <[email protected]>

* feat(lib): add `EnableGlobalMatchersTemplates` SDK opt

Signed-off-by: Dwi Siswanto <[email protected]>

---------

Signed-off-by: Dwi Siswanto <[email protected]>
  • Loading branch information
dwisiswant0 authored Nov 27, 2024
1 parent b2d4efe commit 3a07fa9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/nuclei/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)

Expand Down
8 changes: 8 additions & 0 deletions lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion pkg/templates/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,19 @@ 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
// templates.
//
// 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
Expand Down
4 changes: 3 additions & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a07fa9

Please sign in to comment.