Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/templates/log.go
2070 views
1
package templates
2
3
import (
4
"fmt"
5
"strings"
6
7
"github.com/logrusorgru/aurora"
8
"github.com/projectdiscovery/gologger"
9
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
10
"github.com/projectdiscovery/nuclei/v3/pkg/model/types/severity"
11
mapsutil "github.com/projectdiscovery/utils/maps"
12
)
13
14
var (
15
Colorizer aurora.Aurora
16
SeverityColorizer func(severity.Severity) string
17
deprecatedProtocolNameTemplates = mapsutil.SyncLockMap[string, bool]{Map: mapsutil.Map[string, bool]{}} //templates that still use deprecated protocol names
18
)
19
20
// TemplateLogMessage returns a beautified log string for a template
21
func TemplateLogMessage(id, name string, authors []string, templateSeverity severity.Severity) string {
22
if Colorizer == nil || SeverityColorizer == nil {
23
return ""
24
}
25
// Display the message for the template
26
return fmt.Sprintf("[%s] %s (%s) [%s]",
27
Colorizer.BrightBlue(id).String(),
28
Colorizer.Bold(name).String(),
29
Colorizer.BrightYellow(appendAtSignToAuthors(authors)).String(),
30
SeverityColorizer(templateSeverity))
31
}
32
33
// appendAtSignToAuthors appends @ before each author and returns the final string
34
func appendAtSignToAuthors(authors []string) string {
35
if len(authors) == 0 {
36
return "@none"
37
}
38
39
values := make([]string, 0, len(authors))
40
for _, k := range authors {
41
if !strings.HasPrefix(k, "@") {
42
values = append(values, fmt.Sprintf("@%s", k))
43
} else {
44
values = append(values, k)
45
}
46
}
47
return strings.Join(values, ",")
48
}
49
50
// PrintDeprecatedProtocolNameMsgIfApplicable prints a message if deprecated protocol names are used
51
// Unless mode is silent we print a message for deprecated protocol name
52
func PrintDeprecatedProtocolNameMsgIfApplicable(isSilent bool, verbose bool) {
53
count := 0
54
_ = deprecatedProtocolNameTemplates.Iterate(func(k string, v bool) error {
55
count++
56
return nil
57
})
58
if count > 0 && !isSilent {
59
gologger.Print().Msgf("[%v] Found %v templates loaded with deprecated protocol syntax, update before v3 for continued support.\n", aurora.Yellow("WRN").String(), count)
60
}
61
if config.DefaultConfig.LogAllEvents {
62
_ = deprecatedProtocolNameTemplates.Iterate(func(k string, v bool) error {
63
gologger.Print().Msgf(" - %s\n", k)
64
return nil
65
})
66
}
67
deprecatedProtocolNameTemplates.Lock()
68
deprecatedProtocolNameTemplates.Map = make(map[string]bool)
69
deprecatedProtocolNameTemplates.Unlock()
70
}
71
72