nuclei/v2/pkg/tmplexec/interface.go
Tarun Koyalwar f7fe99f806
add flow support in template (i.e javascript scripting) (#4015)
* add flow logic

* progress

* working POC

* fix string slice normalization issue in variables

* update

* fix nil panic

* remove poll()

* load file with sandbox and more

* fix failing integration tests

* JS: log: print in vardump format

* fix missing id in protocols

* fix proto prefix in template context

* flow: add unit tests

* conditional flow support using flow

* fix proto callbacks + more unit tests

* adds integration test

* conditional flow: check if req has any matchers

* fix lint error

* deprecate iterate-all+ missing multi-proto implementation

* fix ip input in raw request

* JS: feat dedupe object+ more builtin funcs

* feat: hide protocol result using hide

* feat: async execution

* complete async execution support

* fix condition-flow without any matchers

* refactor: template executer package (tmplexec)

* flow executor working

* fix data race in templateCtx

* templateCtx redesign

* fix failing unit test

* add multiprotocol support to deprecated syntax

* fix race condition in utils & tlsx

* add documentation in flow package

* remove regions.txt file

* fix minor issue with self contained templates

* fix typos of copilot

* dep + misc update

* fix reqID: use req.Type instead of template.Type

---------

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
2023-08-31 18:03:01 +05:30

34 lines
1.3 KiB
Go

package tmplexec
import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/contextargs"
"github.com/projectdiscovery/nuclei/v2/pkg/tmplexec/flow"
"github.com/projectdiscovery/nuclei/v2/pkg/tmplexec/generic"
"github.com/projectdiscovery/nuclei/v2/pkg/tmplexec/multiproto"
)
var (
_ TemplateEngine = &generic.Generic{}
_ TemplateEngine = &flow.FlowExecutor{}
_ TemplateEngine = &multiproto.MultiProtocol{}
)
// TemplateEngine is a template executor with different functionality
// Ex:
// 1. generic => executes all protocol requests one after another (Done)
// 2. flow => executes protocol requests based on how they are defined in flow (Done)
// 3. multiprotocol => executes multiple protocols in parallel (Done)
type TemplateEngine interface {
// Note: below methods only need to implement extra / engine specific functionality
// basic request compilation , callbacks , cli output callback etc are handled by `TemplateExecuter` and no need to do it again
// Extra Compilation (if any)
Compile() error
// ExecuteWithResults executes the template and returns results
ExecuteWithResults(input *contextargs.Context, callback protocols.OutputEventCallback) error
// Name returns name of template engine
Name() string
}