2020-12-29 12:32:45 +00:00
|
|
|
package catalogue
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strings"
|
2021-01-14 07:51:21 +00:00
|
|
|
|
|
|
|
"github.com/projectdiscovery/gologger"
|
2020-12-29 12:32:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const nucleiIgnoreFile = ".nuclei-ignore"
|
|
|
|
|
|
|
|
// readNucleiIgnoreFile reads the nuclei ignore file marking it in map
|
|
|
|
func (c *Catalogue) 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 *Catalogue) checkIfInNucleiIgnore(item string) bool {
|
|
|
|
if c.templatesDirectory == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, paths := range c.ignoreFiles {
|
2021-01-15 15:19:44 +00:00
|
|
|
dir := path.Dir(item)
|
|
|
|
|
|
|
|
if strings.EqualFold(dir, paths) {
|
|
|
|
gologger.Error().Msgf("Excluding %s due to nuclei-ignore filter", item)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(paths, ".yaml") && strings.HasSuffix(item, paths) {
|
2021-01-14 07:51:21 +00:00
|
|
|
gologger.Error().Msgf("Excluding %s due to nuclei-ignore filter", item)
|
2020-12-29 12:32:45 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignoreFilesWithExcludes ignores results with exclude paths
|
|
|
|
func (c *Catalogue) ignoreFilesWithExcludes(results, excluded []string) []string {
|
2021-01-14 06:52:19 +00:00
|
|
|
var templates []string
|
2020-12-29 12:32:45 +00:00
|
|
|
|
2021-01-14 06:52:19 +00:00
|
|
|
for _, result := range results {
|
|
|
|
matched := false
|
|
|
|
for _, paths := range excluded {
|
2021-01-15 15:19:44 +00:00
|
|
|
dir := path.Dir(result)
|
|
|
|
|
|
|
|
if strings.EqualFold(dir, paths) {
|
|
|
|
matched = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(paths, ".yaml") && strings.HasSuffix(result, paths) {
|
2021-01-14 06:52:19 +00:00
|
|
|
matched = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !matched {
|
|
|
|
templates = append(templates, result)
|
2021-01-14 07:51:21 +00:00
|
|
|
} else {
|
|
|
|
gologger.Error().Msgf("Excluding %s due to excludes filter", result)
|
2020-12-29 12:32:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return templates
|
|
|
|
}
|