Fixed extractions + input path clear + misc

dev
Ice3man543 2021-01-14 18:27:48 +05:30
parent 7403ade437
commit 8b93d5e1d2
8 changed files with 8 additions and 12 deletions

View File

@ -121,7 +121,7 @@ func (r *Operators) Execute(data map[string]interface{}, match MatchFunc, extrac
} }
// Write a final string of output if matcher type is // Write a final string of output if matcher type is
// AND or if we have extractors for the mechanism too. // AND or if we have extractors for the mechanism too.
if len(result.Extracts) > 0 || matches { if len(result.Extracts) > 0 || len(result.OutputExtracts) > 0 || matches {
return result, true return result, true
} }
return nil, false return nil, false

View File

@ -54,7 +54,7 @@ type ResultEvent struct {
// TemplateID is the ID of the template for the result. // TemplateID is the ID of the template for the result.
TemplateID string `json:"templateID"` TemplateID string `json:"templateID"`
// Info contains information block of the template for the result. // Info contains information block of the template for the result.
Info map[string]string `json:"info"` Info map[string]string `json:"info,inline"`
// MatcherName is the name of the matcher matched if any. // MatcherName is the name of the matcher matched if any.
MatcherName string `json:"matcher_name,omitempty"` MatcherName string `json:"matcher_name,omitempty"`
// ExtractorName is the name of the extractor matched if any. // ExtractorName is the name of the extractor matched if any.

View File

@ -56,7 +56,7 @@ func (r *Request) ExecuteWithResults(input string, metadata output.InternalEvent
event := &output.InternalWrappedEvent{InternalEvent: ouputEvent} event := &output.InternalWrappedEvent{InternalEvent: ouputEvent}
if r.CompiledOperators != nil { if r.CompiledOperators != nil {
result, ok := r.Operators.Execute(ouputEvent, r.Match, r.Extract) result, ok := r.CompiledOperators.Execute(ouputEvent, r.Match, r.Extract)
if ok && result != nil { if ok && result != nil {
event.OperatorsResult = result event.OperatorsResult = result
event.Results = r.MakeResultEvent(event) event.Results = r.MakeResultEvent(event)

View File

@ -50,7 +50,7 @@ func (r *Request) ExecuteWithResults(input string, metadata output.InternalEvent
event := &output.InternalWrappedEvent{InternalEvent: ouputEvent} event := &output.InternalWrappedEvent{InternalEvent: ouputEvent}
if r.CompiledOperators != nil { if r.CompiledOperators != nil {
result, ok := r.Operators.Execute(ouputEvent, r.Match, r.Extract) result, ok := r.CompiledOperators.Execute(ouputEvent, r.Match, r.Extract)
if ok && result != nil { if ok && result != nil {
event.OperatorsResult = result event.OperatorsResult = result
event.Results = r.MakeResultEvent(event) event.Results = r.MakeResultEvent(event)

View File

@ -105,6 +105,8 @@ type generatedRequest struct {
// Make creates a http request for the provided input. // Make creates a http request for the provided input.
// It returns io.EOF as error when all the requests have been exhausted. // It returns io.EOF as error when all the requests have been exhausted.
func (r *requestGenerator) Make(baseURL string, dynamicValues map[string]interface{}) (*generatedRequest, error) { func (r *requestGenerator) Make(baseURL string, dynamicValues map[string]interface{}) (*generatedRequest, error) {
baseURL = strings.TrimSuffix(baseURL, "/")
data, payloads, ok := r.nextValue() data, payloads, ok := r.nextValue()
if !ok { if !ok {
return nil, io.EOF return nil, io.EOF
@ -155,9 +157,6 @@ func baseURLWithTemplatePrefs(data string, parsedURL *url.URL) string {
// MakeHTTPRequestFromModel creates a *http.Request from a request template // MakeHTTPRequestFromModel creates a *http.Request from a request template
func (r *requestGenerator) makeHTTPRequestFromModel(ctx context.Context, data string, values map[string]interface{}) (*generatedRequest, error) { func (r *requestGenerator) makeHTTPRequestFromModel(ctx context.Context, data string, values map[string]interface{}) (*generatedRequest, error) {
if strings.HasSuffix(values["BaseURL"].(string), "/") {
data = strings.TrimPrefix(data, "/")
}
URL := replacer.New(values).Replace(data) URL := replacer.New(values).Replace(data)
// Build a request on the specified URL // Build a request on the specified URL

View File

@ -96,9 +96,6 @@ func Parse(request, baseURL string, unsafe bool) (*Request, error) {
} else if strings.HasPrefix(rawRequest.Path, "?") { } else if strings.HasPrefix(rawRequest.Path, "?") {
rawRequest.Path = fmt.Sprintf("%s%s", parsedURL.Path, rawRequest.Path) rawRequest.Path = fmt.Sprintf("%s%s", parsedURL.Path, rawRequest.Path)
} }
if strings.HasSuffix(hostURL, "/") {
rawRequest.Path = strings.TrimPrefix(rawRequest.Path, "/")
}
rawRequest.FullURL = fmt.Sprintf("%s://%s%s", parsedURL.Scheme, strings.TrimSpace(hostURL), rawRequest.Path) rawRequest.FullURL = fmt.Sprintf("%s://%s%s", parsedURL.Scheme, strings.TrimSpace(hostURL), rawRequest.Path)
// Set the request body // Set the request body

View File

@ -330,7 +330,7 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, dynam
event := &output.InternalWrappedEvent{InternalEvent: ouputEvent} event := &output.InternalWrappedEvent{InternalEvent: ouputEvent}
if r.CompiledOperators != nil { if r.CompiledOperators != nil {
result, ok := r.Operators.Execute(ouputEvent, r.Match, r.Extract) result, ok := r.CompiledOperators.Execute(ouputEvent, r.Match, r.Extract)
if ok && result != nil { if ok && result != nil {
event.OperatorsResult = result event.OperatorsResult = result
result.PayloadValues = request.meta result.PayloadValues = request.meta

View File

@ -122,7 +122,7 @@ func (r *Request) executeAddress(actualAddress, address, input string, callback
event := &output.InternalWrappedEvent{InternalEvent: ouputEvent} event := &output.InternalWrappedEvent{InternalEvent: ouputEvent}
if r.CompiledOperators != nil { if r.CompiledOperators != nil {
result, ok := r.Operators.Execute(ouputEvent, r.Match, r.Extract) result, ok := r.CompiledOperators.Execute(ouputEvent, r.Match, r.Extract)
if ok && result != nil { if ok && result != nil {
event.OperatorsResult = result event.OperatorsResult = result
event.Results = r.MakeResultEvent(event) event.Results = r.MakeResultEvent(event)