diff --git a/v2/cmd/nuclei/main.go b/v2/cmd/nuclei/main.go index 9e961f07..67543443 100644 --- a/v2/cmd/nuclei/main.go +++ b/v2/cmd/nuclei/main.go @@ -52,7 +52,7 @@ based on templates offering massive extensibility and ease of use.`) set.BoolVarP(&options.NoColor, "no-color", "nc", false, "Disable colors in output") set.IntVar(&options.Timeout, "timeout", 5, "Time to wait in seconds before timeout") set.IntVar(&options.Retries, "retries", 1, "Number of times to retry a failed request") - set.BoolVarP(&options.RandomAgent, "random-agent", "ra", false, "Use randomly selected HTTP User-Agent header value") + set.BoolVarP(&options.RandomAgent, "random-agent", "ra", true, "Use randomly selected HTTP User-Agent header value") set.StringSliceVarP(&options.CustomHeaders, "header", "H", []string{}, "Custom Header.") set.BoolVar(&options.Debug, "debug", false, "Debugging request and responses") set.BoolVar(&options.DebugRequests, "debug-req", false, "Debugging request") diff --git a/v2/internal/runner/config.go b/v2/internal/runner/config.go index c7634388..c68b7d59 100644 --- a/v2/internal/runner/config.go +++ b/v2/internal/runner/config.go @@ -114,17 +114,12 @@ func (r *Runner) getIgnoreFilePath() string { _ = os.MkdirAll(configDir, os.ModePerm) defIgnoreFilePath = path.Join(configDir, nucleiIgnoreFile) + return defIgnoreFilePath } - cwd, err := os.Getwd() if err != nil { return defIgnoreFilePath } cwdIgnoreFilePath := path.Join(cwd, nucleiIgnoreFile) - - cwdIfpInfo, err := os.Stat(cwdIgnoreFilePath) - if os.IsNotExist(err) || cwdIfpInfo.IsDir() { - return defIgnoreFilePath - } return cwdIgnoreFilePath } diff --git a/v2/internal/runner/runner.go b/v2/internal/runner/runner.go index c8238664..45d36be6 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -67,6 +67,7 @@ func New(options *types.Options) (*Runner, error) { runner.readNucleiIgnoreFile() } runner.catalog = catalog.New(runner.options.TemplatesDirectory) + runner.catalog.AppendIgnore(runner.templatesConfig.IgnorePaths) var reportingOptions *reporting.Options if options.ReportingConfig != "" { diff --git a/v2/internal/runner/update.go b/v2/internal/runner/update.go index 0da92434..4c7c3818 100644 --- a/v2/internal/runner/update.go +++ b/v2/internal/runner/update.go @@ -44,7 +44,7 @@ func (r *Runner) updateTemplates() error { configDir := path.Join(home, "/.config", "/nuclei") _ = os.MkdirAll(configDir, os.ModePerm) - templatesConfigFile := path.Join(home, nucleiConfigFilename) + templatesConfigFile := path.Join(configDir, nucleiConfigFilename) if _, statErr := os.Stat(templatesConfigFile); !os.IsNotExist(statErr) { config, readErr := readConfiguration() if err != nil { @@ -65,6 +65,7 @@ func (r *Runner) updateTemplates() error { } r.templatesConfig = currentConfig } + // Check if last checked for nuclei-ignore is more than 1 hours. // and if true, run the check. if r.templatesConfig == nil || time.Since(r.templatesConfig.LastCheckedIgnore) > 1*time.Hour || r.options.UpdateTemplates { diff --git a/v2/pkg/catalog/catalogue.go b/v2/pkg/catalog/catalogue.go index cab2857f..c085e5c2 100644 --- a/v2/pkg/catalog/catalogue.go +++ b/v2/pkg/catalog/catalogue.go @@ -9,6 +9,10 @@ type Catalog struct { // New creates a new Catalog structure using provided input items func New(directory string) *Catalog { catalog := &Catalog{templatesDirectory: directory} - catalog.readNucleiIgnoreFile() return catalog } + +// AppendIgnore appends to the catalog store ignore list. +func (c *Catalog) AppendIgnore(list []string) { + c.ignoreFiles = append(c.ignoreFiles, list...) +} diff --git a/v2/pkg/catalog/ignore.go b/v2/pkg/catalog/ignore.go index b727ecd8..77e94525 100644 --- a/v2/pkg/catalog/ignore.go +++ b/v2/pkg/catalog/ignore.go @@ -1,37 +1,11 @@ package catalog import ( - "bufio" - "os" - "path" "strings" "github.com/projectdiscovery/gologger" ) -const nucleiIgnoreFile = ".nuclei-ignore" - -// readNucleiIgnoreFile reads the nuclei ignore file marking it in map -func (c *Catalog) readNucleiIgnoreFile() { - file, err := os.Open(path.Join(c.templatesDirectory, nucleiIgnoreFile)) - if err != nil { - return - } - defer file.Close() - - scanner := bufio.NewScanner(file) - for scanner.Scan() { - text := scanner.Text() - if text == "" { - continue - } - if strings.HasPrefix(text, "#") { - continue - } - c.ignoreFiles = append(c.ignoreFiles, text) - } -} - // checkIfInNucleiIgnore checks if a path falls under nuclei-ignore rules. func (c *Catalog) checkIfInNucleiIgnore(item string) bool { if c.templatesDirectory == "" {