2020-08-29 15:26:11 +02:00
|
|
|
package runner
|
|
|
|
|
|
|
|
|
|
import (
|
2022-05-08 08:52:21 +02:00
|
|
|
"io/fs"
|
2020-08-29 15:26:11 +02:00
|
|
|
"os"
|
2022-05-08 08:52:21 +02:00
|
|
|
"path/filepath"
|
2020-08-29 15:26:11 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/gologger"
|
2021-08-19 02:10:36 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/parsers"
|
2022-03-14 12:32:05 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
|
2021-02-04 18:29:28 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
2020-08-29 15:26:11 +02:00
|
|
|
)
|
|
|
|
|
|
2020-08-29 23:02:45 +02:00
|
|
|
func (r *Runner) logAvailableTemplate(tplPath string) {
|
2021-08-19 02:10:36 +05:30
|
|
|
t, err := parsers.ParseTemplate(tplPath)
|
2020-12-29 15:38:14 +05:30
|
|
|
if err != nil {
|
|
|
|
|
gologger.Error().Msgf("Could not parse file '%s': %s\n", tplPath, err)
|
2021-01-14 13:21:21 +05:30
|
|
|
} else {
|
2022-03-14 12:32:05 +05:30
|
|
|
gologger.Print().Msgf("%s\n", templates.TemplateLogMessage(t.ID,
|
2021-07-12 17:20:01 +03:00
|
|
|
types.ToString(t.Info.Name),
|
2021-09-01 17:36:07 +03:00
|
|
|
t.Info.Authors.ToSlice(),
|
2021-07-13 11:12:03 +03:00
|
|
|
t.Info.SeverityHolder.Severity))
|
2020-08-29 23:02:45 +02:00
|
|
|
}
|
2020-08-29 15:26:11 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-01 17:34:51 +03:00
|
|
|
// listAvailableTemplates prints available templates to stdout
|
2020-08-29 23:02:45 +02:00
|
|
|
func (r *Runner) listAvailableTemplates() {
|
|
|
|
|
if r.templatesConfig == nil {
|
|
|
|
|
return
|
2020-08-29 15:26:11 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-30 13:25:34 +02:00
|
|
|
if _, err := os.Stat(r.templatesConfig.TemplatesDirectory); os.IsNotExist(err) {
|
2020-12-29 15:38:14 +05:30
|
|
|
gologger.Error().Msgf("%s does not exists", r.templatesConfig.TemplatesDirectory)
|
2020-08-30 13:25:34 +02:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 15:38:14 +05:30
|
|
|
gologger.Print().Msgf(
|
2020-08-30 13:25:34 +02:00
|
|
|
"\nListing available v.%s nuclei templates for %s",
|
2021-09-15 04:01:40 +05:30
|
|
|
r.templatesConfig.TemplateVersion,
|
2020-08-30 13:25:34 +02:00
|
|
|
r.templatesConfig.TemplatesDirectory,
|
|
|
|
|
)
|
2022-05-08 08:52:21 +02:00
|
|
|
err := filepath.WalkDir(
|
2020-08-29 23:02:45 +02:00
|
|
|
r.templatesConfig.TemplatesDirectory,
|
2022-05-08 08:52:21 +02:00
|
|
|
func(path string, d fs.DirEntry, err error) error {
|
|
|
|
|
// continue on errors
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2020-08-29 23:02:45 +02:00
|
|
|
if d.IsDir() && path != r.templatesConfig.TemplatesDirectory {
|
2020-12-29 15:38:14 +05:30
|
|
|
gologger.Print().Msgf("\n%s:\n\n", r.colorizer.Bold(r.colorizer.BgBrightBlue(d.Name())).String())
|
2020-08-29 23:02:45 +02:00
|
|
|
} else if strings.HasSuffix(path, ".yaml") {
|
|
|
|
|
r.logAvailableTemplate(path)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
// directory couldn't be walked
|
|
|
|
|
if err != nil {
|
2020-12-29 15:38:14 +05:30
|
|
|
gologger.Error().Msgf("Could not find templates in directory '%s': %s\n", r.templatesConfig.TemplatesDirectory, err)
|
2020-08-29 15:26:11 +02:00
|
|
|
}
|
|
|
|
|
}
|