Skip to content

Commit

Permalink
Support for multiple fingerprints in single template projectdiscovery#25
Browse files Browse the repository at this point in the history
  • Loading branch information
kant01ne committed Apr 22, 2020
1 parent 147464b commit 35d1b4b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
50 changes: 27 additions & 23 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,40 +205,44 @@ func (r *Runner) sendRequest(template *templates.Template, URL string, writer *b
}

// Check if the matcher matched
if !matcher.Match(resp, body, headers) {
continue reqLoop
if matcher.Match(resp, body, headers) {
// If there is an extractor, run it.
var extractorResults []string
for _, extractor := range request.Extractors {
part := extractor.GetPart()
if part == extractors.AllPart || part == extractors.HeaderPart && headers == "" {
headers = headersToString(resp.Header)
}
extractorResults = append(extractorResults, extractor.Extract(body, headers)...)
}

// All the matchers matched, print the output on the screen
output := buildOutput(template, req, extractorResults, matcher)
gologger.Silentf("%s", output)

if writer != nil {
r.outputMutex.Lock()
writer.WriteString(output)
r.outputMutex.Unlock()
}
}
}

// If there is an extractor, run it.
var extractorResults []string
for _, extractor := range request.Extractors {
part := extractor.GetPart()
if part == extractors.AllPart || part == extractors.HeaderPart && headers == "" {
headers = headersToString(resp.Header)
}
extractorResults = append(extractorResults, extractor.Extract(body, headers)...)
}

// All the matchers matched, print the output on the screen
output := buildOutput(template, req, extractorResults)
gologger.Silentf("%s", output)

if writer != nil {
r.outputMutex.Lock()
writer.WriteString(output)
r.outputMutex.Unlock()
}
continue reqLoop
}
}
}

// buildOutput builds an output text for writing results
func buildOutput(template *templates.Template, req *retryablehttp.Request, extractorResults []string) string {
func buildOutput(template *templates.Template, req *retryablehttp.Request, extractorResults []string, matcher *matchers.Matcher) string {
builder := &strings.Builder{}
builder.WriteRune('[')
builder.WriteString(template.ID)
if len(matcher.Name) > 0 {
builder.WriteString(":")
builder.WriteString(matcher.Name)
}
builder.WriteString("] ")

// Escape the URL by replacing all % with %%
URL := req.URL.String()
escapedURL := strings.Replace(URL, "%", "%%", -1)
Expand Down
2 changes: 2 additions & 0 deletions pkg/matchers/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Matcher struct {
// Regex are the regex pattern required to be present in the response
Regex []string `yaml:"regex,omitempty"`
// regexCompiled is the compiled variant
// Matcher Name to be displayed in result output.
Name string `yaml:"name,omitempty"`
regexCompiled []*regexp.Regexp

// Condition is the optional condition between two matcher variables
Expand Down
1 change: 0 additions & 1 deletion pkg/templates/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package templates

import (
"os"

"gopkg.in/yaml.v2"
)

Expand Down

0 comments on commit 35d1b4b

Please sign in to comment.