mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 14:25:25 +00:00
Do not show AND matcher information in the command line output if debug is not enabled #1081
This commit is contained in:
parent
8392143944
commit
435ec5cd5d
@ -108,7 +108,7 @@ type MatchFunc func(data map[string]interface{}, matcher *matchers.Matcher) (boo
|
|||||||
type ExtractFunc func(data map[string]interface{}, matcher *extractors.Extractor) map[string]struct{}
|
type ExtractFunc func(data map[string]interface{}, matcher *extractors.Extractor) map[string]struct{}
|
||||||
|
|
||||||
// Execute executes the operators on data and returns a result structure
|
// Execute executes the operators on data and returns a result structure
|
||||||
func (operators *Operators) Execute(data map[string]interface{}, match MatchFunc, extract ExtractFunc) (*Result, bool) {
|
func (operators *Operators) Execute(data map[string]interface{}, match MatchFunc, extract ExtractFunc, isDebug bool) (*Result, bool) {
|
||||||
matcherCondition := operators.GetMatchersCondition()
|
matcherCondition := operators.GetMatchersCondition()
|
||||||
|
|
||||||
var matches bool
|
var matches bool
|
||||||
@ -140,9 +140,14 @@ func (operators *Operators) Execute(data map[string]interface{}, match MatchFunc
|
|||||||
|
|
||||||
for matcherIndex, matcher := range operators.Matchers {
|
for matcherIndex, matcher := range operators.Matchers {
|
||||||
if isMatch, matched := match(data, matcher); isMatch {
|
if isMatch, matched := match(data, matcher); isMatch {
|
||||||
|
if isDebug { // matchers without an explicit name or with AND condition should only be made visible if debug is enabled
|
||||||
matcherName := getMatcherName(matcher, matcherIndex)
|
matcherName := getMatcherName(matcher, matcherIndex)
|
||||||
result.Matches[matcherName] = matched
|
result.Matches[matcherName] = matched
|
||||||
|
} else { // if it's a "named" matcher with OR condition, then display it
|
||||||
|
if matcherCondition == matchers.ORCondition && matcher.Name != "" {
|
||||||
|
result.Matches[matcher.Name] = matched
|
||||||
|
}
|
||||||
|
}
|
||||||
matches = true
|
matches = true
|
||||||
} else if matcherCondition == matchers.ANDCondition {
|
} else if matcherCondition == matchers.ANDCondition {
|
||||||
if len(result.DynamicValues) > 0 {
|
if len(result.DynamicValues) > 0 {
|
||||||
|
|||||||
@ -67,7 +67,7 @@ func (e *Executer) Execute(input string) (bool, error) {
|
|||||||
dynamicValues := make(map[string]interface{})
|
dynamicValues := make(map[string]interface{})
|
||||||
err := e.requests.ExecuteWithResults(input, dynamicValues, previous, func(event *output.InternalWrappedEvent) {
|
err := e.requests.ExecuteWithResults(input, dynamicValues, previous, func(event *output.InternalWrappedEvent) {
|
||||||
for _, operator := range e.operators {
|
for _, operator := range e.operators {
|
||||||
result, matched := operator.operator.Execute(event.InternalEvent, e.requests.Match, e.requests.Extract)
|
result, matched := operator.operator.Execute(event.InternalEvent, e.requests.Match, e.requests.Extract, e.options.Options.Debug || e.options.Options.DebugResponse)
|
||||||
if matched && result != nil {
|
if matched && result != nil {
|
||||||
event.OperatorsResult = result
|
event.OperatorsResult = result
|
||||||
event.InternalEvent["template-id"] = operator.templateID
|
event.InternalEvent["template-id"] = operator.templateID
|
||||||
@ -98,7 +98,7 @@ func (e *Executer) ExecuteWithResults(input string, callback protocols.OutputEve
|
|||||||
dynamicValues := make(map[string]interface{})
|
dynamicValues := make(map[string]interface{})
|
||||||
err := e.requests.ExecuteWithResults(input, dynamicValues, nil, func(event *output.InternalWrappedEvent) {
|
err := e.requests.ExecuteWithResults(input, dynamicValues, nil, func(event *output.InternalWrappedEvent) {
|
||||||
for _, operator := range e.operators {
|
for _, operator := range e.operators {
|
||||||
result, matched := operator.operator.Execute(event.InternalEvent, e.requests.Match, e.requests.Extract)
|
result, matched := operator.operator.Execute(event.InternalEvent, e.requests.Match, e.requests.Extract, e.options.Options.Debug || e.options.Options.DebugResponse)
|
||||||
if matched && result != nil {
|
if matched && result != nil {
|
||||||
event.OperatorsResult = result
|
event.OperatorsResult = result
|
||||||
event.InternalEvent["template-id"] = operator.templateID
|
event.InternalEvent["template-id"] = operator.templateID
|
||||||
|
|||||||
@ -6,16 +6,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CreateEvent wraps the outputEvent with the result of the operators defined on the request
|
// CreateEvent wraps the outputEvent with the result of the operators defined on the request
|
||||||
func CreateEvent(request protocols.Request, outputEvent output.InternalEvent) *output.InternalWrappedEvent {
|
func CreateEvent(request protocols.Request, outputEvent output.InternalEvent, isResponseDebug bool) *output.InternalWrappedEvent {
|
||||||
return CreateEventWithAdditionalOptions(request, outputEvent, func(internalWrappedEvent *output.InternalWrappedEvent) {})
|
return CreateEventWithAdditionalOptions(request, outputEvent, isResponseDebug, func(internalWrappedEvent *output.InternalWrappedEvent) {})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
// 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, addAdditionalOptions func(internalWrappedEvent *output.InternalWrappedEvent)) *output.InternalWrappedEvent {
|
func CreateEventWithAdditionalOptions(request protocols.Request, outputEvent output.InternalEvent, isResponseDebug bool,
|
||||||
|
addAdditionalOptions func(internalWrappedEvent *output.InternalWrappedEvent)) *output.InternalWrappedEvent {
|
||||||
event := &output.InternalWrappedEvent{InternalEvent: outputEvent}
|
event := &output.InternalWrappedEvent{InternalEvent: outputEvent}
|
||||||
for _, compiledOperator := range request.GetCompiledOperators() {
|
for _, compiledOperator := range request.GetCompiledOperators() {
|
||||||
if compiledOperator != nil {
|
if compiledOperator != nil {
|
||||||
result, ok := compiledOperator.Execute(outputEvent, request.Match, request.Extract)
|
result, ok := compiledOperator.Execute(outputEvent, request.Match, request.Extract, isResponseDebug)
|
||||||
if ok && result != nil {
|
if ok && result != nil {
|
||||||
event.OperatorsResult = result
|
event.OperatorsResult = result
|
||||||
addAdditionalOptions(event)
|
addAdditionalOptions(event)
|
||||||
|
|||||||
@ -145,7 +145,7 @@ func (c *Client) processInteractionForRequest(interaction *server.Interaction, d
|
|||||||
data.Event.InternalEvent["interactsh_protocol"] = interaction.Protocol
|
data.Event.InternalEvent["interactsh_protocol"] = interaction.Protocol
|
||||||
data.Event.InternalEvent["interactsh_request"] = interaction.RawRequest
|
data.Event.InternalEvent["interactsh_request"] = interaction.RawRequest
|
||||||
data.Event.InternalEvent["interactsh_response"] = interaction.RawResponse
|
data.Event.InternalEvent["interactsh_response"] = interaction.RawResponse
|
||||||
result, matched := data.Operators.Execute(data.Event.InternalEvent, data.MatchFunc, data.ExtractFunc)
|
result, matched := data.Operators.Execute(data.Event.InternalEvent, data.MatchFunc, data.ExtractFunc, false)
|
||||||
if !matched || result == nil {
|
if !matched || result == nil {
|
||||||
return false // if we don't match, return
|
return false // if we don't match, return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,45 +73,20 @@ func (request *Request) Extract(data map[string]interface{}, extractor *extracto
|
|||||||
|
|
||||||
// responseToDSLMap converts a DNS response to a map for use in DSL matching
|
// responseToDSLMap converts a DNS response to a map for use in DSL matching
|
||||||
func (request *Request) responseToDSLMap(req, resp *dns.Msg, host, matched string) output.InternalEvent {
|
func (request *Request) responseToDSLMap(req, resp *dns.Msg, host, matched string) output.InternalEvent {
|
||||||
data := make(output.InternalEvent, 11)
|
return output.InternalEvent{
|
||||||
|
"host": host,
|
||||||
// Some data regarding the request metadata
|
"matched": matched,
|
||||||
data["host"] = host
|
"request": req.String(),
|
||||||
data["matched"] = matched
|
"rcode": resp.Rcode,
|
||||||
data["request"] = req.String()
|
"question": questionToString(resp.Question),
|
||||||
|
"extra": rrToString(resp.Extra),
|
||||||
data["rcode"] = resp.Rcode
|
"answer": rrToString(resp.Answer),
|
||||||
buffer := &bytes.Buffer{}
|
"ns": rrToString(resp.Ns),
|
||||||
for _, question := range resp.Question {
|
"raw": resp.String(),
|
||||||
buffer.WriteString(question.String())
|
"template-id": request.options.TemplateID,
|
||||||
|
"template-info": request.options.TemplateInfo,
|
||||||
|
"template-path": request.options.TemplatePath,
|
||||||
}
|
}
|
||||||
data["question"] = buffer.String()
|
|
||||||
buffer.Reset()
|
|
||||||
|
|
||||||
for _, extra := range resp.Extra {
|
|
||||||
buffer.WriteString(extra.String())
|
|
||||||
}
|
|
||||||
data["extra"] = buffer.String()
|
|
||||||
buffer.Reset()
|
|
||||||
|
|
||||||
for _, answer := range resp.Answer {
|
|
||||||
buffer.WriteString(answer.String())
|
|
||||||
}
|
|
||||||
data["answer"] = buffer.String()
|
|
||||||
buffer.Reset()
|
|
||||||
|
|
||||||
for _, ns := range resp.Ns {
|
|
||||||
buffer.WriteString(ns.String())
|
|
||||||
}
|
|
||||||
data["ns"] = buffer.String()
|
|
||||||
buffer.Reset()
|
|
||||||
|
|
||||||
rawData := resp.String()
|
|
||||||
data["raw"] = rawData
|
|
||||||
data["template-id"] = request.options.TemplateID
|
|
||||||
data["template-info"] = request.options.TemplateInfo
|
|
||||||
data["template-path"] = request.options.TemplatePath
|
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeResultEvent creates a result event from internal wrapped event
|
// MakeResultEvent creates a result event from internal wrapped event
|
||||||
@ -134,3 +109,19 @@ func (request *Request) MakeResultEventItem(wrapped *output.InternalWrappedEvent
|
|||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func rrToString(resourceRecords []dns.RR) string { // TODO rewrite with generics when available
|
||||||
|
buffer := &bytes.Buffer{}
|
||||||
|
for _, resourceRecord := range resourceRecords {
|
||||||
|
buffer.WriteString(resourceRecord.String())
|
||||||
|
}
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func questionToString(resourceRecords []dns.Question) string {
|
||||||
|
buffer := &bytes.Buffer{}
|
||||||
|
for _, resourceRecord := range resourceRecords {
|
||||||
|
buffer.WriteString(resourceRecord.String())
|
||||||
|
}
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|||||||
@ -236,13 +236,15 @@ func TestDNSMakeResult(t *testing.T) {
|
|||||||
event := request.responseToDSLMap(req, resp, "one.one.one.one", "one.one.one.one")
|
event := request.responseToDSLMap(req, resp, "one.one.one.one", "one.one.one.one")
|
||||||
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
||||||
if request.CompiledOperators != nil {
|
if request.CompiledOperators != nil {
|
||||||
result, ok := request.CompiledOperators.Execute(event, request.Match, request.Extract)
|
result, ok := request.CompiledOperators.Execute(event, request.Match, request.Extract, false)
|
||||||
if ok && result != nil {
|
if ok && result != nil {
|
||||||
finalEvent.OperatorsResult = result
|
finalEvent.OperatorsResult = result
|
||||||
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
require.Equal(t, 1, len(finalEvent.Results), "could not get correct number of results")
|
require.Equal(t, 1, len(finalEvent.Results), "could not get correct number of results")
|
||||||
require.Equal(t, "test", finalEvent.Results[0].MatcherName, "could not get correct matcher name of results")
|
resultEvent := finalEvent.Results[0]
|
||||||
require.Equal(t, "1.1.1.1", finalEvent.Results[0].ExtractedResults[0], "could not get correct extracted results")
|
require.Equal(t, "test", resultEvent.MatcherName, "could not get correct matcher name of results")
|
||||||
|
require.Equal(t, "1.1.1.1", resultEvent.ExtractedResults[0], "could not get correct extracted results")
|
||||||
|
require.Equal(t, "one.one.one.one", resultEvent.Matched, "could not get matched value")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,9 +8,9 @@ import (
|
|||||||
"github.com/projectdiscovery/gologger"
|
"github.com/projectdiscovery/gologger"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/eventcreator"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/eventcreator"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/responsehighlighter"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/responsehighlighter"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ protocols.Request = &Request{}
|
var _ protocols.Request = &Request{}
|
||||||
@ -62,7 +62,7 @@ func (request *Request) ExecuteWithResults(input string, metadata /*TODO review
|
|||||||
outputEvent[k] = v
|
outputEvent[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
event := eventcreator.CreateEvent(request, outputEvent)
|
event := eventcreator.CreateEvent(request, outputEvent, request.options.Options.Debug || request.options.Options.DebugResponse)
|
||||||
|
|
||||||
if request.options.Options.Debug || request.options.Options.DebugResponse {
|
if request.options.Options.Debug || request.options.Options.DebugResponse {
|
||||||
gologger.Debug().Msgf("[%s] Dumped DNS response for %s", request.options.TemplateID, domain)
|
gologger.Debug().Msgf("[%s] Dumped DNS response for %s", request.options.TemplateID, domain)
|
||||||
|
|||||||
@ -66,18 +66,16 @@ func (request *Request) Extract(data map[string]interface{}, extractor *extracto
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// responseToDSLMap converts a DNS response to a map for use in DSL matching
|
// responseToDSLMap converts a file response to a map for use in DSL matching
|
||||||
func (request *Request) responseToDSLMap(raw, host, matched string) output.InternalEvent {
|
func (request *Request) responseToDSLMap(raw, inputFilePath, matchedFileName string) output.InternalEvent {
|
||||||
data := make(output.InternalEvent, 5)
|
return output.InternalEvent{
|
||||||
|
"path": inputFilePath,
|
||||||
// Some data regarding the request metadata
|
"matched": matchedFileName,
|
||||||
data["path"] = host
|
"raw": raw,
|
||||||
data["matched"] = matched
|
"template-id": request.options.TemplateID,
|
||||||
data["raw"] = raw
|
"template-info": request.options.TemplateInfo,
|
||||||
data["template-id"] = request.options.TemplateID
|
"template-path": request.options.TemplatePath,
|
||||||
data["template-info"] = request.options.TemplateInfo
|
}
|
||||||
data["template-path"] = request.options.TemplatePath
|
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeResultEvent creates a result event from internal wrapped event
|
// MakeResultEvent creates a result event from internal wrapped event
|
||||||
|
|||||||
@ -159,7 +159,62 @@ func TestFileOperatorExtract(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileMakeResult(t *testing.T) {
|
func TestFileMakeResultWithOrMatcher(t *testing.T) {
|
||||||
|
expectedValue := []string{"1.1.1.1"}
|
||||||
|
namedMatcherName := "test"
|
||||||
|
|
||||||
|
finalEvent := testFileMakeResultOperators(t, "or")
|
||||||
|
require.Equal(t, namedMatcherName, finalEvent.Results[0].MatcherName)
|
||||||
|
require.Equal(t, expectedValue, finalEvent.OperatorsResult.Matches[namedMatcherName], "could not get matched value")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFileMakeResultWithAndMatcher(t *testing.T) {
|
||||||
|
finalEvent := testFileMakeResultOperators(t, "and")
|
||||||
|
require.Equal(t, "", finalEvent.Results[0].MatcherName)
|
||||||
|
require.Empty(t, finalEvent.OperatorsResult.Matches)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testFileMakeResultOperators(t *testing.T, matcherCondition string) *output.InternalWrappedEvent {
|
||||||
|
expectedValue := []string{"1.1.1.1"}
|
||||||
|
namedMatcherName := "test"
|
||||||
|
matcher := []*matchers.Matcher{
|
||||||
|
{
|
||||||
|
Part: "raw",
|
||||||
|
Type: "word",
|
||||||
|
Words: expectedValue,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: namedMatcherName,
|
||||||
|
Part: "raw",
|
||||||
|
Type: "word",
|
||||||
|
Words: expectedValue,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedValues := map[string][]string{
|
||||||
|
"word-1": expectedValue,
|
||||||
|
namedMatcherName: expectedValue,
|
||||||
|
}
|
||||||
|
|
||||||
|
finalEvent := testFileMakeResult(t, matcher, matcherCondition, true)
|
||||||
|
for matcherName, matchedValues := range expectedValues {
|
||||||
|
var matchesOne = false
|
||||||
|
for i := 0; i <= len(expectedValue); i++ {
|
||||||
|
resultEvent := finalEvent.Results[i]
|
||||||
|
if matcherName == resultEvent.MatcherName {
|
||||||
|
matchesOne = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
require.True(t, matchesOne)
|
||||||
|
require.Equal(t, matchedValues, finalEvent.OperatorsResult.Matches[matcherName], "could not get matched value")
|
||||||
|
}
|
||||||
|
|
||||||
|
finalEvent = testFileMakeResult(t, matcher, matcherCondition, false)
|
||||||
|
require.Equal(t, 1, len(finalEvent.Results))
|
||||||
|
return finalEvent
|
||||||
|
}
|
||||||
|
|
||||||
|
func testFileMakeResult(t *testing.T, matchers []*matchers.Matcher, matcherCondition string, isDebug bool) *output.InternalWrappedEvent {
|
||||||
options := testutils.DefaultOptions
|
options := testutils.DefaultOptions
|
||||||
|
|
||||||
testutils.Init(options)
|
testutils.Init(options)
|
||||||
@ -171,12 +226,8 @@ func TestFileMakeResult(t *testing.T) {
|
|||||||
Extensions: []string{"*", ".lock"},
|
Extensions: []string{"*", ".lock"},
|
||||||
ExtensionDenylist: []string{".go"},
|
ExtensionDenylist: []string{".go"},
|
||||||
Operators: operators.Operators{
|
Operators: operators.Operators{
|
||||||
Matchers: []*matchers.Matcher{{
|
MatchersCondition: matcherCondition,
|
||||||
Name: "test",
|
Matchers: matchers,
|
||||||
Part: "raw",
|
|
||||||
Type: "word",
|
|
||||||
Words: []string{"1.1.1.1"},
|
|
||||||
}},
|
|
||||||
Extractors: []*extractors.Extractor{{
|
Extractors: []*extractors.Extractor{{
|
||||||
Part: "raw",
|
Part: "raw",
|
||||||
Type: "regex",
|
Type: "regex",
|
||||||
@ -191,20 +242,24 @@ func TestFileMakeResult(t *testing.T) {
|
|||||||
err := request.Compile(executerOpts)
|
err := request.Compile(executerOpts)
|
||||||
require.Nil(t, err, "could not compile file request")
|
require.Nil(t, err, "could not compile file request")
|
||||||
|
|
||||||
resp := "test-data\r\n1.1.1.1\r\n"
|
matchedFileName := "test.txt"
|
||||||
event := request.responseToDSLMap(resp, "one.one.one.one", "one.one.one.one")
|
fileContent := "test-data\r\n1.1.1.1\r\n"
|
||||||
|
|
||||||
|
event := request.responseToDSLMap(fileContent, "/tmp", matchedFileName)
|
||||||
require.Len(t, event, 6, "could not get correct number of items in dsl map")
|
require.Len(t, event, 6, "could not get correct number of items in dsl map")
|
||||||
require.Equal(t, resp, event["raw"], "could not get correct resp")
|
require.Equal(t, fileContent, event["raw"], "could not get correct resp")
|
||||||
|
|
||||||
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
||||||
if request.CompiledOperators != nil {
|
if request.CompiledOperators != nil {
|
||||||
result, ok := request.CompiledOperators.Execute(event, request.Match, request.Extract)
|
result, ok := request.CompiledOperators.Execute(event, request.Match, request.Extract, isDebug)
|
||||||
if ok && result != nil {
|
if ok && result != nil {
|
||||||
finalEvent.OperatorsResult = result
|
finalEvent.OperatorsResult = result
|
||||||
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
require.Equal(t, 1, len(finalEvent.Results), "could not get correct number of results")
|
resultEvent := finalEvent.Results[0]
|
||||||
require.Equal(t, "test", finalEvent.Results[0].MatcherName, "could not get correct matcher name of results")
|
require.Equal(t, "1.1.1.1", resultEvent.ExtractedResults[0], "could not get correct extracted results")
|
||||||
require.Equal(t, "1.1.1.1", finalEvent.Results[0].ExtractedResults[0], "could not get correct extracted results")
|
require.Equal(t, matchedFileName, resultEvent.Matched, "could not get matched value")
|
||||||
|
|
||||||
|
return finalEvent
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ func (request *Request) ExecuteWithResults(input string, metadata /*TODO review
|
|||||||
outputEvent[k] = v
|
outputEvent[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
event := eventcreator.CreateEvent(request, outputEvent)
|
event := eventcreator.CreateEvent(request, outputEvent, request.options.Options.Debug || request.options.Options.DebugResponse)
|
||||||
|
|
||||||
if request.options.Options.Debug || request.options.Options.DebugResponse {
|
if request.options.Options.Debug || request.options.Options.DebugResponse {
|
||||||
gologger.Info().Msgf("[%s] Dumped file request for %s", request.options.TemplateID, filePath)
|
gologger.Info().Msgf("[%s] Dumped file request for %s", request.options.TemplateID, filePath)
|
||||||
|
|||||||
@ -64,19 +64,17 @@ func (request *Request) Extract(data map[string]interface{}, extractor *extracto
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// responseToDSLMap converts a DNS response to a map for use in DSL matching
|
// responseToDSLMap converts a headless response to a map for use in DSL matching
|
||||||
func (request *Request) responseToDSLMap(resp, req, host, matched string) output.InternalEvent {
|
func (request *Request) responseToDSLMap(resp, req, host, matched string) output.InternalEvent {
|
||||||
data := make(output.InternalEvent, 5)
|
return output.InternalEvent{
|
||||||
|
"host": host,
|
||||||
// Some data regarding the request metadata
|
"matched": matched,
|
||||||
data["host"] = host
|
"req": req,
|
||||||
data["matched"] = matched
|
"data": resp,
|
||||||
data["req"] = req
|
"template-id": request.options.TemplateID,
|
||||||
data["data"] = resp
|
"template-info": request.options.TemplateInfo,
|
||||||
data["template-id"] = request.options.TemplateID
|
"template-path": request.options.TemplatePath,
|
||||||
data["template-info"] = request.options.TemplateInfo
|
}
|
||||||
data["template-path"] = request.options.TemplatePath
|
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeResultEvent creates a result event from internal wrapped event
|
// MakeResultEvent creates a result event from internal wrapped event
|
||||||
|
|||||||
@ -65,7 +65,7 @@ func (request *Request) ExecuteWithResults(input string, metadata, previous outp
|
|||||||
outputEvent[k] = v
|
outputEvent[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
event := eventcreator.CreateEvent(request, outputEvent)
|
event := eventcreator.CreateEvent(request, outputEvent, request.options.Options.Debug || request.options.Options.DebugResponse)
|
||||||
|
|
||||||
if request.options.Options.Debug || request.options.Options.DebugResponse {
|
if request.options.Options.Debug || request.options.Options.DebugResponse {
|
||||||
gologger.Debug().Msgf("[%s] Dumped Headless response for %s", request.options.TemplateID, input)
|
gologger.Debug().Msgf("[%s] Dumped Headless response for %s", request.options.TemplateID, input)
|
||||||
|
|||||||
@ -97,8 +97,8 @@ func getMatchPart(part string, data output.InternalEvent) (string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// responseToDSLMap converts an HTTP response to a map for use in DSL matching
|
// responseToDSLMap converts an HTTP response to a map for use in DSL matching
|
||||||
func (request *Request) responseToDSLMap(resp *http.Response, host, matched, rawReq, rawResp, body, headers string, duration time.Duration, extra map[string]interface{}) map[string]interface{} {
|
func (request *Request) responseToDSLMap(resp *http.Response, host, matched, rawReq, rawResp, body, headers string, duration time.Duration, extra map[string]interface{}) output.InternalEvent {
|
||||||
data := make(map[string]interface{}, len(extra)+8+len(resp.Header)+len(resp.Cookies()))
|
data := make(output.InternalEvent, 12+len(extra)+len(resp.Header)+len(resp.Cookies()))
|
||||||
for k, v := range extra {
|
for k, v := range extra {
|
||||||
data[k] = v
|
data[k] = v
|
||||||
}
|
}
|
||||||
|
|||||||
@ -262,7 +262,7 @@ func TestHTTPMakeResult(t *testing.T) {
|
|||||||
event["ip"] = "192.169.1.1"
|
event["ip"] = "192.169.1.1"
|
||||||
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
||||||
if request.CompiledOperators != nil {
|
if request.CompiledOperators != nil {
|
||||||
result, ok := request.CompiledOperators.Execute(event, request.Match, request.Extract)
|
result, ok := request.CompiledOperators.Execute(event, request.Match, request.Extract, false)
|
||||||
if ok && result != nil {
|
if ok && result != nil {
|
||||||
finalEvent.OperatorsResult = result
|
finalEvent.OperatorsResult = result
|
||||||
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
||||||
|
|||||||
@ -477,7 +477,7 @@ func (request *Request) executeRequest(reqURL string, generatedRequest *generate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event := eventcreator.CreateEventWithAdditionalOptions(request, finalEvent, func(internalWrappedEvent *output.InternalWrappedEvent) {
|
event := eventcreator.CreateEventWithAdditionalOptions(request, finalEvent, request.options.Options.Debug || request.options.Options.DebugResponse, func(internalWrappedEvent *output.InternalWrappedEvent) {
|
||||||
internalWrappedEvent.OperatorsResult.PayloadValues = generatedRequest.meta
|
internalWrappedEvent.OperatorsResult.PayloadValues = generatedRequest.meta
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -64,20 +64,18 @@ func (request *Request) Extract(data map[string]interface{}, extractor *extracto
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// responseToDSLMap converts a DNS response to a map for use in DSL matching
|
// responseToDSLMap converts a network response to a map for use in DSL matching
|
||||||
func (request *Request) responseToDSLMap(req, resp, raw, host, matched string) output.InternalEvent {
|
func (request *Request) responseToDSLMap(req, resp, raw, host, matched string) output.InternalEvent {
|
||||||
data := make(output.InternalEvent, 6)
|
return output.InternalEvent{
|
||||||
|
"host": host,
|
||||||
// Some data regarding the request metadata
|
"matched": matched,
|
||||||
data["host"] = host
|
"request": req,
|
||||||
data["matched"] = matched
|
"data": resp, // Data is the last bytes read
|
||||||
data["request"] = req
|
"raw": raw, // Raw is the full transaction data for network
|
||||||
data["data"] = resp // Data is the last bytes read
|
"template-id": request.options.TemplateID,
|
||||||
data["raw"] = raw // Raw is the full transaction data for network
|
"template-info": request.options.TemplateInfo,
|
||||||
data["template-id"] = request.options.TemplateID
|
"template-path": request.options.TemplatePath,
|
||||||
data["template-info"] = request.options.TemplateInfo
|
}
|
||||||
data["template-path"] = request.options.TemplatePath
|
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeResultEvent creates a result event from internal wrapped event
|
// MakeResultEvent creates a result event from internal wrapped event
|
||||||
|
|||||||
@ -192,7 +192,7 @@ func TestNetworkMakeResult(t *testing.T) {
|
|||||||
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
||||||
event["ip"] = "192.168.1.1"
|
event["ip"] = "192.168.1.1"
|
||||||
if request.CompiledOperators != nil {
|
if request.CompiledOperators != nil {
|
||||||
result, ok := request.CompiledOperators.Execute(event, request.Match, request.Extract)
|
result, ok := request.CompiledOperators.Execute(event, request.Match, request.Extract, false)
|
||||||
if ok && result != nil {
|
if ok && result != nil {
|
||||||
finalEvent.OperatorsResult = result
|
finalEvent.OperatorsResult = result
|
||||||
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
||||||
|
|||||||
@ -209,7 +209,7 @@ func (request *Request) executeRequestWithPayloads(actualAddress, address, input
|
|||||||
|
|
||||||
var event *output.InternalWrappedEvent
|
var event *output.InternalWrappedEvent
|
||||||
if interactURL == "" {
|
if interactURL == "" {
|
||||||
event = eventcreator.CreateEventWithAdditionalOptions(request, outputEvent, func(wrappedEvent *output.InternalWrappedEvent) {
|
event = eventcreator.CreateEventWithAdditionalOptions(request, outputEvent, request.options.Options.Debug || request.options.Options.DebugResponse, func(wrappedEvent *output.InternalWrappedEvent) {
|
||||||
wrappedEvent.OperatorsResult.PayloadValues = payloads
|
wrappedEvent.OperatorsResult.PayloadValues = payloads
|
||||||
})
|
})
|
||||||
callback(event)
|
callback(event)
|
||||||
|
|||||||
@ -93,8 +93,8 @@ func getMatchPart(part string, data output.InternalEvent) (string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// responseToDSLMap converts an HTTP response to a map for use in DSL matching
|
// responseToDSLMap converts an HTTP response to a map for use in DSL matching
|
||||||
func (request *Request) responseToDSLMap(resp *http.Response, host, matched, rawReq, rawResp, body, headers string, duration time.Duration, extra map[string]interface{}) map[string]interface{} {
|
func (request *Request) responseToDSLMap(resp *http.Response, host, matched, rawReq, rawResp, body, headers string, duration time.Duration, extra map[string]interface{}) output.InternalEvent {
|
||||||
data := make(map[string]interface{}, len(extra)+8+len(resp.Header)+len(resp.Cookies()))
|
data := make(output.InternalEvent, 12+len(extra)+len(resp.Header)+len(resp.Cookies()))
|
||||||
for k, v := range extra {
|
for k, v := range extra {
|
||||||
data[k] = v
|
data[k] = v
|
||||||
}
|
}
|
||||||
|
|||||||
@ -204,7 +204,7 @@ func TestHTTPMakeResult(t *testing.T) {
|
|||||||
event["ip"] = "192.169.1.1"
|
event["ip"] = "192.169.1.1"
|
||||||
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
finalEvent := &output.InternalWrappedEvent{InternalEvent: event}
|
||||||
for _, operator := range request.compiledOperators {
|
for _, operator := range request.compiledOperators {
|
||||||
result, ok := operator.Execute(event, request.Match, request.Extract)
|
result, ok := operator.Execute(event, request.Match, request.Extract, false)
|
||||||
if ok && result != nil {
|
if ok && result != nil {
|
||||||
finalEvent.OperatorsResult = result
|
finalEvent.OperatorsResult = result
|
||||||
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
finalEvent.Results = request.MakeResultEvent(finalEvent)
|
||||||
|
|||||||
@ -85,7 +85,7 @@ func (request *Request) ExecuteWithResults(input string, metadata /*TODO review
|
|||||||
outputEvent[k] = v
|
outputEvent[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
event := eventcreator.CreateEvent(request, outputEvent)
|
event := eventcreator.CreateEvent(request, outputEvent, request.options.Options.Debug || request.options.Options.DebugResponse)
|
||||||
callback(event)
|
callback(event)
|
||||||
}(data)
|
}(data)
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user