HD Moore f26996cb89
Remove singletons from Nuclei engine (continuation of #6210) (#6296)
* introducing execution id

* wip

* .

* adding separate execution context id

* lint

* vet

* fixing pg dialers

* test ignore

* fixing loader FD limit

* test

* fd fix

* wip: remove CloseProcesses() from dev merge

* wip: fix merge issue

* protocolstate: stop memguarding on last dialer delete

* avoid data race in dialers.RawHTTPClient

* use shared logger and avoid race conditions

* use shared logger and avoid race conditions

* go mod

* patch executionId into compiled template cache

* clean up comment in Parse

* go mod update

* bump echarts

* address merge issues

* fix use of gologger

* switch cmd/nuclei to options.Logger

* address merge issues with go.mod

* go vet: address copy of lock with new Copy function

* fixing tests

* disable speed control

* fix nil ExecuterOptions

* removing deprecated code

* fixing result print

* default logger

* cli default logger

* filter warning from results

* fix performance test

* hardcoding path

* disable upload

* refactor(runner): uses `Warning` instead of `Print` for `pdcpUploadErrMsg`

Signed-off-by: Dwi Siswanto <git@dw1.io>

* Revert "disable upload"

This reverts commit 114fbe6663361bf41cf8b2645fd2d57083d53682.

* Revert "hardcoding path"

This reverts commit cf12ca800e0a0e974bd9fd4826a24e51547f7c00.

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
Co-authored-by: Dwi Siswanto <git@dw1.io>
Co-authored-by: Dwi Siswanto <25837540+dwisiswant0@users.noreply.github.com>
2025-07-10 01:17:26 +05:30
..
2023-10-17 17:44:13 +05:30
2023-10-17 17:44:13 +05:30

multi protocol execution

Implementation

when template is unmarshalled, if it uses more than one protocol, then order of protocols is preserved and is same is passed to Executor multiproto is engine/backend for TemplateExecutor which takes care of sharing logic between protocols and executing them in order

Execution

when multi protocol template is executed , all protocol requests present in Queue are executed in order and dynamic values extracted are added to template context.

  • Protocol Responses apart from extracted internal:true values response fields/values of protocol are added to template context at ExecutorOptions.TemplateCtx which takes care of sync and other issues if any. all response fields are prefixed with template type prefix ex: ssl_subject_dn

Adding New Protocol to multi protocol execution logic

while logic/implementation of multi protocol execution is abstracted. it requires 3 statements to be added in newly implemented protocol to make response fields of that protocol available to global context

  • Add request.options.GetTemplateCtx(f.input.MetaInput).GetAll() to variablesMap in ExecuteWithResults Method just above request.options.Variables.Evaluate
// example
	values := generators.MergeMaps(payloadValues, hostnameVariables, request.options.GetTemplateCtx(f.input.MetaInput).GetAll())
	variablesMap := request.options.Variables.Evaluate(values)
  • Add all response fields to template context just after response map is available
	outputEvent := request.responseToDSLMap(compiledRequest, response, domain, question, traceData)
	// expose response variables in proto_var format
	// this is no-op if the template is not a multi protocol template
	request.options.AddTemplateVars(request.Type(),request.ID, outputEvent)
  • Append all available template context values to outputEvent
	// add variables from template context before matching/extraction
	outputEvent = generators.MergeMaps(outputEvent, request.options.GetTemplateCtx(f.input.MetaInput).GetAll())

adding these 3 statements takes care of all logic related to multi protocol execution

Exceptions

  • statements 1 & 2 are intentionally skipped in file protocol to avoid redundant data
    • file/dir input paths don't contain variables or are used in path (yet)
    • since files are processed by scanning each line. adding statement 2 will unintenionally load all file(s) data