2021-10-01 14:24:45 +03:00
|
|
|
package responsehighlighter
|
|
|
|
|
|
|
|
|
|
import (
|
2021-10-05 13:56:02 +03:00
|
|
|
"fmt"
|
2021-10-01 14:24:45 +03:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/logrusorgru/aurora"
|
|
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Highlight(operatorResult *operators.Result, response string, noColor bool) string {
|
|
|
|
|
result := response
|
|
|
|
|
if operatorResult != nil && !noColor {
|
2021-10-07 20:54:12 +03:00
|
|
|
colorizer := aurora.NewAurora(true)
|
2021-10-01 14:24:45 +03:00
|
|
|
for _, matches := range operatorResult.Matches {
|
|
|
|
|
if len(matches) > 0 {
|
|
|
|
|
for _, currentMatch := range matches {
|
|
|
|
|
result = strings.ReplaceAll(result, currentMatch, colorizer.Green(currentMatch).String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
}
|
2021-10-05 13:56:02 +03:00
|
|
|
|
|
|
|
|
func CreateHTTPStatusMatcherSnippets(statusCode int) []string {
|
|
|
|
|
httpVersions := []string{"0.9", "1.0", "1.1", "2", "2.0", "3", "3.0"}
|
|
|
|
|
var matcherValues = make([]string, 0, len(httpVersions))
|
|
|
|
|
|
|
|
|
|
for _, httpVersion := range httpVersions {
|
|
|
|
|
matcherValues = append(matcherValues, fmt.Sprintf("HTTP/%s %d", httpVersion, statusCode))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return matcherValues
|
|
|
|
|
}
|