Skip to content

Commit

Permalink
temp change (to revert)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunKoyalwar committed May 20, 2024
1 parent cd61c35 commit d3131f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
50 changes: 27 additions & 23 deletions pkg/core/execute_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/projectdiscovery/nuclei/v3/pkg/output"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/contextargs"
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
"github.com/projectdiscovery/nuclei/v3/pkg/templates/types"
"github.com/projectdiscovery/nuclei/v3/pkg/types/scanstrategy"
stringsutil "github.com/projectdiscovery/utils/strings"
syncutil "github.com/projectdiscovery/utils/sync"
"github.com/remeh/sizedwaitgroup"
)

// Execute takes a list of templates/workflows that have been compiled
Expand Down Expand Up @@ -106,36 +106,40 @@ func (e *Engine) executeTemplateSpray(ctx context.Context, templatesList []*temp

// wp is workpool that contains different waitgroups for
// headless and non-headless templates
wp := e.GetWorkPool()
// wp := e.GetWorkPool()
sg := sizedwaitgroup.New(e.options.TemplateThreads)

for _, template := range templatesList {
select {
case <-ctx.Done():
return results
default:
}
// select {
// case <-ctx.Done():
// return results
// default:
// }

// resize check point - nop if there are no changes
wp.RefreshWithConfig(e.GetWorkPoolConfig())

templateType := template.Type()
var wg *syncutil.AdaptiveWaitGroup
if templateType == types.HeadlessProtocol {
wg = wp.Headless
} else {
wg = wp.Default
}

wg.Add()
go func(tpl *templates.Template) {
defer wg.Done()
// wp.RefreshWithConfig(e.GetWorkPoolConfig())

// templateType := template.Type()
// var wg *syncutil.AdaptiveWaitGroup
// if templateType == types.HeadlessProtocol {
// wg = wp.Headless
// } else {
// wg = wp.Default
// }

sg.Add()
go func(ctx1 context.Context, tpl *templates.Template, tx provider.InputProvider, res *atomic.Bool) {
defer sg.Done()
// All other request types are executed here
// Note: executeTemplateWithTargets creates goroutines and blocks
// given template is executed on all targets
e.executeTemplateWithTargets(ctx, tpl, target, results)
}(template)
e.executeTemplateWithTargets(ctx1, tpl, tx, res)
// gologger.Error().Msgf("executing template %s done", tpl.ID)
}(ctx, template, target, results)
}
wp.Wait()
// gologger.Error().Msgf("executing last set of templates")
sg.Wait()
// gologger.Error().Msgf("executing last set of templates done")
return results
}

Expand Down
20 changes: 11 additions & 9 deletions pkg/protocols/network/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ func (request *Request) executeOnTarget(input *contextargs.Context, visited maps
}
visited.Set(actualAddress, struct{}{})

// gologger.Verbose().Msgf("[%v] Making network request to %s\n", request.options.TemplateID, actualAddress)
if err := request.executeAddress(variables, actualAddress, address, input, kv.tls, previous, callback); err != nil {
outputEvent := request.responseToDSLMap("", "", "", address, "")
callback(&output.InternalWrappedEvent{InternalEvent: outputEvent})
gologger.Warning().Msgf("[%v] Could not make network request for (%s) : %s\n", request.options.TemplateID, actualAddress, err)
continue
}
// gologger.Verbose().Msgf("[%v] Network request to %s done\n", request.options.TemplateID, actualAddress)
}
return nil
}
Expand All @@ -175,7 +177,7 @@ func (request *Request) executeAddress(variables map[string]interface{}, actualA
}

// if request threads matches global payload concurrency we follow it
shouldFollowGlobal := request.Threads == request.options.Options.PayloadConcurrency
// shouldFollowGlobal := request.Threads == request.options.Options.PayloadConcurrency

if request.generator != nil {
iterator := request.generator.NewIterator()
Expand All @@ -198,14 +200,14 @@ func (request *Request) executeAddress(variables map[string]interface{}, actualA
default:
}

// resize check point - nop if there are no changes
if shouldFollowGlobal && swg.Size != request.options.Options.PayloadConcurrency {
if err := swg.Resize(input.Context(), request.options.Options.PayloadConcurrency); err != nil {
m.Lock()
multiErr = multierr.Append(multiErr, err)
m.Unlock()
}
}
// // resize check point - nop if there are no changes
// if shouldFollowGlobal && swg.Size != request.options.Options.PayloadConcurrency {
// if err := swg.Resize(input.Context(), request.options.Options.PayloadConcurrency); err != nil {
// m.Lock()
// multiErr = multierr.Append(multiErr, err)
// m.Unlock()
// }
// }

value = generators.MergeMaps(value, payloads)
swg.Add()
Expand Down

0 comments on commit d3131f7

Please sign in to comment.