mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 13:45:28 +00:00
Misc changes to update and ignore handling
This commit is contained in:
parent
6667f285d3
commit
4d52fb45e4
@ -107,7 +107,7 @@ require (
|
|||||||
github.com/projectdiscovery/iputil v0.0.0-20210429152401-c18a5408ca46 // indirect
|
github.com/projectdiscovery/iputil v0.0.0-20210429152401-c18a5408ca46 // indirect
|
||||||
github.com/projectdiscovery/mapcidr v0.0.6 // indirect
|
github.com/projectdiscovery/mapcidr v0.0.6 // indirect
|
||||||
github.com/projectdiscovery/networkpolicy v0.0.1 // indirect
|
github.com/projectdiscovery/networkpolicy v0.0.1 // indirect
|
||||||
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210913094946-d1ec15db5faf // indirect
|
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210914222811-0a072d262f77 // indirect
|
||||||
github.com/rivo/uniseg v0.2.0 // indirect
|
github.com/rivo/uniseg v0.2.0 // indirect
|
||||||
github.com/tklauser/go-sysconf v0.3.7 // indirect
|
github.com/tklauser/go-sysconf v0.3.7 // indirect
|
||||||
github.com/tklauser/numcpus v0.2.3 // indirect
|
github.com/tklauser/numcpus v0.2.3 // indirect
|
||||||
|
|||||||
@ -363,6 +363,8 @@ github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210913094006-ee345cd
|
|||||||
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210913094006-ee345cd25b9b/go.mod h1:pxWVDgq88t9dWv4+J2AIaWgY+EqOE1AyfHS0Tn23w4M=
|
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210913094006-ee345cd25b9b/go.mod h1:pxWVDgq88t9dWv4+J2AIaWgY+EqOE1AyfHS0Tn23w4M=
|
||||||
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210913094946-d1ec15db5faf h1:cFUSV7HERosPKdHuPiV348eVxObVMBqNt0ydYVplsI0=
|
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210913094946-d1ec15db5faf h1:cFUSV7HERosPKdHuPiV348eVxObVMBqNt0ydYVplsI0=
|
||||||
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210913094946-d1ec15db5faf/go.mod h1:pxWVDgq88t9dWv4+J2AIaWgY+EqOE1AyfHS0Tn23w4M=
|
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210913094946-d1ec15db5faf/go.mod h1:pxWVDgq88t9dWv4+J2AIaWgY+EqOE1AyfHS0Tn23w4M=
|
||||||
|
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210914222811-0a072d262f77 h1:SNtAiRRrJtDJJDroaa/bFXt/Tix2LA6+rHRib0ORlJQ=
|
||||||
|
github.com/projectdiscovery/nuclei-updatecheck-api v0.0.0-20210914222811-0a072d262f77/go.mod h1:pxWVDgq88t9dWv4+J2AIaWgY+EqOE1AyfHS0Tn23w4M=
|
||||||
github.com/projectdiscovery/nuclei/v2 v2.5.1/go.mod h1:sU2qcY0MQFS0CqP1BgkR8ZnUyFhqK0BdnY6bvTKNjXY=
|
github.com/projectdiscovery/nuclei/v2 v2.5.1/go.mod h1:sU2qcY0MQFS0CqP1BgkR8ZnUyFhqK0BdnY6bvTKNjXY=
|
||||||
github.com/projectdiscovery/rawhttp v0.0.7 h1:5m4peVgjbl7gqDcRYMTVEuX+Xs/nh76ohTkkvufucLg=
|
github.com/projectdiscovery/rawhttp v0.0.7 h1:5m4peVgjbl7gqDcRYMTVEuX+Xs/nh76ohTkkvufucLg=
|
||||||
github.com/projectdiscovery/rawhttp v0.0.7/go.mod h1:PQERZAhAv7yxI/hR6hdDPgK1WTU56l204BweXrBec+0=
|
github.com/projectdiscovery/rawhttp v0.0.7/go.mod h1:PQERZAhAv7yxI/hR6hdDPgK1WTU56l204BweXrBec+0=
|
||||||
|
|||||||
@ -36,7 +36,7 @@ func ParseOptions(options *types.Options) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
gologger.Fatal().Msgf("Could not read template configuration: %s\n", err)
|
gologger.Fatal().Msgf("Could not read template configuration: %s\n", err)
|
||||||
}
|
}
|
||||||
gologger.Info().Msgf("Current nuclei-templates version: %s (%s)\n", configuration.CurrentVersion, configuration.TemplatesDirectory)
|
gologger.Info().Msgf("Current nuclei-templates version: %s (%s)\n", configuration.TemplateVersion, configuration.TemplatesDirectory)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -392,7 +392,7 @@ func (r *Runner) RunEnumeration() error {
|
|||||||
if r.templatesConfig != nil && r.templatesConfig.NucleiTemplatesLatestVersion != "" { // TODO extract duplicated logic
|
if r.templatesConfig != nil && r.templatesConfig.NucleiTemplatesLatestVersion != "" { // TODO extract duplicated logic
|
||||||
builder.WriteString(" (")
|
builder.WriteString(" (")
|
||||||
|
|
||||||
if r.templatesConfig.CurrentVersion == r.templatesConfig.NucleiTemplatesLatestVersion {
|
if r.templatesConfig.TemplateVersion == r.templatesConfig.NucleiTemplatesLatestVersion {
|
||||||
builder.WriteString(r.colorizer.Green("latest").String())
|
builder.WriteString(r.colorizer.Green("latest").String())
|
||||||
} else {
|
} else {
|
||||||
builder.WriteString(r.colorizer.Red("outdated").String())
|
builder.WriteString(r.colorizer.Red("outdated").String())
|
||||||
@ -403,7 +403,7 @@ func (r *Runner) RunEnumeration() error {
|
|||||||
builder.Reset()
|
builder.Reset()
|
||||||
|
|
||||||
if r.templatesConfig != nil {
|
if r.templatesConfig != nil {
|
||||||
gologger.Info().Msgf("Using Nuclei Templates %s%s", r.templatesConfig.CurrentVersion, messageStr)
|
gologger.Info().Msgf("Using Nuclei Templates %s%s", r.templatesConfig.TemplateVersion, messageStr)
|
||||||
}
|
}
|
||||||
if r.interactsh != nil {
|
if r.interactsh != nil {
|
||||||
gologger.Info().Msgf("Using Interactsh Server %s", r.options.InteractshURL)
|
gologger.Info().Msgf("Using Interactsh Server %s", r.options.InteractshURL)
|
||||||
|
|||||||
@ -70,7 +70,7 @@ func (r *Runner) listAvailableTemplates() {
|
|||||||
|
|
||||||
gologger.Print().Msgf(
|
gologger.Print().Msgf(
|
||||||
"\nListing available v.%s nuclei templates for %s",
|
"\nListing available v.%s nuclei templates for %s",
|
||||||
r.templatesConfig.CurrentVersion,
|
r.templatesConfig.TemplateVersion,
|
||||||
r.templatesConfig.TemplatesDirectory,
|
r.templatesConfig.TemplatesDirectory,
|
||||||
)
|
)
|
||||||
err := directoryWalker(
|
err := directoryWalker(
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/blang/semver"
|
"github.com/blang/semver"
|
||||||
@ -66,7 +65,7 @@ func (r *Runner) updateTemplates() error {
|
|||||||
TemplatesDirectory: filepath.Join(home, "nuclei-templates"),
|
TemplatesDirectory: filepath.Join(home, "nuclei-templates"),
|
||||||
NucleiVersion: config.Version,
|
NucleiVersion: config.Version,
|
||||||
}
|
}
|
||||||
if writeErr := config.WriteConfiguration(currentConfig, false); writeErr != nil {
|
if writeErr := config.WriteConfiguration(currentConfig); writeErr != nil {
|
||||||
return errors.Wrap(writeErr, "could not write template configuration")
|
return errors.Wrap(writeErr, "could not write template configuration")
|
||||||
}
|
}
|
||||||
r.templatesConfig = currentConfig
|
r.templatesConfig = currentConfig
|
||||||
@ -76,17 +75,7 @@ func (r *Runner) updateTemplates() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
client.InitNucleiVersion(config.Version)
|
client.InitNucleiVersion(config.Version)
|
||||||
r.fetchLatestVersionsFromGithub() // also fetch latest versions
|
r.fetchLatestVersionsFromGithub(configDir) // also fetch latest versions
|
||||||
|
|
||||||
// Check if last checked for nuclei-ignore is more than 1 hours.
|
|
||||||
// and if true, run the check.
|
|
||||||
//
|
|
||||||
// Also at the same time fetch latest version from github to do outdated nuclei
|
|
||||||
// and templates check.
|
|
||||||
checkedIgnore := false
|
|
||||||
if r.templatesConfig == nil || time.Since(r.templatesConfig.LastCheckedIgnore) > 1*time.Hour {
|
|
||||||
checkedIgnore = r.checkNucleiIgnoreFileUpdates(configDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
@ -95,7 +84,7 @@ func (r *Runner) updateTemplates() error {
|
|||||||
noTemplatesFound = true
|
noTemplatesFound = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.templatesConfig.CurrentVersion == "" || (r.options.TemplatesDirectory != "" && r.templatesConfig.TemplatesDirectory != r.options.TemplatesDirectory) || noTemplatesFound {
|
if r.templatesConfig.TemplateVersion == "" || (r.options.TemplatesDirectory != "" && r.templatesConfig.TemplatesDirectory != r.options.TemplatesDirectory) || noTemplatesFound {
|
||||||
gologger.Info().Msgf("nuclei-templates are not installed, installing...\n")
|
gologger.Info().Msgf("nuclei-templates are not installed, installing...\n")
|
||||||
|
|
||||||
// Use custom location if user has given a template directory
|
// Use custom location if user has given a template directory
|
||||||
@ -105,7 +94,7 @@ func (r *Runner) updateTemplates() error {
|
|||||||
if r.options.TemplatesDirectory != "" && r.options.TemplatesDirectory != filepath.Join(home, "nuclei-templates") {
|
if r.options.TemplatesDirectory != "" && r.options.TemplatesDirectory != filepath.Join(home, "nuclei-templates") {
|
||||||
r.templatesConfig.TemplatesDirectory, _ = filepath.Abs(r.options.TemplatesDirectory)
|
r.templatesConfig.TemplatesDirectory, _ = filepath.Abs(r.options.TemplatesDirectory)
|
||||||
}
|
}
|
||||||
r.fetchLatestVersionsFromGithub() // also fetch latest versions
|
r.fetchLatestVersionsFromGithub(configDir) // also fetch latest versions
|
||||||
|
|
||||||
version, err := semver.Parse(r.templatesConfig.NucleiTemplatesLatestVersion)
|
version, err := semver.Parse(r.templatesConfig.NucleiTemplatesLatestVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -123,9 +112,9 @@ func (r *Runner) updateTemplates() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r.templatesConfig.CurrentVersion = version.String()
|
r.templatesConfig.TemplateVersion = version.String()
|
||||||
|
|
||||||
err = config.WriteConfiguration(r.templatesConfig, checkedIgnore)
|
err = config.WriteConfiguration(r.templatesConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -134,7 +123,7 @@ func (r *Runner) updateTemplates() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the configuration currently on disk.
|
// Get the configuration currently on disk.
|
||||||
verText := r.templatesConfig.CurrentVersion
|
verText := r.templatesConfig.TemplateVersion
|
||||||
indices := reVersion.FindStringIndex(verText)
|
indices := reVersion.FindStringIndex(verText)
|
||||||
if indices == nil {
|
if indices == nil {
|
||||||
return fmt.Errorf("invalid release found with tag %s", err)
|
return fmt.Errorf("invalid release found with tag %s", err)
|
||||||
@ -157,7 +146,7 @@ func (r *Runner) updateTemplates() error {
|
|||||||
if r.options.UpdateTemplates {
|
if r.options.UpdateTemplates {
|
||||||
gologger.Info().Msgf("No new updates found for nuclei templates")
|
gologger.Info().Msgf("No new updates found for nuclei templates")
|
||||||
}
|
}
|
||||||
return config.WriteConfiguration(r.templatesConfig, checkedIgnore)
|
return config.WriteConfiguration(r.templatesConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
if version.GT(oldVersion) {
|
if version.GT(oldVersion) {
|
||||||
@ -167,7 +156,7 @@ func (r *Runner) updateTemplates() error {
|
|||||||
if r.options.TemplatesDirectory != "" {
|
if r.options.TemplatesDirectory != "" {
|
||||||
r.templatesConfig.TemplatesDirectory = r.options.TemplatesDirectory
|
r.templatesConfig.TemplatesDirectory = r.options.TemplatesDirectory
|
||||||
}
|
}
|
||||||
r.templatesConfig.CurrentVersion = version.String()
|
r.templatesConfig.TemplateVersion = version.String()
|
||||||
|
|
||||||
gologger.Verbose().Msgf("Downloading nuclei-templates (v%s) to %s\n", version.String(), r.templatesConfig.TemplatesDirectory)
|
gologger.Verbose().Msgf("Downloading nuclei-templates (v%s) to %s\n", version.String(), r.templatesConfig.TemplatesDirectory)
|
||||||
|
|
||||||
@ -179,7 +168,7 @@ func (r *Runner) updateTemplates() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = config.WriteConfiguration(r.templatesConfig, checkedIgnore)
|
err = config.WriteConfiguration(r.templatesConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -215,7 +204,7 @@ func (r *Runner) checkNucleiIgnoreFileUpdates(configDir string) bool {
|
|||||||
_ = ioutil.WriteFile(filepath.Join(configDir, nucleiIgnoreFile), data, 0644)
|
_ = ioutil.WriteFile(filepath.Join(configDir, nucleiIgnoreFile), data, 0644)
|
||||||
}
|
}
|
||||||
if r.templatesConfig != nil {
|
if r.templatesConfig != nil {
|
||||||
if err := config.WriteConfiguration(r.templatesConfig, true); err != nil {
|
if err := config.WriteConfiguration(r.templatesConfig); err != nil {
|
||||||
gologger.Warning().Msgf("Could not get ignore-file from server: %s", err)
|
gologger.Warning().Msgf("Could not get ignore-file from server: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -473,7 +462,7 @@ func (r *Runner) printUpdateChangelog(results *templateUpdateResults, version st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetchLatestVersionsFromGithub fetches latest versions of nuclei repos from github
|
// fetchLatestVersionsFromGithub fetches latest versions of nuclei repos from github
|
||||||
func (r *Runner) fetchLatestVersionsFromGithub() {
|
func (r *Runner) fetchLatestVersionsFromGithub(configDir string) {
|
||||||
versions, err := client.GetLatestNucleiTemplatesVersion()
|
versions, err := client.GetLatestNucleiTemplatesVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gologger.Warning().Msgf("Could not fetch latest releases: %s", err)
|
gologger.Warning().Msgf("Could not fetch latest releases: %s", err)
|
||||||
@ -482,6 +471,12 @@ func (r *Runner) fetchLatestVersionsFromGithub() {
|
|||||||
if r.templatesConfig != nil {
|
if r.templatesConfig != nil {
|
||||||
r.templatesConfig.NucleiLatestVersion = versions.Nuclei
|
r.templatesConfig.NucleiLatestVersion = versions.Nuclei
|
||||||
r.templatesConfig.NucleiTemplatesLatestVersion = versions.Templates
|
r.templatesConfig.NucleiTemplatesLatestVersion = versions.Templates
|
||||||
|
|
||||||
|
// If the fetch has resulted in new version of ignore file, update.
|
||||||
|
if r.templatesConfig.NucleiIgnoreHash == "" || r.templatesConfig.NucleiIgnoreHash != versions.IgnoreHash {
|
||||||
|
r.templatesConfig.NucleiIgnoreHash = versions.IgnoreHash
|
||||||
|
r.checkNucleiIgnoreFileUpdates(configDir)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -13,10 +12,10 @@ import (
|
|||||||
|
|
||||||
// Config contains the internal nuclei engine configuration
|
// Config contains the internal nuclei engine configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
TemplatesDirectory string `json:"templates-directory,omitempty"`
|
TemplatesDirectory string `json:"templates-directory,omitempty"`
|
||||||
CurrentVersion string `json:"current-version,omitempty"`
|
TemplateVersion string `json:"template-version,omitempty"`
|
||||||
NucleiVersion string `json:"nuclei-version,omitempty"`
|
NucleiVersion string `json:"nuclei-version,omitempty"`
|
||||||
LastCheckedIgnore time.Time `json:"last-checked-ignore,omitempty"`
|
NucleiIgnoreHash string `json:"nuclei-ignore-hash,omitempty"`
|
||||||
|
|
||||||
NucleiLatestVersion string `json:"nuclei-latest-version"`
|
NucleiLatestVersion string `json:"nuclei-latest-version"`
|
||||||
NucleiTemplatesLatestVersion string `json:"nuclei-templates-latest-version"`
|
NucleiTemplatesLatestVersion string `json:"nuclei-templates-latest-version"`
|
||||||
@ -61,10 +60,7 @@ func ReadConfiguration() (*Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WriteConfiguration writes the updated nuclei configuration to disk
|
// WriteConfiguration writes the updated nuclei configuration to disk
|
||||||
func WriteConfiguration(config *Config, checkedIgnore bool) error {
|
func WriteConfiguration(config *Config) error {
|
||||||
if checkedIgnore {
|
|
||||||
config.LastCheckedIgnore = time.Now()
|
|
||||||
}
|
|
||||||
config.NucleiVersion = Version
|
config.NucleiVersion = Version
|
||||||
|
|
||||||
templatesConfigFile, err := getConfigDetails()
|
templatesConfigFile, err := getConfigDetails()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user