Merge pull request #344 from projectdiscovery/feature-stop-at-first-match

adding stop at first http match cli option
dev
bauthard 2020-10-07 17:28:03 +05:30 committed by GitHub
commit 7da51a8dd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 46 deletions

View File

@ -39,6 +39,7 @@ type Options struct {
CustomHeaders requests.CustomHeaders // Custom global headers
TemplatesDirectory string // TemplatesDirectory is the directory to use for storing templates
RateLimit int // Rate-Limit of requests per specified target
StopAtFirstMatch bool // Stop processing template at first full match (this may break chained requests)
}
type multiStringFlag []string
@ -80,6 +81,7 @@ func ParseOptions() *Options {
flag.BoolVar(&options.EnableProgressBar, "pbar", false, "Enable the progress bar")
flag.BoolVar(&options.TemplateList, "tl", false, "List available templates")
flag.IntVar(&options.RateLimit, "rl", 9999999, "Rate-Limit of requests per specified target") // 9999999 to avoid limiting
flag.BoolVar(&options.StopAtFirstMatch, "stop-at-first-match", false, "Stop processing http requests at first match (this may break template/workflow logic)")
flag.Parse()

View File

@ -66,6 +66,7 @@ func (r *Runner) processTemplateWithList(ctx context.Context, p progress.IProgre
ColoredOutput: !r.options.NoColor,
Colorizer: &r.colorizer,
Decolorizer: r.decolorizer,
StopAtFirstMatch: r.options.StopAtFirstMatch,
})
}

View File

@ -52,6 +52,7 @@ type HTTPExecuter struct {
colorizer colorizer.NucleiColorizer
decolorizer *regexp.Regexp
stopAtFirstMatch bool
}
// HTTPOptions contains configuration options for the HTTP executer.
@ -72,6 +73,7 @@ type HTTPOptions struct {
CookieJar *cookiejar.Jar
Colorizer *colorizer.NucleiColorizer
Decolorizer *regexp.Regexp
StopAtFirstMatch bool
}
// NewHTTPExecuter creates a new HTTP executer from a template
@ -121,6 +123,7 @@ func NewHTTPExecuter(options *HTTPOptions) (*HTTPExecuter, error) {
coloredOutput: options.ColoredOutput,
colorizer: *options.Colorizer,
decolorizer: options.Decolorizer,
stopAtFirstMatch: options.StopAtFirstMatch,
}
return executer, nil
@ -154,6 +157,12 @@ func (e *HTTPExecuter) ExecuteHTTP(ctx context.Context, p progress.IProgress, re
}
}
// Check if has to stop processing at first valid result
if e.stopAtFirstMatch && result.GotResults {
p.Drop(remaining)
break
}
// move always forward with requests
e.bulkHTTPRequest.Increment(reqURL)
p.Update()