Skip to content

Commit

Permalink
bump utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Jul 21, 2023
1 parent aa6e94d commit d361c16
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 27 deletions.
6 changes: 4 additions & 2 deletions v2/cmd/integration-test/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
"github.com/projectdiscovery/ratelimit"
contextutil "github.com/projectdiscovery/utils/context"
)

var codeTestcases = map[string]testutils.TestCase{
Expand Down Expand Up @@ -65,11 +66,12 @@ func (h *goIntegrationTest) Execute(templatePath string) error {

// executeNucleiAsCode contains an example
func executeNucleiAsCode(templatePath, templateURL string) ([]string, error) {
ctx := contextutil.ValueOrDefault(nil)
cache := hosterrorscache.New(30, hosterrorscache.DefaultMaxHostsCount, nil)
defer cache.Close()

mockProgress := &testutils.MockProgressClient{}
reportingClient, err := reporting.New(&reporting.Options{}, "", context.TODO())
reportingClient, err := reporting.New(&reporting.Options{Ctx: ctx}, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -100,7 +102,7 @@ func executeNucleiAsCode(templatePath, templateURL string) ([]string, error) {
ratelimiter := ratelimit.New(context.Background(), 150, time.Second)
defer ratelimiter.Stop()
executerOpts := protocols.ExecutorOptions{
Ctx: context.TODO(),
Ctx: ctx,
Output: outputWriter,
Options: defaultOpts,
Progress: mockProgress,
Expand Down
2 changes: 1 addition & 1 deletion v2/cmd/integration-test/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (h *clientCertificate) Execute(filePath string) error {

tlsConfig := &tls.Config{
Certificates: []tls.Certificate{serverCert},
ClientAuth: tls.RequireAndVerifyClientCert,
ClientAuth: tls.RequireAnyClientCert,
ClientCAs: certPool,
}

Expand Down
2 changes: 1 addition & 1 deletion v2/examples/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
defer cache.Close()

mockProgress := &testutils.MockProgressClient{}
reportingClient, _ := reporting.New(&reporting.Options{}, "", ctx)
reportingClient, _ := reporting.New(&reporting.Options{Ctx: ctx}, "")
defer reportingClient.Close()

outputWriter := testutils.NewMockOutputWriter()
Expand Down
6 changes: 3 additions & 3 deletions v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ require (
github.com/projectdiscovery/sarif v0.0.1
github.com/projectdiscovery/tlsx v1.1.0
github.com/projectdiscovery/uncover v1.0.6-0.20230601103158-bfd7e02a5bb1
github.com/projectdiscovery/utils v0.0.41-0.20230705082547-236cfa9298ab
github.com/projectdiscovery/utils v0.0.45-0.20230721135454-04c5c27e7678
github.com/projectdiscovery/wappalyzergo v0.0.104
github.com/stretchr/testify v1.8.4
gopkg.in/src-d/go-git.v4 v4.13.1
Expand All @@ -101,11 +101,11 @@ require (
github.com/bits-and-blooms/bitset v1.3.1 // indirect
github.com/bits-and-blooms/bloom/v3 v3.4.0 // indirect
github.com/charmbracelet/glamour v0.6.0 // indirect
github.com/cheggaaa/pb/v3 v3.1.2 // indirect
github.com/cheggaaa/pb/v3 v3.1.4 // indirect
github.com/cloudflare/cfssl v1.6.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/dlclark/regexp2 v1.8.1 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gaukas/godicttls v0.0.3 // indirect
github.com/google/certificate-transparency-go v1.1.4 // indirect
Expand Down
12 changes: 6 additions & 6 deletions v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ github.com/caddyserver/certmagic v0.17.2 h1:o30seC1T/dBqBCNNGNHWwj2i5/I/FMjBbTAh
github.com/caddyserver/certmagic v0.17.2/go.mod h1:ouWUuC490GOLJzkyN35eXfV8bSbwMwSf4bdhkIxtdQE=
github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM273bISc=
github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc=
github.com/cheggaaa/pb/v3 v3.1.2 h1:FIxT3ZjOj9XJl0U4o2XbEhjFfZl7jCVCDOGq1ZAB7wQ=
github.com/cheggaaa/pb/v3 v3.1.2/go.mod h1:SNjnd0yKcW+kw0brSusraeDd5Bf1zBfxAzTL2ss3yQ4=
github.com/cheggaaa/pb/v3 v3.1.4 h1:DN8j4TVVdKu3WxVwcRKu0sG00IIU6FewoABZzXbRQeo=
github.com/cheggaaa/pb/v3 v3.1.4/go.mod h1:6wVjILNBaXMs8c21qRiaUM8BR82erfgau1DQ4iUXmSA=
github.com/cloudflare/cfssl v1.6.4 h1:NMOvfrEjFfC63K3SGXgAnFdsgkmiq4kATme5BfcqrO8=
github.com/cloudflare/cfssl v1.6.4/go.mod h1:8b3CQMxfWPAeom3zBnGJ6sd+G1NkL5TXqmDXacb+1J0=
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
Expand Down Expand Up @@ -158,8 +158,8 @@ github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3O
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
Expand Down Expand Up @@ -435,8 +435,8 @@ github.com/projectdiscovery/tlsx v1.1.0 h1:6L5VKpHaoqvIHN6lH9zi7jIvph1JwYMYZOIpW
github.com/projectdiscovery/tlsx v1.1.0/go.mod h1:C9xTbU2t54Anmvuq+4jxevR5rzqpp6XUUtV7G9J5CTE=
github.com/projectdiscovery/uncover v1.0.6-0.20230601103158-bfd7e02a5bb1 h1:Pu6LvDqn+iSlhCDKKWm1ItPc++kqqlU8OntZeB/Prak=
github.com/projectdiscovery/uncover v1.0.6-0.20230601103158-bfd7e02a5bb1/go.mod h1:Drl/CWD392mKtdXJhCBPlMkM0I6671pqedFphcnK5f8=
github.com/projectdiscovery/utils v0.0.41-0.20230705082547-236cfa9298ab h1:KcbRfus364It55dhAUpbqFHfyCuIa8Ls/9QzMWYKq78=
github.com/projectdiscovery/utils v0.0.41-0.20230705082547-236cfa9298ab/go.mod h1:DTFCMSLh8FanDZIrzOwTo3AIv1K4w0PDELi41mjwLiw=
github.com/projectdiscovery/utils v0.0.45-0.20230721135454-04c5c27e7678 h1:v/KHKWWW17m/LjlO1rEkPIu+/EaimAbSVyfKgOleowI=
github.com/projectdiscovery/utils v0.0.45-0.20230721135454-04c5c27e7678/go.mod h1:HtUI1pyNCgQUuwZuxDILQ4NSUaFcfBh0TuCK/ZQTS6Q=
github.com/projectdiscovery/wappalyzergo v0.0.104 h1:hdda6WxAzXVpLBbJW1sLqrwOXHn0prP9IYFY7dfCMjE=
github.com/projectdiscovery/wappalyzergo v0.0.104/go.mod h1:4Z3DKhi75zIPMuA+qSDDWxZvnhL4qTLmDx4dxNMu7MA=
github.com/projectdiscovery/yamldoc-go v1.0.4 h1:eZoESapnMw6WAHiVgRwNqvbJEfNHEH148uthhFbG5jE=
Expand Down
27 changes: 15 additions & 12 deletions v2/internal/runner/runner.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package runner

import (
"context"
"encoding/json"
"net/http"
_ "net/http/pprof"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/internal/installer"
"github.com/projectdiscovery/nuclei/v2/internal/runner/nucleicloud"
uncoverlib "github.com/projectdiscovery/uncover"
contextutil "github.com/projectdiscovery/utils/context"
updateutils "github.com/projectdiscovery/utils/update"

"github.com/logrusorgru/aurora"
Expand Down Expand Up @@ -83,6 +83,8 @@ const pprofServerAddress = "127.0.0.1:8086"

// New creates a new client for running the enumeration process.
func New(options *types.Options) (*Runner, error) {
ctx := contextutil.ValueOrDefault(nil)

runner := &Runner{
options: options,
}
Expand All @@ -105,7 +107,7 @@ func New(options *types.Options) (*Runner, error) {
}

// check for custom template updates and update if available
ctm, err := customtemplates.NewCustomTemplatesManager(context.TODO(), options)
ctm, err := customtemplates.NewCustomTemplatesManager(ctx, options)
if err != nil {
gologger.Error().Label("custom-templates").Msgf("Failed to create custom templates manager: %s\n", err)
}
Expand All @@ -116,10 +118,10 @@ func New(options *types.Options) (*Runner, error) {
CustomTemplates: ctm,
DisablePublicTemplates: options.PublicTemplateDisableDownload,
}
if err := tm.FreshInstallIfNotExists(context.TODO()); err != nil {
if err := tm.FreshInstallIfNotExists(ctx); err != nil {
gologger.Warning().Msgf("failed to install nuclei templates: %s\n", err)
}
if err := tm.UpdateIfOutdated(context.TODO()); err != nil {
if err := tm.UpdateIfOutdated(ctx); err != nil {
gologger.Warning().Msgf("failed to update nuclei templates: %s\n", err)
}

Expand All @@ -137,7 +139,7 @@ func New(options *types.Options) (*Runner, error) {
}
// manually trigger update of custom templates
if ctm != nil {
ctm.Update(context.TODO())
ctm.Update(ctx)
}
}
}
Expand Down Expand Up @@ -184,7 +186,7 @@ func New(options *types.Options) (*Runner, error) {
}

if reportingOptions != nil {
client, err := reporting.New(reportingOptions, options.ReportingDB, context.TODO())
client, err := reporting.New(reportingOptions, options.ReportingDB)
if err != nil {
return nil, errors.Wrap(err, "could not create issue reporting client")
}
Expand Down Expand Up @@ -215,7 +217,7 @@ func New(options *types.Options) (*Runner, error) {

// Initialize the input source
hmapInput, err := hybrid.New(&hybrid.Options{
Ctx: context.TODO(),
Ctx: ctx,
Options: options,
NotFoundCallback: func(target string) bool {
if !options.Cloud {
Expand Down Expand Up @@ -318,11 +320,11 @@ func New(options *types.Options) (*Runner, error) {
}

if options.RateLimitMinute > 0 {
runner.rateLimiter = ratelimit.New(context.TODO(), uint(options.RateLimitMinute), time.Minute)
runner.rateLimiter = ratelimit.New(ctx, uint(options.RateLimitMinute), time.Minute)
} else if options.RateLimit > 0 {
runner.rateLimiter = ratelimit.New(context.TODO(), uint(options.RateLimit), time.Second)
runner.rateLimiter = ratelimit.New(ctx, uint(options.RateLimit), time.Second)
} else {
runner.rateLimiter = ratelimit.NewUnlimited(context.TODO())
runner.rateLimiter = ratelimit.NewUnlimited(ctx)
}
return runner, nil
}
Expand Down Expand Up @@ -398,6 +400,7 @@ func createReportingOptions(options *types.Options) (*reporting.Options, error)

// Close releases all the resources and cleans up
func (r *Runner) Close() {
ctx := contextutil.ValueOrDefault(nil)
if r.output != nil {
r.output.Close()
}
Expand All @@ -407,7 +410,7 @@ func (r *Runner) Close() {
r.hmapInputProvider.Close()
protocolinit.Close()
if r.pprofServer != nil {
_ = r.pprofServer.Shutdown(context.TODO())
_ = r.pprofServer.Shutdown(ctx)
}
if r.rateLimiter != nil {
r.rateLimiter.Stop()
Expand Down Expand Up @@ -438,7 +441,7 @@ func (r *Runner) RunEnumeration(options ...core.EnumerateOption) error {
// Create the executor options which will be used throughout the execution
// stage by the nuclei engine modules.
executorOpts := protocols.ExecutorOptions{
Ctx: context.Background(), // set default value
Ctx: contextutil.ValueOrDefault(nil), // set default value
Output: r.output,
Options: r.options,
Progress: r.progress,
Expand Down
3 changes: 3 additions & 0 deletions v2/pkg/reporting/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package reporting

import (
"context"

"github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/es"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/jsonexporter"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/jsonl"
Expand All @@ -15,6 +17,7 @@ import (

// Options is a configuration file for nuclei reporting module
type Options struct {
Ctx context.Context `yaml:"-"`
// AllowList contains a list of allowed events for reporting module
AllowList *Filter `yaml:"allow-list"`
// DenyList contains a list of denied events for reporting module
Expand Down
6 changes: 4 additions & 2 deletions v2/pkg/reporting/reporting.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package reporting

import (
"context"
"os"

"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/trackers/github"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/trackers/gitlab"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/trackers/jira"
contextutil "github.com/projectdiscovery/utils/context"
errorutil "github.com/projectdiscovery/utils/errors"
fileutil "github.com/projectdiscovery/utils/file"
sliceutil "github.com/projectdiscovery/utils/slice"
Expand Down Expand Up @@ -95,7 +95,9 @@ type ReportingClient struct {
}

// New creates a new nuclei issue tracker reporting client
func New(options *Options, db string, ctx context.Context) (Client, error) {
func New(options *Options, db string) (Client, error) {
ctx := contextutil.ValueOrDefault(options.Ctx)

client := &ReportingClient{options: options}

if options.GitHub != nil {
Expand Down

0 comments on commit d361c16

Please sign in to comment.