2021-10-01 16:52:38 +03:00
|
|
|
package eventcreator
|
|
|
|
|
|
|
|
|
|
import (
|
2022-08-25 15:37:03 +05:30
|
|
|
"github.com/projectdiscovery/gologger"
|
2023-10-17 17:44:13 +05:30
|
|
|
"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"
|
2023-10-13 13:17:27 +05:30
|
|
|
"golang.org/x/text/cases"
|
|
|
|
|
"golang.org/x/text/language"
|
2021-10-01 16:52:38 +03:00
|
|
|
)
|
|
|
|
|
|
2021-10-07 20:54:12 +03:00
|
|
|
// CreateEvent wraps the outputEvent with the result of the operators defined on the request
|
2021-10-12 20:06:55 +03:00
|
|
|
func CreateEvent(request protocols.Request, outputEvent output.InternalEvent, isResponseDebug bool) *output.InternalWrappedEvent {
|
2022-02-23 13:54:46 +01:00
|
|
|
return CreateEventWithAdditionalOptions(request, outputEvent, isResponseDebug, nil)
|
2021-10-01 16:52:38 +03:00
|
|
|
}
|
|
|
|
|
|
2022-02-23 13:54:46 +01:00
|
|
|
// 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.
|
2021-10-12 20:06:55 +03:00
|
|
|
func CreateEventWithAdditionalOptions(request protocols.Request, outputEvent output.InternalEvent, isResponseDebug bool,
|
|
|
|
|
addAdditionalOptions func(internalWrappedEvent *output.InternalWrappedEvent)) *output.InternalWrappedEvent {
|
2021-10-01 16:52:38 +03:00
|
|
|
event := &output.InternalWrappedEvent{InternalEvent: outputEvent}
|
2022-08-25 15:37:03 +05:30
|
|
|
|
|
|
|
|
// Dump response variables if ran in debug mode
|
2022-11-01 20:28:50 +05:30
|
|
|
if vardump.EnableVarDump {
|
2023-10-13 13:17:27 +05:30
|
|
|
protoName := cases.Title(language.English).String(request.Type().String())
|
2024-10-14 21:01:36 +07:00
|
|
|
gologger.Debug().Msgf("%v Protocol response variables: %s\n", protoName, vardump.DumpVariables(outputEvent))
|
2022-08-25 15:37:03 +05:30
|
|
|
}
|
2021-10-01 16:52:38 +03:00
|
|
|
for _, compiledOperator := range request.GetCompiledOperators() {
|
|
|
|
|
if compiledOperator != nil {
|
2021-10-12 20:06:55 +03:00
|
|
|
result, ok := compiledOperator.Execute(outputEvent, request.Match, request.Extract, isResponseDebug)
|
2021-10-01 16:52:38 +03:00
|
|
|
if ok && result != nil {
|
2024-01-05 05:25:31 +05:30
|
|
|
// if result has both extracted values and dynamic values, put dynamic values in data
|
|
|
|
|
// and remove dynamic values to avoid skipping legitimate event
|
|
|
|
|
if (len(result.Extracts) > 0 || len(result.OutputExtracts) > 0) && len(result.DynamicValues) > 0 {
|
|
|
|
|
for k, v := range result.DynamicValues {
|
|
|
|
|
event.InternalEvent[k] = v
|
|
|
|
|
}
|
|
|
|
|
result.DynamicValues = nil
|
|
|
|
|
}
|
2021-10-01 16:52:38 +03:00
|
|
|
event.OperatorsResult = result
|
2022-02-23 13:54:46 +01:00
|
|
|
if addAdditionalOptions != nil {
|
|
|
|
|
addAdditionalOptions(event)
|
|
|
|
|
}
|
2021-10-06 21:53:03 +03:00
|
|
|
event.Results = append(event.Results, request.MakeResultEvent(event)...)
|
2021-10-01 16:52:38 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return event
|
|
|
|
|
}
|
2022-02-26 09:06:43 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|