* 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>
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package filter
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/ffuf/ffuf/pkg/ffuf"
|
|
)
|
|
|
|
type RegexpFilter struct {
|
|
Value *regexp.Regexp
|
|
valueRaw string
|
|
}
|
|
|
|
func NewRegexpFilter(value string) (ffuf.FilterProvider, error) {
|
|
re, err := regexp.Compile(value)
|
|
if err != nil {
|
|
return &RegexpFilter{}, fmt.Errorf("Regexp filter or matcher (-fr / -mr): invalid value: %s", value)
|
|
}
|
|
return &RegexpFilter{Value: re, valueRaw: value}, nil
|
|
}
|
|
|
|
func (f *RegexpFilter) Filter(response *ffuf.Response) (bool, error) {
|
|
matchheaders := ""
|
|
for k, v := range response.Headers {
|
|
for _, iv := range v {
|
|
matchheaders += k + ": " + iv + "\r\n"
|
|
}
|
|
}
|
|
matchdata := []byte(matchheaders)
|
|
matchdata = append(matchdata, response.Data...)
|
|
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 {
|
|
return fmt.Sprintf("Regexp: %s", f.valueRaw)
|
|
}
|