multiple bug fixes + performance improvements (#5148)

* prototype errkit

* complete errkit implementation

* add cause to all timeouts

* fix request timeout annotation @timeout

* increase responseHeaderTimeout to 8 for stability

* rawhttp error related improvements

* feat: add port status caching

* add port status caching to http

* migrate to new utils/errkit

* remote dialinterface + error cause

* debug dir support using .gitignore debug-*

* make nuclei easy to debug

* debug dir update .gitignore

* temp change (to revert)

* Revert "temp change (to revert)"

This reverts commit d3131f7777.

* use available context instead of new one

* bump fastdialer

* fix hosterrorscache + misc improvements

* add 'address' field in error log

* fix js vague errors + pgwrap driver

* fix max host error + misc updates

* update tests as per changes

* fix request annotation context

* remove closed dialer reference

* fix sdk panic issue

* bump retryablehttp-go,utils,fastdialer

---------

Co-authored-by: Sandeep Singh <sandeep@projectdiscovery.io>
This commit is contained in:
Tarun Koyalwar
2024-05-25 00:29:04 +05:30
committed by GitHub
parent 46e4810efb
commit 23bd0336fb
38 changed files with 768 additions and 205 deletions

View File

@@ -32,6 +32,7 @@ import (
protocolutils "github.com/projectdiscovery/nuclei/v3/pkg/protocols/utils"
templateTypes "github.com/projectdiscovery/nuclei/v3/pkg/templates/types"
"github.com/projectdiscovery/nuclei/v3/pkg/types"
"github.com/projectdiscovery/utils/errkit"
errorutil "github.com/projectdiscovery/utils/errors"
iputil "github.com/projectdiscovery/utils/ip"
syncutil "github.com/projectdiscovery/utils/sync"
@@ -360,7 +361,7 @@ func (request *Request) ExecuteWithResults(target *contextargs.Context, dynamicV
}
if request.generator != nil && request.Threads > 1 {
request.executeRequestParallel(context.Background(), hostPort, hostname, input, payloadValues, callback)
request.executeRequestParallel(target.Context(), hostPort, hostname, input, payloadValues, callback)
return nil
}
@@ -387,11 +388,10 @@ func (request *Request) ExecuteWithResults(target *contextargs.Context, dynamicV
}
callback(result)
}, requestOptions); err != nil {
_ = err
// Review: should we log error here?
// it is technically not error as it is expected to fail
// gologger.Warning().Msgf("Could not execute request: %s\n", err)
// do not return even if error occured
if errkit.IsNetworkPermanentErr(err) {
// gologger.Verbose().Msgf("Could not execute request: %s\n", err)
return err
}
}
// If this was a match, and we want to stop at first match, skip all further requests.
shouldStopAtFirstMatch := request.options.Options.StopAtFirstMatch || request.StopAtFirstMatch
@@ -408,8 +408,8 @@ func (request *Request) executeRequestParallel(ctxParent context.Context, hostPo
if threads == 0 {
threads = 1
}
ctx, cancel := context.WithCancel(ctxParent)
defer cancel()
ctx, cancel := context.WithCancelCause(ctxParent)
defer cancel(nil)
requestOptions := request.options
gotmatches := &atomic.Bool{}
@@ -453,16 +453,15 @@ func (request *Request) executeRequestParallel(ctxParent context.Context, hostPo
}
callback(result)
}, requestOptions); err != nil {
_ = err
// Review: should we log error here?
// it is technically not error as it is expected to fail
// gologger.Warning().Msgf("Could not execute request: %s\n", err)
// do not return even if error occured
if errkit.IsNetworkPermanentErr(err) {
cancel(err)
return
}
}
// If this was a match, and we want to stop at first match, skip all further requests.
if shouldStopAtFirstMatch && gotmatches.Load() {
cancel()
cancel(nil)
return
}
}()
@@ -507,7 +506,6 @@ func (request *Request) executeRequestWithPayloads(hostPort string, input *conte
results = compiler.ExecuteResult{"success": false, "error": err.Error()}
}
request.options.Progress.IncrementRequests()
requestOptions.Output.Request(requestOptions.TemplateID, hostPort, request.Type().String(), err)
gologger.Verbose().Msgf("[%s] Sent Javascript request to %s", request.options.TemplateID, hostPort)