mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 16:55:25 +00:00
Added feature to run raw http templates without inputs
This commit is contained in:
parent
8a2ca1ebb8
commit
d0f5c3ce9f
@ -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()
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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")
|
||||
}
|
||||
|
||||
|
||||
@ -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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user