Added feature to run raw http templates without inputs

This commit is contained in:
Ice3man543 2021-02-07 03:46:26 +05:30
parent 8a2ca1ebb8
commit d0f5c3ce9f
4 changed files with 33 additions and 20 deletions

View File

@ -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()

View File

@ -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,9 +272,6 @@ 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)
@ -292,7 +288,6 @@ func (r *Runner) RunEnumeration() {
}(t)
}
wgtemplates.Wait()
}
r.progress.Stop()
if !results.Load() {

View File

@ -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")
}

View File

@ -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))