Skip to content

Commit

Permalink
Added internal extractor support to network templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice3man543 committed Jul 6, 2021
1 parent 93ab540 commit 0910d52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
18 changes: 18 additions & 0 deletions v2/pkg/operators/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,21 @@ func (r *Operators) Execute(data map[string]interface{}, match MatchFunc, extrac
}
return nil, false
}

// ExecuteInternalExtractors executes internal dynamic extractors
func (r *Operators) ExecuteInternalExtractors(data map[string]interface{}, extract ExtractFunc) map[string]interface{} {
dynamicValues := make(map[string]interface{})

// Start with the extractors first and evaluate them.
for _, extractor := range r.Extractors {
if !extractor.Internal {
continue
}
for match := range extract(data, extractor) {
if _, ok := dynamicValues[extractor.Name]; !ok {
dynamicValues[extractor.Name] = match
}
}
}
return dynamicValues
}
12 changes: 11 additions & 1 deletion v2/pkg/protocols/network/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,18 @@ func (r *Request) executeRequestWithPayloads(actualAddress, address, input strin
buffer := make([]byte, input.Read)
n, _ := conn.Read(buffer)
responseBuilder.Write(buffer[:n])

bufferStr := string(buffer[:n])
if input.Name != "" {
inputEvents[input.Name] = string(buffer[:n])
inputEvents[input.Name] = bufferStr
}

// Run any internal extractors for the request here and add found values to map.
if r.CompiledOperators != nil {
values := r.CompiledOperators.ExecuteInternalExtractors(map[string]interface{}{input.Name: bufferStr}, r.Extract)
for k, v := range values {
payloads[k] = v
}
}
}
}
Expand Down

0 comments on commit 0910d52

Please sign in to comment.