Do autocalibration for full path (#22)
* Do autocalibration for full path * Linter fixes
This commit is contained in:
parent
21a19a1f3d
commit
1db80d49fc
@ -55,14 +55,18 @@ func (j *Job) calibrationRequest(inputs map[string][]byte) (Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//CalibrateForHost runs autocalibration for a specific host
|
//CalibrateForHost runs autocalibration for a specific host
|
||||||
func (j *Job) CalibrateForHost(host string, input map[string][]byte) error {
|
func (j *Job) CalibrateForHost(host string, baseinput map[string][]byte) error {
|
||||||
if j.Config.MatcherManager.CalibratedForDomain(host) {
|
if j.Config.MatcherManager.CalibratedForDomain(host) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if input[j.Config.AutoCalibrationKeyword] == nil {
|
if baseinput[j.Config.AutoCalibrationKeyword] == nil {
|
||||||
return fmt.Errorf("Autocalibration keyword \"%s\" not found in the request.", j.Config.AutoCalibrationKeyword)
|
return fmt.Errorf("Autocalibration keyword \"%s\" not found in the request.", j.Config.AutoCalibrationKeyword)
|
||||||
}
|
}
|
||||||
cStrings := j.autoCalibrationStrings()
|
cStrings := j.autoCalibrationStrings()
|
||||||
|
input := make(map[string][]byte)
|
||||||
|
for k, v := range baseinput {
|
||||||
|
input[k] = v
|
||||||
|
}
|
||||||
for _, v := range cStrings {
|
for _, v := range cStrings {
|
||||||
responses := make([]Response, 0)
|
responses := make([]Response, 0)
|
||||||
for _, cs := range v {
|
for _, cs := range v {
|
||||||
@ -136,14 +140,14 @@ func (j *Job) calibrateFilters(responses []Response, perHost bool) error {
|
|||||||
if sizeMatch {
|
if sizeMatch {
|
||||||
if perHost {
|
if perHost {
|
||||||
// Check if already filtered
|
// Check if already filtered
|
||||||
for _, f := range j.Config.MatcherManager.FiltersForDomain(responses[0].Request.Host) {
|
for _, f := range j.Config.MatcherManager.FiltersForDomain(HostURLFromRequest(*responses[0].Request)) {
|
||||||
match, _ := f.Filter(&responses[0])
|
match, _ := f.Filter(&responses[0])
|
||||||
if match {
|
if match {
|
||||||
// Already filtered
|
// Already filtered
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = j.Config.MatcherManager.AddPerDomainFilter(responses[0].Request.Host, "size", strconv.FormatInt(baselineSize, 10))
|
_ = j.Config.MatcherManager.AddPerDomainFilter(HostURLFromRequest(*responses[0].Request), "size", strconv.FormatInt(baselineSize, 10))
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
// Check if already filtered
|
// Check if already filtered
|
||||||
@ -170,14 +174,14 @@ func (j *Job) calibrateFilters(responses []Response, perHost bool) error {
|
|||||||
if wordsMatch {
|
if wordsMatch {
|
||||||
if perHost {
|
if perHost {
|
||||||
// Check if already filtered
|
// Check if already filtered
|
||||||
for _, f := range j.Config.MatcherManager.FiltersForDomain(responses[0].Request.Host) {
|
for _, f := range j.Config.MatcherManager.FiltersForDomain(HostURLFromRequest(*responses[0].Request)) {
|
||||||
match, _ := f.Filter(&responses[0])
|
match, _ := f.Filter(&responses[0])
|
||||||
if match {
|
if match {
|
||||||
// Already filtered
|
// Already filtered
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = j.Config.MatcherManager.AddPerDomainFilter(responses[0].Request.Host, "word", strconv.FormatInt(baselineWords, 10))
|
_ = j.Config.MatcherManager.AddPerDomainFilter(HostURLFromRequest(*responses[0].Request), "word", strconv.FormatInt(baselineWords, 10))
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
// Check if already filtered
|
// Check if already filtered
|
||||||
@ -204,14 +208,14 @@ func (j *Job) calibrateFilters(responses []Response, perHost bool) error {
|
|||||||
if linesMatch {
|
if linesMatch {
|
||||||
if perHost {
|
if perHost {
|
||||||
// Check if already filtered
|
// Check if already filtered
|
||||||
for _, f := range j.Config.MatcherManager.FiltersForDomain(responses[0].Request.Host) {
|
for _, f := range j.Config.MatcherManager.FiltersForDomain(HostURLFromRequest(*responses[0].Request)) {
|
||||||
match, _ := f.Filter(&responses[0])
|
match, _ := f.Filter(&responses[0])
|
||||||
if match {
|
if match {
|
||||||
// Already filtered
|
// Already filtered
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = j.Config.MatcherManager.AddPerDomainFilter(responses[0].Request.Host, "line", strconv.FormatInt(baselineLines, 10))
|
_ = j.Config.MatcherManager.AddPerDomainFilter(HostURLFromRequest(*responses[0].Request), "line", strconv.FormatInt(baselineLines, 10))
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
// Check if already filtered
|
// Check if already filtered
|
||||||
|
|||||||
@ -329,7 +329,7 @@ func (j *Job) isMatch(resp Response) bool {
|
|||||||
var matchers map[string]FilterProvider
|
var matchers map[string]FilterProvider
|
||||||
var filters map[string]FilterProvider
|
var filters map[string]FilterProvider
|
||||||
if j.Config.AutoCalibrationPerHost {
|
if j.Config.AutoCalibrationPerHost {
|
||||||
filters = j.Config.MatcherManager.FiltersForDomain(resp.Request.Host)
|
filters = j.Config.MatcherManager.FiltersForDomain(HostURLFromRequest(*resp.Request))
|
||||||
} else {
|
} else {
|
||||||
filters = j.Config.MatcherManager.GetFilters()
|
filters = j.Config.MatcherManager.GetFilters()
|
||||||
}
|
}
|
||||||
@ -415,7 +415,7 @@ func (j *Job) runTask(input map[string][]byte, position int, retried bool) {
|
|||||||
j.pauseWg.Wait()
|
j.pauseWg.Wait()
|
||||||
|
|
||||||
// Handle autocalibration, must be done after the actual request to ensure sane value in req.Host
|
// Handle autocalibration, must be done after the actual request to ensure sane value in req.Host
|
||||||
_ = j.CalibrateIfNeeded(req.Host, input)
|
_ = j.CalibrateIfNeeded(HostURLFromRequest(req), input)
|
||||||
|
|
||||||
if j.isMatch(resp) {
|
if j.isMatch(resp) {
|
||||||
// Re-send request through replay-proxy if needed
|
// Re-send request through replay-proxy if needed
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package ffuf
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -66,6 +67,15 @@ func RequestContainsKeyword(req Request, kw string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//HostURLFromRequest gets a host + path without the filename or last part of the URL path
|
||||||
|
func HostURLFromRequest(req Request) string {
|
||||||
|
u, _ := url.Parse(req.Url)
|
||||||
|
u.Host = req.Host
|
||||||
|
pathparts := strings.Split(u.Path, "/")
|
||||||
|
trimpath := strings.TrimSpace(strings.Join(pathparts[:len(pathparts)-1], "/"))
|
||||||
|
return u.Host + trimpath
|
||||||
|
}
|
||||||
|
|
||||||
//Version returns the ffuf version string
|
//Version returns the ffuf version string
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return fmt.Sprintf("%s%s", VERSION, VERSION_APPENDIX)
|
return fmt.Sprintf("%s%s", VERSION, VERSION_APPENDIX)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user