mirror of https://github.com/daffainfo/nuclei.git
Merge pull request #1561 from projectdiscovery/issue-1543-rand-seed
Implementing incremental expression replacementdev
commit
249937ca72
|
@ -41,7 +41,6 @@ func evaluate(data string, base map[string]interface{}) (string, error) {
|
||||||
// - complex: containing helper functions [ + variables]
|
// - complex: containing helper functions [ + variables]
|
||||||
// literals like {{2+2}} are not considered expressions
|
// literals like {{2+2}} are not considered expressions
|
||||||
expressions := findExpressions(data, marker.ParenthesisOpen, marker.ParenthesisClose, mergeFunctions(dsl.HelperFunctions(), mapToFunctions(base)))
|
expressions := findExpressions(data, marker.ParenthesisOpen, marker.ParenthesisClose, mergeFunctions(dsl.HelperFunctions(), mapToFunctions(base)))
|
||||||
dynamicValues := make(map[string]interface{})
|
|
||||||
for _, expression := range expressions {
|
for _, expression := range expressions {
|
||||||
// replace variable placeholders with base values
|
// replace variable placeholders with base values
|
||||||
expression = replacer.Replace(expression, base)
|
expression = replacer.Replace(expression, base)
|
||||||
|
@ -54,10 +53,11 @@ func evaluate(data string, base map[string]interface{}) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
dynamicValues[expression] = result
|
// replace incrementally
|
||||||
|
data = replacer.ReplaceOne(data, expression, result)
|
||||||
}
|
}
|
||||||
// Replacer dynamic values if any in raw request and parse it
|
|
||||||
return replacer.Replace(data, dynamicValues), nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// maxIterations to avoid infinite loop
|
// maxIterations to avoid infinite loop
|
||||||
|
|
|
@ -31,3 +31,14 @@ func Replace(template string, values map[string]interface{}) string {
|
||||||
final := replacer.Replace(template)
|
final := replacer.Replace(template)
|
||||||
return final
|
return final
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace replaces one placeholder in template with one value on the fly.
|
||||||
|
func ReplaceOne(template string, key string, value interface{}) string {
|
||||||
|
data := replaceOneWithMarkers(template, key, value, marker.ParenthesisOpen, marker.ParenthesisClose)
|
||||||
|
return replaceOneWithMarkers(data, key, value, marker.General, marker.General)
|
||||||
|
}
|
||||||
|
|
||||||
|
// replaceOneWithMarkers is a helper function that perform one time replacement
|
||||||
|
func replaceOneWithMarkers(template, key string, value interface{}, openMarker, closeMarker string) string {
|
||||||
|
return strings.Replace(template, openMarker+key+closeMarker, types.ToString(value), 1)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue