Skip to content

Commit

Permalink
Add support for template exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbua committed Aug 2, 2020
1 parent c6df7fb commit 4a355f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion v2/internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type Options struct {
Debug bool // Debug mode allows debugging request/responses for the engine
Templates multiStringFlag // Signature specifies the template/templates to use
ExcludedTemplates multiStringFlag // Signature specifies the template/templates to exclude
Target string // Target is a single URL/Domain to scan usng a template
Targets string // Targets specifies the targets to scan using templates.
Threads int // Thread controls the number of concurrent requests to make.
Expand Down Expand Up @@ -51,7 +52,8 @@ func ParseOptions() *Options {
options := &Options{}

flag.StringVar(&options.Target, "target", "", "Target is a single target to scan using template")
flag.Var(&options.Templates, "t", "Template input file/files to run on host. Can be used multiple times.")
flag.Var(&options.Templates, "t", "Template input dir/file/files to run on host. Can be used multiple times. Supports globbing.")
flag.Var(&options.ExcludedTemplates, "exclude", "Template input dir/file/files to exclude. Can be used multiple times. Supports globbing.")
flag.StringVar(&options.Targets, "l", "", "List of URLs to run templates on")
flag.StringVar(&options.Output, "o", "", "File to write output to (optional)")
flag.StringVar(&options.ProxyURL, "proxy-url", "", "URL of the proxy server")
Expand Down
22 changes: 20 additions & 2 deletions v2/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,26 @@ func (r *Runner) getTemplatesFor(definitions []string) []string {
// RunEnumeration sets up the input layer for giving input nuclei.
// binary and runs the actual enumeration
func (r *Runner) RunEnumeration() {
// resolves input templates
allTemplates := r.getTemplatesFor(r.options.Templates)
// resolves input templates definitions and any optional exclusion
includedTemplates := r.getTemplatesFor(r.options.Templates)
excludedTemplates := r.getTemplatesFor(r.options.ExcludedTemplates)
// defaults to all templates
allTemplates := includedTemplates
if len(excludedTemplates) > 0 {
excludedMap := make(map[string]struct{}, len(excludedTemplates))
for _, excl := range excludedTemplates {
excludedMap[excl] = struct{}{}
}
// rebuild list with only non-excluded templates
allTemplates = []string{}
for _, incl := range includedTemplates {
if _, found := excludedMap[incl]; !found {
allTemplates = append(allTemplates, incl)
} else {
gologger.Warningf("Excluding '%s'", incl)
}
}
}

// 0 matches means no templates were found in directory
if len(allTemplates) == 0 {
Expand Down

0 comments on commit 4a355f0

Please sign in to comment.