Skip to content

Commit

Permalink
Merge branch 'master' into fix-175-results-highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbua committed Jul 29, 2020
2 parents 7d22f6c + 9c7237d commit 2ebc0cf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions v2/internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion v2/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion v2/pkg/executer/executer_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
25 changes: 24 additions & 1 deletion v2/pkg/requests/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/generators"
)

type GeneratorState int

const (
Init GeneratorState = iota
Running
Done
)

type Generator struct {
sync.RWMutex
positionPath int
positionRaw int
currentPayloads map[string]interface{}
gchan chan map[string]interface{}
currentGeneratorValue map[string]interface{}
state GeneratorState
}

type GeneratorFSM struct {
Expand Down Expand Up @@ -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}
}
}

Expand Down Expand Up @@ -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
}
Expand All @@ -102,6 +113,7 @@ func (gfsm *GeneratorFSM) ReadOne(key string) {
case <-afterCh:
g.Lock()
g.gchan = nil
g.state = Done
g.Unlock()
return
}
Expand All @@ -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
}
}
}
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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++
}
}
Expand Down

0 comments on commit 2ebc0cf

Please sign in to comment.