Cancel http requests if the host keeps erroring

dev
Ice3man543 2021-08-17 14:23:42 +05:30
parent dd6f9bbc61
commit b800e2cce2
2 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,8 @@
package runner
import (
"fmt"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
"github.com/remeh/sizedwaitgroup"
@ -22,6 +24,7 @@ func (r *Runner) processTemplateWithList(template *templates.Template) bool {
go func(URL string) {
defer wg.Done()
fmt.Printf("%v %v\n", URL, template.Info)
match, err := template.Executer.Execute(URL)
if err != nil {
gologger.Warning().Msgf("[%s] Could not execute step: %s\n", r.colorizer.BrightBlue(template.ID), err)

View File

@ -216,6 +216,10 @@ func (r *Request) ExecuteWithResults(reqURL string, dynamicValues, previous outp
return err
}
// Check if hosts just keep erroring
if r.options.HostErrorsCache != nil && r.options.HostErrorsCache.Check(reqURL) {
break
}
var gotOutput bool
r.options.RateLimiter.Take()
err = r.executeRequest(reqURL, request, previous, func(event *output.InternalWrappedEvent) {
@ -237,7 +241,10 @@ func (r *Request) ExecuteWithResults(reqURL string, dynamicValues, previous outp
}
}, requestCount)
if err != nil {
requestErr = multierr.Append(requestErr, err)
if r.options.HostErrorsCache != nil && r.options.HostErrorsCache.CheckError(err) {
r.options.HostErrorsCache.MarkFailed(reqURL)
}
requestErr = err
}
requestCount++
r.options.Progress.IncrementRequests()