Adding HexOrString helper

dev
mzack 2022-03-23 16:26:05 +01:00
parent d2fbf875cd
commit 55a4da5dab
2 changed files with 21 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package format
import (
"bytes"
"crypto/rand"
"fmt"
"strconv"
"strings"
@ -54,7 +55,9 @@ func MarkdownDescription(event *output.ResultEvent) string { // TODO remove the
if event.Request != "" {
builder.WriteString("\n**Request**\n\n```http\n")
builder.WriteString(event.Request)
token := make([]byte, 2500)
rand.Read(token)
builder.WriteString(types.ToHexOrString(token))
builder.WriteString("\n```\n")
}
if event.Response != "" {
@ -135,7 +138,7 @@ func MarkdownDescription(event *output.ResultEvent) string { // TODO remove the
if event.CURLCommand != "" {
builder.WriteString("\n**CURL Command**\n```\n")
builder.WriteString(event.CURLCommand)
builder.WriteString(types.ToHexOrString(event.CURLCommand))
builder.WriteString("\n```")
}

View File

@ -3,10 +3,12 @@
package types
import (
"encoding/hex"
"fmt"
"strconv"
"strings"
"github.com/asaskevich/govalidator"
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
)
@ -75,6 +77,20 @@ func ToString(data interface{}) string {
}
}
func ToHexOrString(data interface{}) string {
switch s := data.(type) {
case string:
if govalidator.IsASCII(s) {
return s
}
return hex.Dump([]byte(s))
case []byte:
return hex.Dump(s)
default:
return fmt.Sprintf("%v", data)
}
}
// ToStringSlice casts an interface to a []string type.
func ToStringSlice(i interface{}) []string {
var a []string