mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-23 04:55:24 +00:00
tl flag improvements (#2596)
* tl flag improvements * tl flag enhancement with additional filters * added ExcluedTags filter * tl flas to list template paths * using stdout * misc update Co-authored-by: sandeep <sandeep@projectdiscovery.io>
This commit is contained in:
parent
99c14f4c9c
commit
512eab7b21
@ -144,10 +144,6 @@ func New(options *types.Options) (*Runner, error) {
|
|||||||
templates.Colorizer = runner.colorizer
|
templates.Colorizer = runner.colorizer
|
||||||
templates.SeverityColorizer = colorizer.New(runner.colorizer)
|
templates.SeverityColorizer = colorizer.New(runner.colorizer)
|
||||||
|
|
||||||
if options.TemplateList {
|
|
||||||
runner.listAvailableTemplates()
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
if options.EnablePprof {
|
if options.EnablePprof {
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: pprofServerAddress,
|
Addr: pprofServerAddress,
|
||||||
@ -399,6 +395,11 @@ func (r *Runner) RunEnumeration() error {
|
|||||||
}
|
}
|
||||||
store.Load()
|
store.Load()
|
||||||
|
|
||||||
|
// list all templates
|
||||||
|
if r.options.TemplateList {
|
||||||
|
r.listAvailableStoreTemplates(store)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
r.displayExecutionInfo(store)
|
r.displayExecutionInfo(store)
|
||||||
|
|
||||||
var results *atomic.Bool
|
var results *atomic.Bool
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
package runner
|
package runner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/fs"
|
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/loader"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -12,6 +11,7 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// log available templates for verbose (-vv)
|
||||||
func (r *Runner) logAvailableTemplate(tplPath string) {
|
func (r *Runner) logAvailableTemplate(tplPath string) {
|
||||||
t, err := parsers.ParseTemplate(tplPath, r.catalog)
|
t, err := parsers.ParseTemplate(tplPath, r.catalog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -24,39 +24,29 @@ func (r *Runner) logAvailableTemplate(tplPath string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// listAvailableTemplates prints available templates to stdout
|
func (r *Runner) listAvailableStoreTemplates(store *loader.Store) {
|
||||||
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(
|
gologger.Print().Msgf(
|
||||||
"\nListing available v.%s nuclei templates for %s",
|
"\nListing available v.%s nuclei templates for %s",
|
||||||
r.templatesConfig.TemplateVersion,
|
r.templatesConfig.TemplateVersion,
|
||||||
r.templatesConfig.TemplatesDirectory,
|
r.templatesConfig.TemplatesDirectory,
|
||||||
)
|
)
|
||||||
err := filepath.WalkDir(
|
extraFlags := r.options.Templates != nil || r.options.Authors != nil ||
|
||||||
r.templatesConfig.TemplatesDirectory,
|
r.options.Tags != nil || len(r.options.ExcludeTags) > 3 ||
|
||||||
func(path string, d fs.DirEntry, err error) error {
|
r.options.IncludeTags != nil || r.options.IncludeIds != nil ||
|
||||||
// continue on errors
|
r.options.ExcludeIds != nil || r.options.IncludeTemplates != nil ||
|
||||||
if err != nil {
|
r.options.ExcludedTemplates != nil || r.options.ExcludeMatchers != nil ||
|
||||||
return nil
|
r.options.Severities != nil || r.options.ExcludeSeverities != nil ||
|
||||||
|
r.options.Protocols != nil || r.options.ExcludeProtocols != nil ||
|
||||||
|
r.options.IncludeConditions != nil || r.options.TemplateList
|
||||||
|
for _, tl := range store.Templates() {
|
||||||
|
if extraFlags {
|
||||||
|
path := strings.TrimPrefix(tl.Path, r.templatesConfig.TemplatesDirectory+string(filepath.Separator))
|
||||||
|
gologger.Silent().Msgf("%s\n", path)
|
||||||
|
} else {
|
||||||
|
gologger.Print().Msgf("%s\n", templates.TemplateLogMessage(tl.ID,
|
||||||
|
types.ToString(tl.Info.Name),
|
||||||
|
tl.Info.Authors.ToSlice(),
|
||||||
|
tl.Info.SeverityHolder.Severity))
|
||||||
}
|
}
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user