nuclei/v2/pkg/extractors/extractors.go

73 lines
1.9 KiB
Go
Raw Normal View History

2020-04-05 18:35:01 +00:00
package extractors
import "regexp"
// Extractor is used to extract part of response using a regex.
type Extractor struct {
2020-07-10 07:04:38 +00:00
// Name is the extractor's name
Name string `yaml:"name,omitempty"`
2020-07-14 22:47:01 +00:00
// Type is the type of the extractor
Type string `yaml:"type"`
2020-07-14 22:47:01 +00:00
// extractorType is the internal type of the extractor
extractorType ExtractorType
2020-04-05 18:35:01 +00:00
// 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"`
2020-04-05 18:35:01 +00:00
// regexCompiled is the compiled variant
regexCompiled []*regexp.Regexp
2020-04-05 18:35:01 +00:00
2020-07-16 08:32:00 +00:00
// KVal are the kval to be present in the response headers/cookies
KVal []string `yaml:"kval,omitempty"`
2020-04-05 18:35:01 +00:00
// Part is the part of the request to match
//
// By default, matching is performed in request body.
Part string `yaml:"part,omitempty"`
// part is the part of the request to match
part Part
2020-07-25 19:15:28 +00:00
// Internal defines if this is used internally
Internal bool `yaml:"internal,omitempty"`
2020-04-05 18:35:01 +00:00
}
// ExtractorType is the type of the extractor specified
type ExtractorType = int
const (
// RegexExtractor extracts responses with regexes
RegexExtractor ExtractorType = iota + 1
2020-07-14 22:47:01 +00:00
// KValExtractor extracts responses with key:value
KValExtractor
)
// ExtractorTypes is an table for conversion of extractor type from string.
var ExtractorTypes = map[string]ExtractorType{
"regex": RegexExtractor,
2020-07-14 22:47:01 +00:00
"kval": KValExtractor,
}
2020-04-05 18:35:01 +00:00
// Part is the part of the request to match
type Part int
const (
// BodyPart matches body of the response.
BodyPart Part = iota + 1
// HeaderPart matches headers of the response.
HeaderPart
// AllPart matches both response body and headers of the response.
AllPart
)
// PartTypes is an table for conversion of part type from string.
var PartTypes = map[string]Part{
"body": BodyPart,
"header": HeaderPart,
"all": AllPart,
}
// GetPart returns the part of the matcher
func (e *Extractor) GetPart() Part {
return e.part
}