mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 04:55:28 +00:00
Added matched count + misc
This commit is contained in:
parent
9d27f79cb1
commit
a50bc4c30f
@ -67,6 +67,7 @@ func (p *Progress) Init(hostCount int64, rulesCount int, requestCount int64) {
|
||||
p.stats.AddStatic("startedAt", time.Now())
|
||||
p.stats.AddCounter("requests", uint64(0))
|
||||
p.stats.AddCounter("errors", uint64(0))
|
||||
p.stats.AddCounter("matched", uint64(0))
|
||||
p.stats.AddCounter("total", uint64(requestCount))
|
||||
|
||||
if p.active {
|
||||
@ -86,6 +87,11 @@ func (p *Progress) IncrementRequests() {
|
||||
p.stats.IncrementCounter("requests", 1)
|
||||
}
|
||||
|
||||
// IncrementMatched increments the matched counter by 1.
|
||||
func (p *Progress) IncrementMatched() {
|
||||
p.stats.IncrementCounter("matched", 1)
|
||||
}
|
||||
|
||||
// DecrementRequests decrements the number of requests from total.
|
||||
func (p *Progress) DecrementRequests(count int64) {
|
||||
// mimic dropping by incrementing the completed requests
|
||||
@ -119,6 +125,11 @@ func makePrintCallback() func(stats clistats.StatisticsClient) {
|
||||
builder.WriteString(" | RPS: ")
|
||||
builder.WriteString(clistats.String(uint64(float64(requests) / duration.Seconds())))
|
||||
|
||||
matched, _ := stats.GetCounter("matched")
|
||||
|
||||
builder.WriteString(" | Matched: ")
|
||||
builder.WriteString(clistats.String(matched))
|
||||
|
||||
errors, _ := stats.GetCounter("errors")
|
||||
builder.WriteString(" | Errors: ")
|
||||
builder.WriteString(clistats.String(errors))
|
||||
@ -153,6 +164,8 @@ func (p *Progress) getMetrics() map[string]interface{} {
|
||||
results["templates"] = clistats.String(templates)
|
||||
hosts, _ := p.stats.GetStatic("hosts")
|
||||
results["hosts"] = clistats.String(hosts)
|
||||
matched, _ := p.stats.GetStatic("matched")
|
||||
results["matched"] = clistats.String(matched)
|
||||
requests, _ := p.stats.GetCounter("requests")
|
||||
results["requests"] = clistats.String(requests)
|
||||
total, _ := p.stats.GetCounter("total")
|
||||
|
||||
@ -224,6 +224,7 @@ func (r *Runner) RunEnumeration() {
|
||||
}
|
||||
|
||||
originalTemplatesCount := len(availableTemplates)
|
||||
clusterCount := 0
|
||||
clusters := clusterer.Cluster(availableTemplates)
|
||||
for _, cluster := range clusters {
|
||||
if len(cluster) > 1 {
|
||||
@ -235,6 +236,7 @@ func (r *Runner) RunEnumeration() {
|
||||
Executer: clusterer.NewExecuter(cluster, executerOpts),
|
||||
TotalRequests: len(cluster[0].RequestsHTTP),
|
||||
})
|
||||
clusterCount++
|
||||
} else {
|
||||
finalTemplates = append(finalTemplates, cluster[0])
|
||||
}
|
||||
@ -248,7 +250,7 @@ func (r *Runner) RunEnumeration() {
|
||||
totalRequests += int64(t.TotalRequests) * r.inputCount
|
||||
}
|
||||
if totalRequests < unclusteredRequests {
|
||||
gologger.Info().Msgf("Reduced %d requests to %d via clustering", unclusteredRequests, totalRequests)
|
||||
gologger.Info().Msgf("Reduced %d requests to %d (%d templates clustered)", unclusteredRequests, totalRequests, clusterCount)
|
||||
}
|
||||
templateCount := originalTemplatesCount
|
||||
hasWorkflows := workflowCount > 0
|
||||
@ -272,8 +274,7 @@ func (r *Runner) RunEnumeration() {
|
||||
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
|
||||
p := r.progress
|
||||
p.Init(r.inputCount, templateCount, totalRequests)
|
||||
r.progress.Init(r.inputCount, templateCount, totalRequests)
|
||||
|
||||
for _, t := range finalTemplates {
|
||||
wgtemplates.Add()
|
||||
@ -288,7 +289,7 @@ func (r *Runner) RunEnumeration() {
|
||||
}(t)
|
||||
}
|
||||
wgtemplates.Wait()
|
||||
p.Stop()
|
||||
r.progress.Stop()
|
||||
}
|
||||
|
||||
if !results.Load() {
|
||||
|
||||
@ -71,6 +71,7 @@ func (e *Executer) Execute(input string) (bool, error) {
|
||||
results = true
|
||||
for _, r := range event.Results {
|
||||
e.options.Output.Write(r)
|
||||
e.options.Progress.IncrementMatched()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ func (e *Executer) Execute(input string) (bool, error) {
|
||||
for _, result := range event.Results {
|
||||
results = true
|
||||
e.options.Output.Write(result)
|
||||
e.options.Progress.IncrementMatched()
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@ -3,6 +3,7 @@ package workflows
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v2/internal/progress"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||
@ -10,9 +11,14 @@ import (
|
||||
)
|
||||
|
||||
func TestWorkflowsSimple(t *testing.T) {
|
||||
progress, _ := progress.NewProgress(false, false, 0)
|
||||
|
||||
workflow := &Workflow{Workflows: []*WorkflowTemplate{
|
||||
{Executer: &mockExecuter{result: true}},
|
||||
}}
|
||||
},
|
||||
options: &protocols.ExecuterOptions{
|
||||
Progress: progress,
|
||||
}}
|
||||
|
||||
matched, err := workflow.RunWorkflow("https://test.com")
|
||||
require.Nil(t, err, "could not run workflow")
|
||||
@ -20,6 +26,8 @@ func TestWorkflowsSimple(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWorkflowsSimpleMultiple(t *testing.T) {
|
||||
progress, _ := progress.NewProgress(false, false, 0)
|
||||
|
||||
var firstInput, secondInput string
|
||||
workflow := &Workflow{Workflows: []*WorkflowTemplate{
|
||||
{Executer: &mockExecuter{result: true, executeHook: func(input string) {
|
||||
@ -28,7 +36,8 @@ func TestWorkflowsSimpleMultiple(t *testing.T) {
|
||||
{Executer: &mockExecuter{result: true, executeHook: func(input string) {
|
||||
secondInput = input
|
||||
}}},
|
||||
}}
|
||||
},
|
||||
options: &protocols.ExecuterOptions{Progress: progress}}
|
||||
|
||||
matched, err := workflow.RunWorkflow("https://test.com")
|
||||
require.Nil(t, err, "could not run workflow")
|
||||
@ -39,6 +48,8 @@ func TestWorkflowsSimpleMultiple(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWorkflowsSubtemplates(t *testing.T) {
|
||||
progress, _ := progress.NewProgress(false, false, 0)
|
||||
|
||||
var firstInput, secondInput string
|
||||
workflow := &Workflow{Workflows: []*WorkflowTemplate{
|
||||
{Executer: &mockExecuter{result: true, executeHook: func(input string) {
|
||||
@ -49,7 +60,8 @@ func TestWorkflowsSubtemplates(t *testing.T) {
|
||||
secondInput = input
|
||||
}}},
|
||||
}},
|
||||
}}
|
||||
},
|
||||
options: &protocols.ExecuterOptions{Progress: progress}}
|
||||
|
||||
matched, err := workflow.RunWorkflow("https://test.com")
|
||||
require.Nil(t, err, "could not run workflow")
|
||||
@ -60,6 +72,8 @@ func TestWorkflowsSubtemplates(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWorkflowsSubtemplatesNoMatch(t *testing.T) {
|
||||
progress, _ := progress.NewProgress(false, false, 0)
|
||||
|
||||
var firstInput, secondInput string
|
||||
workflow := &Workflow{Workflows: []*WorkflowTemplate{
|
||||
{Executer: &mockExecuter{result: false, executeHook: func(input string) {
|
||||
@ -70,7 +84,8 @@ func TestWorkflowsSubtemplatesNoMatch(t *testing.T) {
|
||||
secondInput = input
|
||||
}}},
|
||||
}},
|
||||
}}
|
||||
},
|
||||
options: &protocols.ExecuterOptions{Progress: progress}}
|
||||
|
||||
matched, err := workflow.RunWorkflow("https://test.com")
|
||||
require.Nil(t, err, "could not run workflow")
|
||||
@ -81,6 +96,8 @@ func TestWorkflowsSubtemplatesNoMatch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWorkflowsSubtemplatesWithMatcher(t *testing.T) {
|
||||
progress, _ := progress.NewProgress(false, false, 0)
|
||||
|
||||
var firstInput, secondInput string
|
||||
workflow := &Workflow{Workflows: []*WorkflowTemplate{
|
||||
{Executer: &mockExecuter{result: true, executeHook: func(input string) {
|
||||
@ -99,7 +116,8 @@ func TestWorkflowsSubtemplatesWithMatcher(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
},
|
||||
}}
|
||||
},
|
||||
options: &protocols.ExecuterOptions{Progress: progress}}
|
||||
|
||||
matched, err := workflow.RunWorkflow("https://test.com")
|
||||
require.Nil(t, err, "could not run workflow")
|
||||
@ -110,6 +128,8 @@ func TestWorkflowsSubtemplatesWithMatcher(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWorkflowsSubtemplatesWithMatcherNoMatch(t *testing.T) {
|
||||
progress, _ := progress.NewProgress(false, false, 0)
|
||||
|
||||
var firstInput, secondInput string
|
||||
workflow := &Workflow{Workflows: []*WorkflowTemplate{
|
||||
{Executer: &mockExecuter{result: true, executeHook: func(input string) {
|
||||
@ -128,7 +148,8 @@ func TestWorkflowsSubtemplatesWithMatcherNoMatch(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
},
|
||||
}}
|
||||
},
|
||||
options: &protocols.ExecuterOptions{Progress: progress}}
|
||||
|
||||
matched, err := workflow.RunWorkflow("https://test.com")
|
||||
require.Nil(t, err, "could not run workflow")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user