From d5d745e9b035aaaafd226e886809fe3017912e58 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Wed, 29 Jul 2020 19:50:54 +0200 Subject: [PATCH 1/3] adding missing check to pointer --- v2/pkg/executer/executer_http.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/v2/pkg/executer/executer_http.go b/v2/pkg/executer/executer_http.go index 219b2e4f57..5bdc354c4b 100644 --- a/v2/pkg/executer/executer_http.go +++ b/v2/pkg/executer/executer_http.go @@ -118,7 +118,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 } From 7edad4bb3320322cf0f148eae5e8bd869bbbd209 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Wed, 29 Jul 2020 20:07:13 +0200 Subject: [PATCH 2/3] adding -no-pbar option --- v2/internal/runner/options.go | 2 ++ v2/internal/runner/runner.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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 bffbe3d7b8..fa3fb30784 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -130,7 +130,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) } From 5cc3d9fe14cf2c92f8456c027b3ec2158e16d31d Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Wed, 29 Jul 2020 21:20:39 +0200 Subject: [PATCH 3/3] corrected payload issue --- v2/pkg/requests/generator.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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++ } }