Merge pull request #312 from projectdiscovery/add-group-feature

Added group capturing in backward compatible way
dev
Ice3man 2020-09-16 23:36:08 -07:00 committed by GitHub
commit 57fa83ca35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -54,13 +54,15 @@ func (e *Extractor) ExtractDNS(msg *dns.Msg) map[string]struct{} {
func (e *Extractor) extractRegex(corpus string) map[string]struct{} {
results := make(map[string]struct{})
groupPlusOne := e.RegexGroup + 1
for _, regex := range e.regexCompiled {
matches := regex.FindAllString(corpus, -1)
matches := regex.FindAllStringSubmatch(corpus, -1)
for _, match := range matches {
results[match] = struct{}{}
if len(match) >= groupPlusOne {
results[match[e.RegexGroup]] = struct{}{}
}
}
}
return results
}

View File

@ -13,6 +13,8 @@ type Extractor struct {
// Regex are the regex pattern required to be present in the response
Regex []string `yaml:"regex"`
// RegexGroup specifies a group to extract from the regex
RegexGroup int `yaml:"group"`
// regexCompiled is the compiled variant
regexCompiled []*regexp.Regexp
@ -25,7 +27,6 @@ type Extractor struct {
Part string `yaml:"part,omitempty"`
// part is the part of the request to match
part Part
// Internal defines if this is used internally
Internal bool `yaml:"internal,omitempty"`
}