diff --git a/v2/internal/runner/options.go b/v2/internal/runner/options.go index 78838eedb1..f99676c548 100644 --- a/v2/internal/runner/options.go +++ b/v2/internal/runner/options.go @@ -30,6 +30,7 @@ type Options struct { TemplatesDirectory string // TemplatesDirectory is the directory to use for storing templates JSON bool // JSON writes json output to files JSONRequests bool // write requests/responses for matches in JSON output + DisableProgressBar bool // Disable progrss bar Stdin bool // Stdin specifies whether stdin input was given to the process } @@ -68,6 +69,7 @@ func ParseOptions() *Options { flag.StringVar(&options.TemplatesDirectory, "update-directory", "", "Directory to use for storing nuclei-templates") flag.BoolVar(&options.JSON, "json", false, "Write json output to files") flag.BoolVar(&options.JSONRequests, "json-requests", false, "Write requests/responses for matches in JSON output") + flag.BoolVar(&options.DisableProgressBar, "no-pbar", false, "Disable the progress bar") flag.Parse() diff --git a/v2/internal/runner/runner.go b/v2/internal/runner/runner.go index 952785ef66..b71b221b2c 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -148,7 +148,7 @@ func New(options *Options) (*Runner, error) { runner.output = output } - if !options.Silent { + if !options.Silent && !options.DisableProgressBar { // Creates the progress tracking object runner.progress = progress.NewProgress(runner.options.NoColor) } diff --git a/v2/pkg/executer/executer_http.go b/v2/pkg/executer/executer_http.go index f84b3d87a0..5ee67f4f88 100644 --- a/v2/pkg/executer/executer_http.go +++ b/v2/pkg/executer/executer_http.go @@ -130,7 +130,9 @@ func (e *HTTPExecuter) ExecuteHTTP(p *progress.Progress, URL string) (result Res httpRequest, err := e.bulkHttpRequest.MakeHTTPRequest(URL, dynamicvalues, e.bulkHttpRequest.Current(URL)) if err != nil { result.Error = errors.Wrap(err, "could not build http request") - p.Drop(remaining) + if p != nil { + p.Drop(remaining) + } return } diff --git a/v2/pkg/requests/generator.go b/v2/pkg/requests/generator.go index bc470c8804..737c01cf8f 100644 --- a/v2/pkg/requests/generator.go +++ b/v2/pkg/requests/generator.go @@ -7,6 +7,14 @@ import ( "github.com/projectdiscovery/nuclei/v2/pkg/generators" ) +type GeneratorState int + +const ( + Init GeneratorState = iota + Running + Done +) + type Generator struct { sync.RWMutex positionPath int @@ -14,6 +22,7 @@ type Generator struct { currentPayloads map[string]interface{} gchan chan map[string]interface{} currentGeneratorValue map[string]interface{} + state GeneratorState } type GeneratorFSM struct { @@ -58,7 +67,7 @@ func (gfsm *GeneratorFSM) Add(key string) { defer gfsm.Unlock() if _, ok := gfsm.Generators[key]; !ok { - gfsm.Generators[key] = &Generator{} + gfsm.Generators[key] = &Generator{state: Init} } } @@ -92,6 +101,8 @@ func (gfsm *GeneratorFSM) ReadOne(key string) { if !ok { g.Lock() g.gchan = nil + g.state = Done + g.currentGeneratorValue = nil g.Unlock() return } @@ -102,6 +113,7 @@ func (gfsm *GeneratorFSM) ReadOne(key string) { case <-afterCh: g.Lock() g.gchan = nil + g.state = Done g.Unlock() return } @@ -122,6 +134,7 @@ func (gfsm *GeneratorFSM) InitOrSkip(key string) { defer g.Unlock() if g.gchan == nil { g.gchan = gfsm.generator(gfsm.basePayloads) + g.state = Running } } } @@ -138,6 +151,10 @@ func (gfsm *GeneratorFSM) Value(key string) map[string]interface{} { return g.currentGeneratorValue } +func (gfsm *GeneratorFSM) hasPayloads() bool { + return len(gfsm.basePayloads) > 0 +} + func (gfsm *GeneratorFSM) Next(key string) bool { gfsm.RLock() defer gfsm.RUnlock() @@ -147,11 +164,16 @@ func (gfsm *GeneratorFSM) Next(key string) bool { return false } + if gfsm.hasPayloads() && g.state == Done { + return false + } + if g.positionPath+g.positionRaw >= len(gfsm.Paths)+len(gfsm.Raws) { return false } return true } + func (gfsm *GeneratorFSM) Position(key string) int { gfsm.RLock() defer gfsm.RUnlock() @@ -216,6 +238,7 @@ func (gfsm *GeneratorFSM) Increment(key string) { if len(gfsm.Raws) > 0 && g.positionRaw < len(gfsm.Raws) { // if we have payloads increment only when the generators are done if g.gchan == nil { + g.state = Done g.positionRaw++ } }