Added internal extractor support to network templates

dev
Ice3man543 2021-07-06 18:34:25 +05:30
parent 93ab540b54
commit 0910d526af
2 changed files with 29 additions and 1 deletions

View File

@ -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
}

View File

@ -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
}
}
}
}