Changed/removed some documentation/comments

This commit is contained in:
forgedhallpass 2021-09-01 17:34:51 +03:00
parent f36ed8df64
commit f9eb8ba8ac
7 changed files with 23 additions and 28 deletions

View File

@ -77,12 +77,10 @@ func hasStdin() bool {
// validateOptions validates the configuration options passed // validateOptions validates the configuration options passed
func validateOptions(options *types.Options) error { func validateOptions(options *types.Options) error {
// Both verbose and silent flags were used
if options.Verbose && options.Silent { if options.Verbose && options.Silent {
return errors.New("both verbose and silent mode specified") return errors.New("both verbose and silent mode specified")
} }
// Validate proxy options if provided
if err := validateProxyURL(options.ProxyURL, "invalid http proxy format (It should be http://username:password@host:port)"); err != nil { if err := validateProxyURL(options.ProxyURL, "invalid http proxy format (It should be http://username:password@host:port)"); err != nil {
return err return err
} }
@ -111,9 +109,8 @@ func isValidURL(urlString string) bool {
return err == nil return err == nil
} }
// configureOutput configures the output on the screen // configureOutput configures the output logging levels to be displayed on the screen
func configureOutput(options *types.Options) { func configureOutput(options *types.Options) {
// If the user desires verbose output, show verbose output
if options.Verbose { if options.Verbose {
gologger.DefaultLogger.SetMaxLevel(levels.LevelVerbose) gologger.DefaultLogger.SetMaxLevel(levels.LevelVerbose)
} }

View File

@ -7,7 +7,7 @@ import (
"go.uber.org/atomic" "go.uber.org/atomic"
) )
// processTemplateWithList process a template on the URL list // processTemplateWithList execute a template against the list of user provided targets
func (r *Runner) processTemplateWithList(template *templates.Template) bool { func (r *Runner) processTemplateWithList(template *templates.Template) bool {
results := &atomic.Bool{} results := &atomic.Bool{}
wg := sizedwaitgroup.New(r.options.BulkSize) wg := sizedwaitgroup.New(r.options.BulkSize)

View File

@ -229,7 +229,7 @@ func New(options *types.Options) (*Runner, error) {
return nil, progressErr return nil, progressErr
} }
// create project file if requested or load existing one // create project file if requested or load the existing one
if options.Project { if options.Project {
var projectFileErr error var projectFileErr error
runner.projectFile, projectFileErr = projectfile.New(&projectfile.Options{Path: options.ProjectPath, Cleanup: utils.IsBlank(options.ProjectPath)}) runner.projectFile, projectFileErr = projectfile.New(&projectfile.Options{Path: options.ProjectPath, Cleanup: utils.IsBlank(options.ProjectPath)})
@ -284,7 +284,7 @@ func (r *Runner) Close() {
func (r *Runner) RunEnumeration() error { func (r *Runner) RunEnumeration() error {
defer r.Close() defer r.Close()
// If user asked for new templates to be executed, collect the list from template directory. // If user asked for new templates to be executed, collect the list from the templates' directory.
if r.options.NewTemplates { if r.options.NewTemplates {
templatesLoaded, err := r.readNewTemplatesFile() templatesLoaded, err := r.readNewTemplatesFile()
if err != nil { if err != nil {
@ -536,7 +536,7 @@ func (r *Runner) readNewTemplatesFile() ([]string, error) {
return templatesList, nil return templatesList, nil
} }
// readNewTemplatesFile reads newly added templates from directory if it exists // countNewTemplates returns the number of newly added templates
func (r *Runner) countNewTemplates() int { func (r *Runner) countNewTemplates() int {
if r.templatesConfig == nil { if r.templatesConfig == nil {
return 0 return 0

View File

@ -57,7 +57,7 @@ func (r *Runner) logAvailableTemplate(tplPath string) {
} }
} }
// ListAvailableTemplates prints available templates to stdout // listAvailableTemplates prints available templates to stdout
func (r *Runner) listAvailableTemplates() { func (r *Runner) listAvailableTemplates() {
if r.templatesConfig == nil { if r.templatesConfig == nil {
return return

View File

@ -44,11 +44,11 @@ const (
var reVersion = regexp.MustCompile(`\d+\.\d+\.\d+`) var reVersion = regexp.MustCompile(`\d+\.\d+\.\d+`)
// updateTemplates checks if the default list of nuclei-templates // updateTemplates checks if the default list of nuclei-templates
// exist in the users home directory, if not the latest revision // exist in the user's home directory, if not the latest revision
// is downloaded from github. // is downloaded from GitHub.
// //
// If the path exists but is not latest, the new version is downloaded // If the path exists but does not contain the latest version of public templates,
// from github and replaced with the templates directory. // the new version is downloaded from GitHub to the templates' directory, overwriting the old content.
func (r *Runner) updateTemplates() error { func (r *Runner) updateTemplates() error {
home, err := os.UserHomeDir() home, err := os.UserHomeDir()
if err != nil { if err != nil {
@ -61,7 +61,7 @@ func (r *Runner) updateTemplates() error {
return errors.Wrap(err, "could not read configuration file") return errors.Wrap(err, "could not read configuration file")
} }
// If the config doesn't exist, write it now. // If the config doesn't exist, create it now.
if r.templatesConfig == nil { if r.templatesConfig == nil {
currentConfig := &config.Config{ currentConfig := &config.Config{
TemplatesDirectory: filepath.Join(home, "nuclei-templates"), TemplatesDirectory: filepath.Join(home, "nuclei-templates"),
@ -78,11 +78,8 @@ func (r *Runner) updateTemplates() error {
return nil return nil
} }
// Check if last checked for nuclei-ignore is more than 1 hours. // Tests if last checked time for nuclei-ignore file was more than 1 hour ago, if yes, updates the local content.
// and if true, run the check. // Retrieves the latest version number of nuclei and nuclei-templates from GitHub, to check if the current build is using outdated versions or not.
//
// Also at the same time fetch latest version from github to do outdated nuclei
// and templates check.
checkedIgnore := false checkedIgnore := false
if r.templatesConfig == nil || time.Since(r.templatesConfig.LastCheckedIgnore) > 1*time.Hour { if r.templatesConfig == nil || time.Since(r.templatesConfig.LastCheckedIgnore) > 1*time.Hour {
checkedIgnore = r.checkNucleiIgnoreFileUpdates(configDir) checkedIgnore = r.checkNucleiIgnoreFileUpdates(configDir)
@ -92,7 +89,7 @@ func (r *Runner) updateTemplates() error {
if r.templatesConfig.CurrentVersion == "" || (r.options.TemplatesDirectory != "" && r.templatesConfig.TemplatesDirectory != r.options.TemplatesDirectory) { if r.templatesConfig.CurrentVersion == "" || (r.options.TemplatesDirectory != "" && r.templatesConfig.TemplatesDirectory != r.options.TemplatesDirectory) {
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 the custom location if the user has given a template directory
r.templatesConfig = &config.Config{ r.templatesConfig = &config.Config{
TemplatesDirectory: filepath.Join(home, "nuclei-templates"), TemplatesDirectory: filepath.Join(home, "nuclei-templates"),
} }
@ -107,7 +104,7 @@ func (r *Runner) updateTemplates() error {
} }
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)
r.fetchLatestVersionsFromGithub() // also fetch latest versions r.fetchLatestVersionsFromGithub() // also fetch the latest versions
if _, err := r.downloadReleaseAndUnzip(ctx, version.String(), asset.GetZipballURL()); err != nil { if _, err := r.downloadReleaseAndUnzip(ctx, version.String(), asset.GetZipballURL()); err != nil {
return err return err
} }
@ -120,13 +117,14 @@ func (r *Runner) updateTemplates() error {
return nil return nil
} }
// Check if last checked is more than 24 hours and we don't have updateTemplates flag. // If the template update was not requested explicitly by the user,
// If not, return since we don't want to do anything now. // and the last version check was less than 24 hours ago,
// then no further action is required.
if time.Since(r.templatesConfig.LastChecked) < 24*time.Hour && !r.options.UpdateTemplates { if time.Since(r.templatesConfig.LastChecked) < 24*time.Hour && !r.options.UpdateTemplates {
return nil return nil
} }
// Get the configuration currently on disk. // Get the current configuration from disk.
verText := r.templatesConfig.CurrentVersion verText := r.templatesConfig.CurrentVersion
indices := reVersion.FindStringIndex(verText) indices := reVersion.FindStringIndex(verText)
if indices == nil { if indices == nil {
@ -190,7 +188,7 @@ func (r *Runner) readInternalConfigurationFile(home, configDir string) error {
return nil return nil
} }
// checkNucleiIgnoreFileUpdates checks .nuclei-ignore file for updates from github // checkNucleiIgnoreFileUpdates checks .nuclei-ignore file for updates from GitHub
func (r *Runner) checkNucleiIgnoreFileUpdates(configDir string) bool { func (r *Runner) checkNucleiIgnoreFileUpdates(configDir string) bool {
ignoreURL := defaultIgnoreURL ignoreURL := defaultIgnoreURL
if r.templatesConfig != nil && r.templatesConfig.IgnoreURL != "" { if r.templatesConfig != nil && r.templatesConfig.IgnoreURL != "" {
@ -290,7 +288,7 @@ func (r *Runner) downloadReleaseAndUnzip(ctx context.Context, version, downloadU
return nil, fmt.Errorf("failed to uncompress zip file: %s", err) return nil, fmt.Errorf("failed to uncompress zip file: %s", err)
} }
// Create the template folder if it doesn't exists // Create the template folder if it doesn't exist
if err := os.MkdirAll(r.templatesConfig.TemplatesDirectory, os.ModePerm); err != nil { if err := os.MkdirAll(r.templatesConfig.TemplatesDirectory, os.ModePerm); err != nil {
return nil, fmt.Errorf("failed to create template base folder: %s", err) return nil, fmt.Errorf("failed to create template base folder: %s", err)
} }

View File

@ -29,7 +29,7 @@ func setSeverity(severities *Severities, value string) error {
return fmt.Errorf("'%s' is not a valid severity", value) return fmt.Errorf("'%s' is not a valid severity", value)
} }
// TODO change the Severities type to map[Severity]interface{}, where the values are struct{}{}, to "simulates" a "set" data structure // TODO change the Severities type to map[Severity]interface{}, where the values are struct{}{}, to "simulate" a "set" data structure
*severities = append(*severities, computedSeverity) *severities = append(*severities, computedSeverity)
return nil return nil
} }

View File

@ -20,7 +20,7 @@ type TagFilter struct {
var ErrExcluded = errors.New("the template was excluded") var ErrExcluded = errors.New("the template was excluded")
// Match filters templates based on user provided tags, authors, extraTags and severity. // Match filters templates based on user provided tags, authors, extraTags and severity.
// If the template contains tags specified in the deny list, it will not be matched // If the template contains tags specified in the deny-list, it will not be matched
// unless it is explicitly specified by user using the includeTags (matchAllows field). // unless it is explicitly specified by user using the includeTags (matchAllows field).
// Matching rule: (tag1 OR tag2...) AND (author1 OR author2...) AND (severity1 OR severity2...) AND (extraTags1 OR extraTags2...) // Matching rule: (tag1 OR tag2...) AND (author1 OR author2...) AND (severity1 OR severity2...) AND (extraTags1 OR extraTags2...)
// Returns true if the template matches the filter criteria, false otherwise. // Returns true if the template matches the filter criteria, false otherwise.