mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 11:55:26 +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{}
|
results := &atomic.Bool{}
|
||||||
wg := sizedwaitgroup.New(r.options.BulkSize)
|
wg := sizedwaitgroup.New(r.options.BulkSize)
|
||||||
|
|
||||||
|
executed := atomic.NewBool(false)
|
||||||
r.hostMap.Scan(func(k, _ []byte) error {
|
r.hostMap.Scan(func(k, _ []byte) error {
|
||||||
URL := string(k)
|
URL := string(k)
|
||||||
|
executed.CAS(false, true)
|
||||||
|
|
||||||
wg.Add()
|
wg.Add()
|
||||||
go func(URL string) {
|
go func(URL string) {
|
||||||
@ -31,6 +33,14 @@ func (r *Runner) processTemplateWithList(template *templates.Template) bool {
|
|||||||
}(URL)
|
}(URL)
|
||||||
return nil
|
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()
|
wg.Wait()
|
||||||
|
|
||||||
return results.Load()
|
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)
|
gologger.Info().Msgf("Reduced %d requests to %d (%d templates clustered)", unclusteredRequests, totalRequests, clusterCount)
|
||||||
}
|
}
|
||||||
templateCount := originalTemplatesCount
|
templateCount := originalTemplatesCount
|
||||||
hasWorkflows := workflowCount > 0
|
|
||||||
|
|
||||||
// 0 matches means no templates were found in directory
|
// 0 matches means no templates were found in directory
|
||||||
if templateCount == 0 {
|
if templateCount == 0 {
|
||||||
@ -273,26 +272,22 @@ func (r *Runner) RunEnumeration() {
|
|||||||
// Starts polling or ignore
|
// Starts polling or ignore
|
||||||
collaborator.DefaultCollaborator.Poll()
|
collaborator.DefaultCollaborator.Poll()
|
||||||
|
|
||||||
if r.inputCount == 0 {
|
// tracks global progress and captures stdout/stderr until p.Wait finishes
|
||||||
gologger.Error().Msgf("Could not find any valid input URLs.")
|
r.progress.Init(r.inputCount, templateCount, totalRequests)
|
||||||
} else if totalRequests > 0 || hasWorkflows {
|
|
||||||
// tracks global progress and captures stdout/stderr until p.Wait finishes
|
|
||||||
r.progress.Init(r.inputCount, templateCount, totalRequests)
|
|
||||||
|
|
||||||
for _, t := range finalTemplates {
|
for _, t := range finalTemplates {
|
||||||
wgtemplates.Add()
|
wgtemplates.Add()
|
||||||
go func(template *templates.Template) {
|
go func(template *templates.Template) {
|
||||||
defer wgtemplates.Done()
|
defer wgtemplates.Done()
|
||||||
|
|
||||||
if len(template.Workflows) > 0 {
|
if len(template.Workflows) > 0 {
|
||||||
results.CAS(false, r.processWorkflowWithList(template))
|
results.CAS(false, r.processWorkflowWithList(template))
|
||||||
} else {
|
} else {
|
||||||
results.CAS(false, r.processTemplateWithList(template))
|
results.CAS(false, r.processTemplateWithList(template))
|
||||||
}
|
}
|
||||||
}(t)
|
}(t)
|
||||||
}
|
|
||||||
wgtemplates.Wait()
|
|
||||||
}
|
}
|
||||||
|
wgtemplates.Wait()
|
||||||
r.progress.Stop()
|
r.progress.Stop()
|
||||||
|
|
||||||
if !results.Load() {
|
if !results.Load() {
|
||||||
|
|||||||
@ -13,8 +13,8 @@ func TestBaseURLWithTemplatePrefs(t *testing.T) {
|
|||||||
parsed, _ := url.Parse(baseURL)
|
parsed, _ := url.Parse(baseURL)
|
||||||
|
|
||||||
data := "{{BaseURL}}:8000/newpath"
|
data := "{{BaseURL}}:8000/newpath"
|
||||||
data, new := baseURLWithTemplatePrefs(data, parsed)
|
data, parsed = baseURLWithTemplatePrefs(data, parsed)
|
||||||
require.Equal(t, "http://localhost:8000/test", new, "could not get correct value")
|
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")
|
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 drainReqSize = int64(8 * 1024)
|
||||||
|
const testInputMarker = "http://test.test"
|
||||||
|
|
||||||
// executeRequest executes the actual generated request and returns error if occured
|
// 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 {
|
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
|
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 {
|
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.Info().Msgf("[%s] Dumped HTTP request for %s\n\n", r.options.TemplateID, reqURL)
|
||||||
gologger.Print().Msgf("%s", string(dumpedRequest))
|
gologger.Print().Msgf("%s", string(dumpedRequest))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user