mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-22 02:35:27 +00:00
Support template wildcarding
This commit is contained in:
parent
f22a223ea0
commit
959711edb0
@ -9,6 +9,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http/cookiejar"
|
"net/http/cookiejar"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -126,23 +127,44 @@ func (r *Runner) RunEnumeration() {
|
|||||||
for _, t := range r.options.Templates {
|
for _, t := range r.options.Templates {
|
||||||
// resolve and convert relative to absolute path
|
// resolve and convert relative to absolute path
|
||||||
absPath, err := r.resolvePathIfRelative(t)
|
absPath, err := r.resolvePathIfRelative(t)
|
||||||
if err != nil {
|
if err != nil && !strings.Contains(t, "*") {
|
||||||
gologger.Errorf("Could not find template file '%s': %s\n", t, err)
|
gologger.Errorf("Could not find template file '%s': %s\n", t, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Template input includes a wildcard
|
||||||
|
if strings.Contains(t, "*") {
|
||||||
|
matches := []string{}
|
||||||
|
matches, err = filepath.Glob(t)
|
||||||
|
if err != nil {
|
||||||
|
gologger.Labelf("Wildcard found, but unable to glob '%s': %s\n", t, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, i := range matches {
|
||||||
|
processed[i] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// couldn't find templates in directory
|
||||||
|
if len(matches) == 0 {
|
||||||
|
gologger.Labelf("Error, no templates were found with '%s'.\n", t)
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
gologger.Labelf("Identified %d templates\n", len(matches))
|
||||||
|
}
|
||||||
|
|
||||||
|
allTemplates = append(allTemplates, matches...)
|
||||||
|
} else {
|
||||||
// determine file/directory
|
// determine file/directory
|
||||||
isFile, err := isFilePath(absPath)
|
isFile, err := isFilePath(absPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gologger.Errorf("Could not stat '%s': %s\n", absPath, err)
|
gologger.Errorf("Could not stat '%s': %s\n", absPath, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// test for uniqueness
|
// test for uniqueness
|
||||||
if !isNewPath(absPath, processed) {
|
if !isNewPath(absPath, processed) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark this absolute path as processed
|
// mark this absolute path as processed
|
||||||
// - if it's a file, we'll never process it again
|
// - if it's a file, we'll never process it again
|
||||||
// - if it's a dir, we'll never walk it again
|
// - if it's a dir, we'll never walk it again
|
||||||
@ -185,6 +207,7 @@ func (r *Runner) RunEnumeration() {
|
|||||||
allTemplates = append(allTemplates, matches...)
|
allTemplates = append(allTemplates, matches...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 0 matches means no templates were found in directory
|
// 0 matches means no templates were found in directory
|
||||||
if len(allTemplates) == 0 {
|
if len(allTemplates) == 0 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user