nuclei/v2/pkg/tmplexec/flow/options.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

49 lines
1.4 KiB
Go

package flow
import (
"strings"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
)
// ProtoOptions are options that can be passed to flow protocol callback
// ex: dns(protoOptions) <- protoOptions are optional and can be anything
type ProtoOptions struct {
Hide bool
Async bool
protoName string
reqIDS []string
}
// Examples
// dns() <- callback without any options
// dns(1) or dns(1,3) <- callback with index of protocol in template request at 1 or 1 and 3
// dns("probe-http") or dns("extract-vpc","probe-http") <- callback with id's instead of index of request in template
// dns({hide:true}) or dns({hide:true,async:true}) <- callback with protocol options
// hide - hides result/event from output & sdk
// async - executes protocols in parallel (implicit wait no need to specify wait)
// Note: all of these options are optional and can be combined together in any order
// LoadOptions loads the protocol options from a map
func (P *ProtoOptions) LoadOptions(m map[string]interface{}) {
P.Hide = GetBool(m["hide"])
P.Async = GetBool(m["async"])
}
// GetBool returns bool value from interface
func GetBool(value interface{}) bool {
if value == nil {
return false
}
switch v := value.(type) {
case bool:
return v
default:
tmpValue := types.ToString(value)
if strings.EqualFold(tmpValue, "true") {
return true
}
}
return false
}