Adding support for ignore file path override if custom config file is used (#1441)

* Adding support for ignore file path override if custom config file is used
dev
Mzack9999 2022-01-10 10:16:48 +01:00 committed by GitHub
parent c26a1ac21c
commit 0635b9e54f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/projectdiscovery/goflags"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/internal/runner"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
@ -203,6 +204,10 @@ on extensive configurability, massive extensibility and ease of use.`)
if err := flagSet.MergeConfigFile(cfgFile); err != nil {
gologger.Fatal().Msgf("Could not read config: %s\n", err)
}
cfgFileFolder := filepath.Dir(cfgFile)
if err := config.OverrideIgnoreFilePath(cfgFileFolder); err != nil {
gologger.Warning().Msgf("Could not read ignore file from custom path: %s\n", err)
}
}
}

View File

@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"github.com/projectdiscovery/fileutil"
"github.com/projectdiscovery/gologger"
)
@ -105,10 +106,38 @@ func ReadIgnoreFile() IgnoreFile {
return ignore
}
var (
// customIgnoreFilePath contains a custom path for the ignore file
customIgnoreFilePath string
// ErrCustomIgnoreFilePathNotExist is raised when the ignore file doesn't exist in the custom path
ErrCustomIgnoreFilePathNotExist = errors.New("Ignore file doesn't exist in custom path")
// ErrCustomFolderNotExist is raised when the custom ignore folder doesn't exist
ErrCustomFolderNotExist = errors.New("The custom ignore path doesn't exist")
)
// OverrideIgnoreFilePath with a custom existing folder
func OverrideIgnoreFilePath(customPath string) error {
// custom path does not exist
if !fileutil.FolderExists(customPath) {
return ErrCustomFolderNotExist
}
// ignore file within the custom path does not exist
if !fileutil.FileExists(filepath.Join(customPath, nucleiIgnoreFile)) {
return ErrCustomIgnoreFilePathNotExist
}
customIgnoreFilePath = customPath
return nil
}
// getIgnoreFilePath returns the ignore file path for the runner
func getIgnoreFilePath() string {
var defIgnoreFilePath string
if customIgnoreFilePath != "" {
defIgnoreFilePath = filepath.Join(customIgnoreFilePath, nucleiIgnoreFile)
return defIgnoreFilePath
}
home, err := os.UserHomeDir()
if err == nil {
configDir := filepath.Join(home, ".config", "nuclei")