mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 19:45:28 +00:00
* refactor(vardump): use `godump` lib also increate limit char to `255`. Signed-off-by: Dwi Siswanto <git@dw1.io> * feat(vardump): add global var `Limit` Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(protocols): rm newline Signed-off-by: Dwi Siswanto <git@dw1.io> * feat(types): add `VarDumpLimit` option Signed-off-by: Dwi Siswanto <git@dw1.io> * test(vardump): add test cases Signed-off-by: Dwi Siswanto <git@dw1.io> * chore: tidy up mod Signed-off-by: Dwi Siswanto <git@dw1.io> --------- Signed-off-by: Dwi Siswanto <git@dw1.io>
58 lines
2.6 KiB
Go
58 lines
2.6 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: %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 {
|
|
// 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
|
|
}
|
|
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
|
|
}
|