43 lines
1006 B
Go
Raw Normal View History

2020-04-06 00:05:01 +05:30
package extractors
2020-12-24 12:13:18 +05:30
import "github.com/projectdiscovery/nuclei/v2/pkg/types"
2020-07-16 10:32:00 +02:00
2020-12-24 20:47:41 +05:30
// ExtractRegex extracts text from a corpus and returns it
func (e *Extractor) ExtractRegex(corpus string) map[string]struct{} {
2020-04-27 23:34:08 +05:30
results := make(map[string]struct{})
groupPlusOne := e.RegexGroup + 1
for _, regex := range e.regexCompiled {
matches := regex.FindAllStringSubmatch(corpus, -1)
2020-12-24 12:13:18 +05:30
2020-04-27 23:34:08 +05:30
for _, match := range matches {
2020-12-24 12:13:18 +05:30
if len(match) < groupPlusOne {
continue
}
2020-12-24 12:13:18 +05:30
matchString := match[e.RegexGroup]
2020-12-24 12:13:18 +05:30
if _, ok := results[matchString]; !ok {
results[matchString] = struct{}{}
}
2020-07-16 10:32:00 +02:00
}
}
return results
}
2020-12-24 20:47:41 +05:30
// ExtractKval extracts key value pairs from a data map
func (e *Extractor) ExtractKval(data map[string]interface{}) map[string]struct{} {
2020-07-16 10:32:00 +02:00
results := make(map[string]struct{})
2020-07-16 12:58:56 +02:00
for _, k := range e.KVal {
2020-12-24 12:13:18 +05:30
item, ok := data[k]
if !ok {
continue
}
itemString := types.ToString(item)
if _, ok := results[itemString]; !ok {
results[itemString] = struct{}{}
2020-07-16 10:32:00 +02:00
}
}
return results
}