Skip to content

Commit

Permalink
fuzzing input in result, resolves #76 (#124)
Browse files Browse the repository at this point in the history
* regexp filter had a copy-paste error talking about size filter, fixed

* implement -mr/-fr FUZZ, detecting if fuzzed input is present in response. resolves #76

* quote regexp control characters to obtain exact matches (according to joohoi's comment)

* allow keywords as part of regexp matching/filtering

* updated changelog

Co-authored-by: Joona Hoikkala <joohoi@users.noreply.github.com>
  • Loading branch information
delic and joohoi committed Dec 23, 2019
1 parent 918d5dc commit f5609a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -194,6 +194,7 @@ The only dependency of ffuf is Go 1.11. No dependencies outside of Go standard l
- New
- Changed
- Limit the use of `-e` (extensions) to a single keyword: FUZZ
- Regexp matching and filtering (-mr/-fr) allow using keywords in patterns
- Take 429 responses into account when -sa (stop on all error cases) is used

- v0.12
Expand Down
13 changes: 11 additions & 2 deletions pkg/filter/regex.go
Expand Up @@ -3,6 +3,7 @@ package filter
import (
"fmt"
"regexp"
"strings"

"github.com/ffuf/ffuf/pkg/ffuf"
)
Expand All @@ -15,7 +16,7 @@ type RegexpFilter struct {
func NewRegexpFilter(value string) (ffuf.FilterProvider, error) {
re, err := regexp.Compile(value)
if err != nil {
return &RegexpFilter{}, fmt.Errorf("Size filter or matcher (-fs / -ms): invalid value: %s", value)
return &RegexpFilter{}, fmt.Errorf("Regexp filter or matcher (-fr / -mr): invalid value: %s", value)
}
return &RegexpFilter{Value: re, valueRaw: value}, nil
}
Expand All @@ -29,7 +30,15 @@ func (f *RegexpFilter) Filter(response *ffuf.Response) (bool, error) {
}
matchdata := []byte(matchheaders)
matchdata = append(matchdata, response.Data...)
return f.Value.Match(matchdata), nil
pattern := f.valueRaw
for keyword, inputitem := range response.Request.Input {
pattern = strings.Replace(pattern, keyword, regexp.QuoteMeta(string(inputitem)), -1)
}
matched, err := regexp.Match(pattern, matchdata)
if err != nil {
return false, nil
}
return matched, nil
}

func (f *RegexpFilter) Repr() string {
Expand Down

0 comments on commit f5609a2

Please sign in to comment.