Skip to content

Commit

Permalink
adding stop at first http match cli option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Oct 6, 2020
1 parent e765b29 commit e12003c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 46 deletions.
2 changes: 2 additions & 0 deletions v2/internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
31 changes: 16 additions & 15 deletions v2/internal/runner/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,22 @@ func (r *Runner) processTemplateWithList(ctx context.Context, p progress.IProgre
})
case *requests.BulkHTTPRequest:
httpExecuter, err = executer.NewHTTPExecuter(&executer.HTTPOptions{
Debug: r.options.Debug,
Template: template,
BulkHTTPRequest: value,
Writer: r.output,
Timeout: r.options.Timeout,
Retries: r.options.Retries,
ProxyURL: r.options.ProxyURL,
ProxySocksURL: r.options.ProxySocksURL,
CustomHeaders: r.options.CustomHeaders,
JSON: r.options.JSON,
JSONRequests: r.options.JSONRequests,
CookieReuse: value.CookieReuse,
ColoredOutput: !r.options.NoColor,
Colorizer: &r.colorizer,
Decolorizer: r.decolorizer,
Debug: r.options.Debug,
Template: template,
BulkHTTPRequest: value,
Writer: r.output,
Timeout: r.options.Timeout,
Retries: r.options.Retries,
ProxyURL: r.options.ProxyURL,
ProxySocksURL: r.options.ProxySocksURL,
CustomHeaders: r.options.CustomHeaders,
JSON: r.options.JSON,
JSONRequests: r.options.JSONRequests,
CookieReuse: value.CookieReuse,
ColoredOutput: !r.options.NoColor,
Colorizer: &r.colorizer,
Decolorizer: r.decolorizer,
StopAtFirstMatch: r.options.StopAtFirstMatch,
})
}

Expand Down
71 changes: 40 additions & 31 deletions v2/pkg/executer/executer_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,30 @@ type HTTPExecuter struct {
customHeaders requests.CustomHeaders
CookieJar *cookiejar.Jar

colorizer colorizer.NucleiColorizer
decolorizer *regexp.Regexp
colorizer colorizer.NucleiColorizer
decolorizer *regexp.Regexp
stopAtFirstMatch bool
}

// HTTPOptions contains configuration options for the HTTP executer.
type HTTPOptions struct {
Debug bool
JSON bool
JSONRequests bool
CookieReuse bool
ColoredOutput bool
Template *templates.Template
BulkHTTPRequest *requests.BulkHTTPRequest
Writer *bufwriter.Writer
Timeout int
Retries int
ProxyURL string
ProxySocksURL string
CustomHeaders requests.CustomHeaders
CookieJar *cookiejar.Jar
Colorizer *colorizer.NucleiColorizer
Decolorizer *regexp.Regexp
Debug bool
JSON bool
JSONRequests bool
CookieReuse bool
ColoredOutput bool
Template *templates.Template
BulkHTTPRequest *requests.BulkHTTPRequest
Writer *bufwriter.Writer
Timeout int
Retries int
ProxyURL string
ProxySocksURL string
CustomHeaders requests.CustomHeaders
CookieJar *cookiejar.Jar
Colorizer *colorizer.NucleiColorizer
Decolorizer *regexp.Regexp
StopAtFirstMatch bool
}

// NewHTTPExecuter creates a new HTTP executer from a template
Expand Down Expand Up @@ -108,19 +110,20 @@ func NewHTTPExecuter(options *HTTPOptions) (*HTTPExecuter, error) {
rawClient := rawhttp.NewClient(rawhttp.DefaultOptions)

executer := &HTTPExecuter{
debug: options.Debug,
jsonOutput: options.JSON,
jsonRequest: options.JSONRequests,
httpClient: client,
rawHttpClient: rawClient,
template: options.Template,
bulkHTTPRequest: options.BulkHTTPRequest,
writer: options.Writer,
customHeaders: options.CustomHeaders,
CookieJar: options.CookieJar,
coloredOutput: options.ColoredOutput,
colorizer: *options.Colorizer,
decolorizer: options.Decolorizer,
debug: options.Debug,
jsonOutput: options.JSON,
jsonRequest: options.JSONRequests,
httpClient: client,
rawHttpClient: rawClient,
template: options.Template,
bulkHTTPRequest: options.BulkHTTPRequest,
writer: options.Writer,
customHeaders: options.CustomHeaders,
CookieJar: options.CookieJar,
coloredOutput: options.ColoredOutput,
colorizer: *options.Colorizer,
decolorizer: options.Decolorizer,
stopAtFirstMatch: options.StopAtFirstMatch,
}

return executer, nil
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e12003c

Please sign in to comment.