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 28, 2020
2 parents f8e52ce + 4cf4b2e commit 7d22f6c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion v2/internal/runner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const banner = `
`

// Version is the current version of nuclei
const Version = `2.0.4`
const Version = `2.0.5`

// showBanner is used to show the banner to the user
func showBanner() {
Expand Down
27 changes: 18 additions & 9 deletions v2/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ func New(options *Options) (*Runner, error) {
runner.output = output
}

// Creates the progress tracking object
runner.progress = progress.NewProgress(runner.options.NoColor)
if !options.Silent {
// Creates the progress tracking object
runner.progress = progress.NewProgress(runner.options.NoColor)
}

runner.limiter = make(chan struct{}, options.Threads)

Expand Down Expand Up @@ -337,8 +339,10 @@ func (r *Runner) RunEnumeration() {
} else if totalRequests > 0 || hasWorkflows {

// track global progress
p.InitProgressbar(r.inputCount, templateCount, totalRequests)
p.StartStdCapture()
if p != nil {
p.InitProgressbar(r.inputCount, templateCount, totalRequests)
p.StartStdCapture()
}

for _, match := range allTemplates {
wgtemplates.Add(1)
Expand All @@ -364,11 +368,14 @@ func (r *Runner) RunEnumeration() {
}

wgtemplates.Wait()
p.Wait()

p.StopStdCapture()
p.ShowStdErr()
p.ShowStdOut()
if p != nil {
p.Wait()

p.StopStdCapture()
p.ShowStdErr()
p.ShowStdOut()
}
}

if !results.Get() {
Expand Down Expand Up @@ -434,7 +441,9 @@ func (r *Runner) processTemplateWithList(p *progress.Progress, template *templat
})
}
if err != nil {
p.Drop(request.(*requests.BulkHTTPRequest).GetRequestCount())
if p != nil {
p.Drop(request.(*requests.BulkHTTPRequest).GetRequestCount())
}
gologger.Warningf("Could not create http client: %s\n", err)
return false
}
Expand Down
16 changes: 11 additions & 5 deletions v2/pkg/executer/executer_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package executer
import (
"bufio"
"fmt"
"github.com/logrusorgru/aurora"
"github.com/projectdiscovery/nuclei/v2/internal/progress"
"os"
"regexp"
"sync"

"github.com/logrusorgru/aurora"
"github.com/pkg/errors"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/internal/progress"
"github.com/projectdiscovery/nuclei/v2/pkg/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/requests"
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
Expand Down Expand Up @@ -89,7 +89,9 @@ func (e *DNSExecuter) ExecuteDNS(p *progress.Progress, URL string) (result Resul
compiledRequest, err := e.dnsRequest.MakeDNSRequest(domain)
if err != nil {
result.Error = errors.Wrap(err, "could not make dns request")
p.Drop(1)
if p != nil {
p.Drop(1)
}
return
}

Expand All @@ -102,11 +104,15 @@ func (e *DNSExecuter) ExecuteDNS(p *progress.Progress, URL string) (result Resul
resp, err := e.dnsClient.Do(compiledRequest)
if err != nil {
result.Error = errors.Wrap(err, "could not send dns request")
p.Drop(1)
if p != nil {
p.Drop(1)
}
return
}

p.Update()
if p != nil {
p.Update()
}

gologger.Verbosef("Sent DNS request to %s\n", "dns-request", URL)

Expand Down
8 changes: 6 additions & 2 deletions v2/pkg/executer/executer_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@ func (e *HTTPExecuter) ExecuteHTTP(p *progress.Progress, URL string) (result Res
err = e.handleHTTP(p, URL, httpRequest, dynamicvalues, &result)
if err != nil {
result.Error = errors.Wrap(err, "could not handle http request")
p.Drop(remaining)
if p != nil {
p.Drop(remaining)
}
return
}

e.bulkHttpRequest.Increment(URL)
p.Update()
if p != nil {
p.Update()
}
remaining--
}

Expand Down
12 changes: 9 additions & 3 deletions v2/pkg/workflows/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func (n *NucleiVar) Call(args ...tengo.Object) (ret tengo.Object, err error) {
for _, template := range n.Templates {
p := template.Progress
if template.HTTPOptions != nil {
p.AddToTotal(template.HTTPOptions.Template.GetHTTPRequestCount())
if p != nil {
p.AddToTotal(template.HTTPOptions.Template.GetHTTPRequestCount())
}
for _, request := range template.HTTPOptions.Template.BulkRequestsHTTP {
// apply externally supplied payloads if any
request.Headers = generators.MergeMapsWithStrings(request.Headers, headers)
Expand All @@ -66,7 +68,9 @@ func (n *NucleiVar) Call(args ...tengo.Object) (ret tengo.Object, err error) {
template.HTTPOptions.BulkHttpRequest = request
httpExecuter, err := executer.NewHTTPExecuter(template.HTTPOptions)
if err != nil {
p.Drop(request.GetRequestCount())
if p != nil {
p.Drop(request.GetRequestCount())
}
gologger.Warningf("Could not compile request for template '%s': %s\n", template.HTTPOptions.Template.ID, err)
continue
}
Expand All @@ -84,7 +88,9 @@ func (n *NucleiVar) Call(args ...tengo.Object) (ret tengo.Object, err error) {
}

if template.DNSOptions != nil {
p.AddToTotal(template.DNSOptions.Template.GetDNSRequestCount())
if p != nil {
p.AddToTotal(template.DNSOptions.Template.GetDNSRequestCount())
}
for _, request := range template.DNSOptions.Template.RequestsDNS {
template.DNSOptions.DNSRequest = request
dnsExecuter := executer.NewDNSExecuter(template.DNSOptions)
Expand Down

0 comments on commit 7d22f6c

Please sign in to comment.