mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 19:35:27 +00:00
* use parsed options while signing * update project layout to v3 * fix .gitignore * remove example template * misc updates * bump tlsx version * hide template sig warning with env * js: retain value while using log * fix nil pointer derefernce * misc doc update --------- Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
50 lines
2.2 KiB
Go
50 lines
2.2 KiB
Go
package eventcreator
|
|
|
|
import (
|
|
"github.com/projectdiscovery/gologger"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/operators"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/output"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/protocols"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/utils/vardump"
|
|
"golang.org/x/text/cases"
|
|
"golang.org/x/text/language"
|
|
)
|
|
|
|
// CreateEvent wraps the outputEvent with the result of the operators defined on the request
|
|
func CreateEvent(request protocols.Request, outputEvent output.InternalEvent, isResponseDebug bool) *output.InternalWrappedEvent {
|
|
return CreateEventWithAdditionalOptions(request, outputEvent, isResponseDebug, nil)
|
|
}
|
|
|
|
// CreateEventWithAdditionalOptions wraps the outputEvent with the result of the operators defined on the request
|
|
// and enables extending the resulting event with additional attributes or values.
|
|
func CreateEventWithAdditionalOptions(request protocols.Request, outputEvent output.InternalEvent, isResponseDebug bool,
|
|
addAdditionalOptions func(internalWrappedEvent *output.InternalWrappedEvent)) *output.InternalWrappedEvent {
|
|
event := &output.InternalWrappedEvent{InternalEvent: outputEvent}
|
|
|
|
// Dump response variables if ran in debug mode
|
|
if vardump.EnableVarDump {
|
|
protoName := cases.Title(language.English).String(request.Type().String())
|
|
gologger.Debug().Msgf("%v Protocol response variables: \n%s\n", protoName, vardump.DumpVariables(outputEvent))
|
|
}
|
|
for _, compiledOperator := range request.GetCompiledOperators() {
|
|
if compiledOperator != nil {
|
|
result, ok := compiledOperator.Execute(outputEvent, request.Match, request.Extract, isResponseDebug)
|
|
if ok && result != nil {
|
|
event.OperatorsResult = result
|
|
if addAdditionalOptions != nil {
|
|
addAdditionalOptions(event)
|
|
}
|
|
event.Results = append(event.Results, request.MakeResultEvent(event)...)
|
|
}
|
|
}
|
|
}
|
|
return event
|
|
}
|
|
|
|
func CreateEventWithOperatorResults(request protocols.Request, internalEvent output.InternalEvent, operatorResult *operators.Result) *output.InternalWrappedEvent {
|
|
event := &output.InternalWrappedEvent{InternalEvent: internalEvent}
|
|
event.OperatorsResult = operatorResult
|
|
event.Results = append(event.Results, request.MakeResultEvent(event)...)
|
|
return event
|
|
}
|