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-08 20:18:00 +03:00
|
|
|
var colorizer = aurora.NewAurora(true)
|
|
|
|
|
|
2021-10-01 14:24:45 +03:00
|
|
|
func Highlight(operatorResult *operators.Result, response string, noColor bool) string {
|
|
|
|
|
result := response
|
|
|
|
|
if operatorResult != nil && !noColor {
|
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|