diff --git a/v2/internal/runner/processor.go b/v2/internal/runner/processor.go index 4ed008cd5..6091faee5 100644 --- a/v2/internal/runner/processor.go +++ b/v2/internal/runner/processor.go @@ -16,8 +16,10 @@ func (r *Runner) processTemplateWithList(template *templates.Template) bool { results := &atomic.Bool{} wg := sizedwaitgroup.New(r.options.BulkSize) + executed := atomic.NewBool(false) r.hostMap.Scan(func(k, _ []byte) error { URL := string(k) + executed.CAS(false, true) wg.Add() go func(URL string) { @@ -31,6 +33,14 @@ func (r *Runner) processTemplateWithList(template *templates.Template) bool { }(URL) return nil }) + // Run template once if we have http requests with no input + if len(template.RequestsHTTP) > 0 && r.hostMap.Size() == 0 && !executed.Load() { + match, err := template.Executer.Execute("http://test.test") + if err != nil { + gologger.Warning().Msgf("[%s] Could not execute step: %s\n", r.colorizer.BrightBlue(template.ID), err) + } + results.CAS(false, match) + } wg.Wait() return results.Load() diff --git a/v2/internal/runner/runner.go b/v2/internal/runner/runner.go index 18a9291e6..bf73b896f 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -256,7 +256,6 @@ func (r *Runner) RunEnumeration() { gologger.Info().Msgf("Reduced %d requests to %d (%d templates clustered)", unclusteredRequests, totalRequests, clusterCount) } templateCount := originalTemplatesCount - hasWorkflows := workflowCount > 0 // 0 matches means no templates were found in directory if templateCount == 0 { @@ -273,26 +272,22 @@ func (r *Runner) RunEnumeration() { // Starts polling or ignore collaborator.DefaultCollaborator.Poll() - if r.inputCount == 0 { - gologger.Error().Msgf("Could not find any valid input URLs.") - } else if totalRequests > 0 || hasWorkflows { - // tracks global progress and captures stdout/stderr until p.Wait finishes - r.progress.Init(r.inputCount, templateCount, totalRequests) + // tracks global progress and captures stdout/stderr until p.Wait finishes + r.progress.Init(r.inputCount, templateCount, totalRequests) - for _, t := range finalTemplates { - wgtemplates.Add() - go func(template *templates.Template) { - defer wgtemplates.Done() + for _, t := range finalTemplates { + wgtemplates.Add() + go func(template *templates.Template) { + defer wgtemplates.Done() - if len(template.Workflows) > 0 { - results.CAS(false, r.processWorkflowWithList(template)) - } else { - results.CAS(false, r.processTemplateWithList(template)) - } - }(t) - } - wgtemplates.Wait() + if len(template.Workflows) > 0 { + results.CAS(false, r.processWorkflowWithList(template)) + } else { + results.CAS(false, r.processTemplateWithList(template)) + } + }(t) } + wgtemplates.Wait() r.progress.Stop() if !results.Load() { diff --git a/v2/pkg/protocols/http/build_request_test.go b/v2/pkg/protocols/http/build_request_test.go index d4d315499..6ad75f7a1 100644 --- a/v2/pkg/protocols/http/build_request_test.go +++ b/v2/pkg/protocols/http/build_request_test.go @@ -13,8 +13,8 @@ func TestBaseURLWithTemplatePrefs(t *testing.T) { parsed, _ := url.Parse(baseURL) data := "{{BaseURL}}:8000/newpath" - data, new := baseURLWithTemplatePrefs(data, parsed) - require.Equal(t, "http://localhost:8000/test", new, "could not get correct value") + data, parsed = baseURLWithTemplatePrefs(data, parsed) + require.Equal(t, "http://localhost:8000/test", parsed.String(), "could not get correct value") require.Equal(t, "{{BaseURL}}/newpath", data, "could not get correct data") } diff --git a/v2/pkg/protocols/http/request.go b/v2/pkg/protocols/http/request.go index f68dfd26b..e01a662b9 100644 --- a/v2/pkg/protocols/http/request.go +++ b/v2/pkg/protocols/http/request.go @@ -206,6 +206,7 @@ func (r *Request) ExecuteWithResults(reqURL string, dynamicValues, previous outp } const drainReqSize = int64(8 * 1024) +const testInputMarker = "http://test.test" // executeRequest executes the actual generated request and returns error if occured func (r *Request) executeRequest(reqURL string, request *generatedRequest, dynamicvalues, previous output.InternalEvent, callback protocols.OutputEventCallback) error { @@ -224,6 +225,13 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, dynam return err } + if reqURL == testInputMarker { + if request.request != nil { + reqURL = request.request.URL.String() + } else if request.rawRequest != nil { + reqURL = request.rawRequest.FullURL + } + } if r.options.Options.Debug || r.options.Options.DebugRequests { gologger.Info().Msgf("[%s] Dumped HTTP request for %s\n\n", r.options.TemplateID, reqURL) gologger.Print().Msgf("%s", string(dumpedRequest))