Added nucleiignore feature

dev
Ice3man543 2020-08-24 00:16:18 +05:30
parent 3eb37df130
commit 320f312be0
2 changed files with 55 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package runner
import (
"archive/zip"
"bufio"
"bytes"
"context"
"errors"
@ -27,6 +28,9 @@ type nucleiConfig struct {
TemplatesDirectory string `json:"templates-directory,omitempty"`
CurrentVersion string `json:"current-version,omitempty"`
LastChecked time.Time `json:"last-checked,omitempty"`
// ignorePaths ignores all the paths listed unless specified manually
ignorePaths []string `json:"ignore-paths,omitempty"`
}
// nucleiConfigFilename is the filename of nuclei configuration file.
@ -76,6 +80,44 @@ func (r *Runner) writeConfiguration(config *nucleiConfig) error {
return nil
}
const nucleiIgnoreFile = ".nuclei-ignore"
// readNucleiIgnoreFile reads the nuclei ignore file marking it in map
func (r *Runner) readNucleiIgnoreFile() {
file, err := os.Open(path.Join(r.templatesConfig.TemplatesDirectory, nucleiIgnoreFile))
if err != nil {
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
text := scanner.Text()
if text == "" {
continue
}
r.templatesConfig.ignorePaths = append(r.templatesConfig.ignorePaths, text)
}
}
// checkIfInNucleiIgnore checks if a path falls under nuclei-ignore rules.
func (r *Runner) checkIfInNucleiIgnore(item string) bool {
for _, paths := range r.templatesConfig.ignorePaths {
// If we have a path to ignore, check if it's in the item.
if paths[len(paths)] == '/' {
if strings.Contains(item, paths) {
return true
}
continue
}
// Check for file based extension in ignores
if strings.HasSuffix(item, paths) {
return true
}
}
return false
}
// updateTemplates checks if the default list of nuclei-templates
// exist in the users home directory, if not the latest revision
// is downloaded from github.

View File

@ -5,7 +5,6 @@ import (
"context"
"errors"
"fmt"
"github.com/logrusorgru/aurora"
"io"
"io/ioutil"
"net/http/cookiejar"
@ -15,6 +14,8 @@ import (
"strings"
"sync"
"github.com/logrusorgru/aurora"
tengo "github.com/d5/tengo/v2"
"github.com/d5/tengo/v2/stdlib"
"github.com/karrick/godirwalk"
@ -63,6 +64,10 @@ func New(options *Options) (*Runner, error) {
if (len(options.Templates) == 0 || (options.Targets == "" && !options.Stdin && options.Target == "")) && options.UpdateTemplates {
os.Exit(0)
}
// Read nucleiignore file if given a templateconfig
if runner.templatesConfig != nil {
runner.readNucleiIgnoreFile()
}
// output coloring
useColor := !options.NoColor
@ -278,10 +283,6 @@ func (r *Runner) getTemplatesFor(definitions []string) []string {
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", absPath)
@ -290,7 +291,12 @@ func (r *Runner) getTemplatesFor(definitions []string) []string {
gologger.Labelf("Identified %d templates\n", len(matches))
}
allTemplates = append(allTemplates, matches...)
for _, match := range matches {
if !r.checkIfInNucleiIgnore(match) {
processed[match] = true
allTemplates = append(allTemplates, match)
}
}
} else {
// determine file/directory
isFile, err := isFilePath(absPath)
@ -316,7 +322,7 @@ func (r *Runner) getTemplatesFor(definitions []string) []string {
err = godirwalk.Walk(absPath, &godirwalk.Options{
Callback: func(path string, d *godirwalk.Dirent) error {
if !d.IsDir() && strings.HasSuffix(path, ".yaml") {
if isNewPath(path, processed) {
if !r.checkIfInNucleiIgnore(path) && isNewPath(path, processed) {
matches = append(matches, path)
processed[path] = true
}