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

View File

@ -28,7 +28,7 @@ func (request *Request) Match(data map[string]interface{}, matcher *matchers.Mat
if !ok { if !ok {
return false, []string{} 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: case matchers.SizeMatcher:
return matcher.Result(matcher.MatchSize(len(item))), []string{} return matcher.Result(matcher.MatchSize(len(item))), []string{}
case matchers.WordsMatcher: case matchers.WordsMatcher:

View File

@ -28,7 +28,7 @@ func (request *Request) Match(data map[string]interface{}, matcher *matchers.Mat
if !ok { if !ok {
return false, []string{} 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: case matchers.SizeMatcher:
return matcher.Result(matcher.MatchSize(len(item))), []string{} return matcher.Result(matcher.MatchSize(len(item))), []string{}
case matchers.WordsMatcher: case matchers.WordsMatcher: