2020-12-21 00:04:11 +05:30
|
|
|
package output
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
2022-02-10 15:59:05 +05:30
|
|
|
"strconv"
|
2024-01-12 23:10:00 +05:30
|
|
|
"strings"
|
2021-07-19 21:04:08 +03:00
|
|
|
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
2023-09-16 16:02:17 +05:30
|
|
|
mapsutil "github.com/projectdiscovery/utils/maps"
|
2020-12-21 00:04:11 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// formatScreen formats the output for showing on screen.
|
2021-02-26 13:13:11 +05:30
|
|
|
func (w *StandardWriter) formatScreen(output *ResultEvent) []byte {
|
2020-12-21 00:04:11 +05:30
|
|
|
builder := &bytes.Buffer{}
|
|
|
|
|
|
|
|
|
|
if !w.noMetadata {
|
2022-12-04 22:16:55 +05:30
|
|
|
if w.timestamp {
|
2021-08-27 19:12:06 +05:30
|
|
|
builder.WriteRune('[')
|
|
|
|
|
builder.WriteString(w.aurora.Cyan(output.Timestamp.Format("2006-01-02 15:04:05")).String())
|
|
|
|
|
builder.WriteString("] ")
|
|
|
|
|
}
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteRune('[')
|
2020-12-25 12:55:46 +05:30
|
|
|
builder.WriteString(w.aurora.BrightGreen(output.TemplateID).String())
|
2020-12-21 00:04:11 +05:30
|
|
|
|
2020-12-25 12:55:46 +05:30
|
|
|
if output.MatcherName != "" {
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteString(":")
|
2020-12-25 12:55:46 +05:30
|
|
|
builder.WriteString(w.aurora.BrightGreen(output.MatcherName).Bold().String())
|
2021-01-17 12:02:59 +05:30
|
|
|
} else if output.ExtractorName != "" {
|
|
|
|
|
builder.WriteString(":")
|
|
|
|
|
builder.WriteString(w.aurora.BrightGreen(output.ExtractorName).Bold().String())
|
2020-12-21 00:04:11 +05:30
|
|
|
}
|
|
|
|
|
|
2021-11-22 17:53:25 +05:30
|
|
|
if w.matcherStatus {
|
|
|
|
|
builder.WriteString("] [")
|
|
|
|
|
if !output.MatcherStatus {
|
|
|
|
|
builder.WriteString(w.aurora.Red("failed").String())
|
|
|
|
|
} else {
|
|
|
|
|
builder.WriteString(w.aurora.Green("matched").String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteString("] [")
|
2020-12-25 12:55:46 +05:30
|
|
|
builder.WriteString(w.aurora.BrightBlue(output.Type).String())
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteString("] ")
|
|
|
|
|
|
|
|
|
|
builder.WriteString("[")
|
2021-07-13 11:12:03 +03:00
|
|
|
builder.WriteString(w.severityColors(output.Info.SeverityHolder.Severity))
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteString("] ")
|
|
|
|
|
}
|
2021-11-22 17:53:25 +05:30
|
|
|
if output.Matched != "" {
|
|
|
|
|
builder.WriteString(output.Matched)
|
|
|
|
|
} else {
|
|
|
|
|
builder.WriteString(output.Host)
|
|
|
|
|
}
|
2020-12-21 00:04:11 +05:30
|
|
|
|
|
|
|
|
// If any extractors, write the results
|
2020-12-25 12:55:46 +05:30
|
|
|
if len(output.ExtractedResults) > 0 {
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteString(" [")
|
|
|
|
|
|
2020-12-25 12:55:46 +05:30
|
|
|
for i, item := range output.ExtractedResults {
|
2024-01-12 23:10:00 +05:30
|
|
|
// trim trailing space
|
2024-03-29 13:31:30 +05:30
|
|
|
// quote non-ascii and non printable characters and then
|
|
|
|
|
// unquote quotes (`"`) for readability
|
2024-01-12 23:10:00 +05:30
|
|
|
item = strings.TrimSpace(item)
|
2024-03-29 13:31:30 +05:30
|
|
|
item = strconv.QuoteToASCII(item)
|
|
|
|
|
item = strings.ReplaceAll(item, `\"`, `"`)
|
|
|
|
|
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteString(w.aurora.BrightCyan(item).String())
|
|
|
|
|
|
2020-12-25 12:55:46 +05:30
|
|
|
if i != len(output.ExtractedResults)-1 {
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteRune(',')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
builder.WriteString("]")
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-23 23:32:25 +01:00
|
|
|
if len(output.Lines) > 0 {
|
2022-02-10 15:59:05 +05:30
|
|
|
builder.WriteString(" [LN: ")
|
|
|
|
|
|
2022-02-23 23:32:25 +01:00
|
|
|
for i, line := range output.Lines {
|
2022-02-10 15:59:05 +05:30
|
|
|
builder.WriteString(strconv.Itoa(line))
|
|
|
|
|
|
2022-02-23 23:32:25 +01:00
|
|
|
if i != len(output.Lines)-1 {
|
2022-02-10 15:59:05 +05:30
|
|
|
builder.WriteString(",")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
builder.WriteString("]")
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 00:04:11 +05:30
|
|
|
// Write meta if any
|
2020-12-25 12:55:46 +05:30
|
|
|
if len(output.Metadata) > 0 {
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteString(" [")
|
|
|
|
|
|
2021-07-06 21:15:40 +05:30
|
|
|
first := true
|
2023-09-16 16:02:17 +05:30
|
|
|
// sort to get predictable output
|
|
|
|
|
for _, name := range mapsutil.GetSortedKeys(output.Metadata) {
|
|
|
|
|
value := output.Metadata[name]
|
2020-12-25 12:55:46 +05:30
|
|
|
if !first {
|
2020-12-21 00:04:11 +05:30
|
|
|
builder.WriteRune(',')
|
|
|
|
|
}
|
|
|
|
|
first = false
|
|
|
|
|
|
|
|
|
|
builder.WriteString(w.aurora.BrightYellow(name).String())
|
|
|
|
|
builder.WriteRune('=')
|
2023-01-05 21:02:36 +05:30
|
|
|
builder.WriteString(w.aurora.BrightYellow(strconv.QuoteToASCII(types.ToString(value))).String())
|
2020-12-21 00:04:11 +05:30
|
|
|
}
|
|
|
|
|
builder.WriteString("]")
|
|
|
|
|
}
|
2024-05-03 18:46:28 +05:30
|
|
|
|
|
|
|
|
// If it is a fuzzing output, enrich with additional
|
|
|
|
|
// metadata for the match.
|
|
|
|
|
if output.IsFuzzingResult {
|
|
|
|
|
if output.FuzzingParameter != "" {
|
|
|
|
|
builder.WriteString(" [")
|
|
|
|
|
builder.WriteString(output.FuzzingPosition)
|
|
|
|
|
builder.WriteRune(':')
|
|
|
|
|
builder.WriteString(w.aurora.BrightMagenta(output.FuzzingParameter).String())
|
|
|
|
|
builder.WriteString("]")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.WriteString(" [")
|
|
|
|
|
builder.WriteString(output.FuzzingMethod)
|
|
|
|
|
builder.WriteString("]")
|
|
|
|
|
}
|
2021-02-26 13:13:11 +05:30
|
|
|
return builder.Bytes()
|
2020-12-21 00:04:11 +05:30
|
|
|
}
|