nuclei/v2/pkg/extractors/extract.go

46 lines
1.1 KiB
Go
Raw Normal View History

2020-04-06 00:05:01 +05:30
package extractors
// Extract extracts response from the parts of request using a regex
2020-04-27 23:34:08 +05:30
func (e *Extractor) Extract(body, headers string) map[string]struct{} {
2020-07-15 00:47:01 +02:00
switch e.extractorType {
case RegexExtractor:
if e.part == BodyPart {
return e.extractRegex(body)
} else if e.part == HeaderPart {
return e.extractRegex(headers)
} else {
matches := e.extractRegex(headers)
if len(matches) > 0 {
return matches
}
return e.extractRegex(body)
2020-04-06 00:05:01 +05:30
}
2020-07-15 00:47:01 +02:00
case KValExtractor:
2020-04-06 00:05:01 +05:30
}
2020-07-15 00:47:01 +02:00
return nil
2020-04-06 00:05:01 +05:30
}
2020-04-22 22:45:02 +02:00
// ExtractDNS extracts response from dns message using a regex
2020-04-27 23:34:08 +05:30
func (e *Extractor) ExtractDNS(msg string) map[string]struct{} {
2020-07-15 00:47:01 +02:00
switch e.extractorType {
case RegexExtractor:
return e.extractRegex(msg)
case KValExtractor:
}
return nil
2020-04-22 22:45:02 +02:00
}
2020-04-06 00:05:01 +05:30
// extractRegex extracts text from a corpus and returns it
2020-04-27 23:34:08 +05:30
func (e *Extractor) extractRegex(corpus string) map[string]struct{} {
results := make(map[string]struct{})
for _, regex := range e.regexCompiled {
2020-04-27 23:34:08 +05:30
matches := regex.FindAllString(corpus, -1)
for _, match := range matches {
results[match] = struct{}{}
}
}
return results
2020-04-06 00:05:01 +05:30
}