mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-23 17:15:25 +00:00
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package runner
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/karrick/godirwalk"
|
|
|
|
"github.com/projectdiscovery/gologger"
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/parsers"
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
|
)
|
|
|
|
func (r *Runner) logAvailableTemplate(tplPath string) {
|
|
t, err := parsers.ParseTemplate(tplPath)
|
|
if err != nil {
|
|
gologger.Error().Msgf("Could not parse file '%s': %s\n", tplPath, err)
|
|
} else {
|
|
gologger.Print().Msgf("%s\n", templates.TemplateLogMessage(t.ID,
|
|
types.ToString(t.Info.Name),
|
|
t.Info.Authors.ToSlice(),
|
|
t.Info.SeverityHolder.Severity))
|
|
}
|
|
}
|
|
|
|
// listAvailableTemplates prints available templates to stdout
|
|
func (r *Runner) listAvailableTemplates() {
|
|
if r.templatesConfig == nil {
|
|
return
|
|
}
|
|
|
|
if _, err := os.Stat(r.templatesConfig.TemplatesDirectory); os.IsNotExist(err) {
|
|
gologger.Error().Msgf("%s does not exists", r.templatesConfig.TemplatesDirectory)
|
|
return
|
|
}
|
|
|
|
gologger.Print().Msgf(
|
|
"\nListing available v.%s nuclei templates for %s",
|
|
r.templatesConfig.TemplateVersion,
|
|
r.templatesConfig.TemplatesDirectory,
|
|
)
|
|
err := directoryWalker(
|
|
r.templatesConfig.TemplatesDirectory,
|
|
func(path string, d *godirwalk.Dirent) error {
|
|
if d.IsDir() && path != r.templatesConfig.TemplatesDirectory {
|
|
gologger.Print().Msgf("\n%s:\n\n", r.colorizer.Bold(r.colorizer.BgBrightBlue(d.Name())).String())
|
|
} else if strings.HasSuffix(path, ".yaml") {
|
|
r.logAvailableTemplate(path)
|
|
}
|
|
return nil
|
|
},
|
|
)
|
|
// directory couldn't be walked
|
|
if err != nil {
|
|
gologger.Error().Msgf("Could not find templates in directory '%s': %s\n", r.templatesConfig.TemplatesDirectory, err)
|
|
}
|
|
}
|
|
|
|
func directoryWalker(fsPath string, callback func(fsPath string, d *godirwalk.Dirent) error) error {
|
|
return godirwalk.Walk(fsPath, &godirwalk.Options{
|
|
Callback: callback,
|
|
ErrorCallback: func(fsPath string, err error) godirwalk.ErrorAction {
|
|
return godirwalk.SkipNode
|
|
},
|
|
Unsorted: true,
|
|
})
|
|
}
|