[feature] Add coloring to debug information #999

* Code review changes
This commit is contained in:
forgedhallpass 2021-10-08 20:18:00 +03:00
parent f96168fc2c
commit fc66195b28
3 changed files with 10 additions and 12 deletions

View File

@ -1,7 +1,7 @@
package responsehighlighter
import (
"fmt"
"strconv"
"strings"
"github.com/logrusorgru/aurora"
@ -9,10 +9,11 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
)
var colorizer = aurora.NewAurora(true)
func Highlight(operatorResult *operators.Result, response string, noColor bool) string {
result := response
if operatorResult != nil && !noColor {
colorizer := aurora.NewAurora(true)
for _, matches := range operatorResult.Matches {
if len(matches) > 0 {
for _, currentMatch := range matches {
@ -25,13 +26,10 @@ func Highlight(operatorResult *operators.Result, response string, noColor bool)
return result
}
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))
func CreateStatusCodeSnippet(response string, statusCode int) string {
if strings.HasPrefix(response, "HTTP/") {
strStatusCode := strconv.Itoa(statusCode)
return response[:strings.Index(response, strStatusCode)+len(strStatusCode)]
}
return matcherValues
return ""
}

View File

@ -28,7 +28,7 @@ func (request *Request) Match(data map[string]interface{}, matcher *matchers.Mat
if !ok {
return false, []string{}
}
return matcher.Result(matcher.MatchStatusCode(statusCode)), responsehighlighter.CreateHTTPStatusMatcherSnippets(statusCode)
return matcher.Result(matcher.MatchStatusCode(statusCode)), []string{responsehighlighter.CreateStatusCodeSnippet(data["response"].(string), statusCode)}
case matchers.SizeMatcher:
return matcher.Result(matcher.MatchSize(len(item))), []string{}
case matchers.WordsMatcher:

View File

@ -28,7 +28,7 @@ func (request *Request) Match(data map[string]interface{}, matcher *matchers.Mat
if !ok {
return false, []string{}
}
return matcher.Result(matcher.MatchStatusCode(statusCode)), responsehighlighter.CreateHTTPStatusMatcherSnippets(statusCode)
return matcher.Result(matcher.MatchStatusCode(statusCode)), []string{responsehighlighter.CreateStatusCodeSnippet(data["response"].(string), statusCode)}
case matchers.SizeMatcher:
return matcher.Result(matcher.MatchSize(len(item))), []string{}
case matchers.WordsMatcher: