2021-10-01 14:24:45 +03:00
|
|
|
package responsehighlighter
|
|
|
|
|
|
|
|
|
|
import (
|
2021-10-08 20:18:00 +03:00
|
|
|
"strconv"
|
2021-10-01 14:24:45 +03:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/logrusorgru/aurora"
|
|
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
|
|
|
|
|
)
|
|
|
|
|
|
2021-10-30 13:17:47 +03:00
|
|
|
var colorFunction = aurora.Green
|
2021-10-08 20:18:00 +03:00
|
|
|
|
2021-10-30 13:17:47 +03:00
|
|
|
func Highlight(operatorResult *operators.Result, response string, noColor, hexDump bool) string {
|
2021-10-01 14:24:45 +03:00
|
|
|
result := response
|
|
|
|
|
if operatorResult != nil && !noColor {
|
|
|
|
|
for _, matches := range operatorResult.Matches {
|
|
|
|
|
if len(matches) > 0 {
|
|
|
|
|
for _, currentMatch := range matches {
|
2021-10-30 13:17:47 +03:00
|
|
|
if hexDump {
|
|
|
|
|
highlightedHexDump, err := toHighLightedHexDump(result, currentMatch)
|
|
|
|
|
if err == nil {
|
|
|
|
|
result = highlightedHexDump.String()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result = strings.ReplaceAll(result, currentMatch, addColor(currentMatch))
|
|
|
|
|
}
|
2021-10-01 14:24:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
}
|
2021-10-05 13:56:02 +03:00
|
|
|
|
2021-10-08 20:18:00 +03:00
|
|
|
func CreateStatusCodeSnippet(response string, statusCode int) string {
|
|
|
|
|
if strings.HasPrefix(response, "HTTP/") {
|
|
|
|
|
strStatusCode := strconv.Itoa(statusCode)
|
|
|
|
|
return response[:strings.Index(response, strStatusCode)+len(strStatusCode)]
|
2021-10-05 13:56:02 +03:00
|
|
|
}
|
2021-10-08 20:18:00 +03:00
|
|
|
return ""
|
2021-10-05 13:56:02 +03:00
|
|
|
}
|
2021-10-30 13:17:47 +03:00
|
|
|
|
|
|
|
|
func addColor(value string) string {
|
|
|
|
|
return colorFunction(value).String()
|
|
|
|
|
}
|