Path: blob/dev/pkg/operators/extractors/extractors.go
2070 views
package extractors12import (3"regexp"45"github.com/Knetic/govaluate"6"github.com/itchyny/gojq"7)89// Extractor is used to extract part of response using a regex.10type Extractor struct {11// description: |12// Name of the extractor. Name should be lowercase and must not contain13// spaces or underscores (_).14// examples:15// - value: "\"cookie-extractor\""16Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"title=name of the extractor,description=Name of the extractor"`17// description: |18// Type is the type of the extractor.19Type ExtractorTypeHolder `json:"type" yaml:"type"`20// extractorType is the internal type of the extractor21extractorType ExtractorType2223// description: |24// Regex contains the regular expression patterns to extract from a part.25//26// Go regex engine does not support lookaheads or lookbehinds, so as a result27// they are also not supported in nuclei.28// examples:29// - name: Braintree Access Token Regex30// value: >31// []string{"access_token\\$production\\$[0-9a-z]{16}\\$[0-9a-f]{32}"}32// - name: Wordpress Author Extraction regex33// value: >34// []string{"Author:(?:[A-Za-z0-9 -\\_=\"]+)?<span(?:[A-Za-z0-9 -\\_=\"]+)?>([A-Za-z0-9]+)<\\/span>"}35Regex []string `yaml:"regex,omitempty" json:"regex,omitempty" jsonschema:"title=regex to extract from part,description=Regex to extract from part"`36// description: |37// Group specifies a numbered group to extract from the regex.38// examples:39// - name: Example Regex Group40// value: "1"41RegexGroup int `yaml:"group,omitempty" json:"group,omitempty" jsonschema:"title=group to extract from regex,description=Group to extract from regex"`42// regexCompiled is the compiled variant43regexCompiled []*regexp.Regexp4445// description: |46// kval contains the key-value pairs present in the HTTP response header.47// kval extractor can be used to extract HTTP response header and cookie key-value pairs.48// kval extractor inputs are case-insensitive, and does not support dash (-) in input which can replaced with underscores (_)49// For example, Content-Type should be replaced with content_type50//51// A list of supported parts is available in docs for request types.52// examples:53// - name: Extract Server Header From HTTP Response54// value: >55// []string{"server"}56// - name: Extracting value of PHPSESSID Cookie57// value: >58// []string{"phpsessid"}59// - name: Extracting value of Content-Type Cookie60// value: >61// []string{"content_type"}62KVal []string `yaml:"kval,omitempty" json:"kval,omitempty" jsonschema:"title=kval pairs to extract from response,description=Kval pairs to extract from response"`6364// description: |65// JSON allows using jq-style syntax to extract items from json response66//67// examples:68// - value: >69// []string{".[] | .id"}70// - value: >71// []string{".batters | .batter | .[] | .id"}72JSON []string `yaml:"json,omitempty" json:"json,omitempty" jsonschema:"title=json jq expressions to extract data,description=JSON JQ expressions to evaluate from response part"`73// description: |74// XPath allows using xpath expressions to extract items from html response75//76// examples:77// - value: >78// []string{"/html/body/div/p[2]/a"}79XPath []string `yaml:"xpath,omitempty" json:"xpath,omitempty" jsonschema:"title=html xpath expressions to extract data,description=XPath allows using xpath expressions to extract items from html response"`80// description: |81// Attribute is an optional attribute to extract from response XPath.82//83// examples:84// - value: "\"href\""85Attribute string `yaml:"attribute,omitempty" json:"attribute,omitempty" jsonschema:"title=optional attribute to extract from xpath,description=Optional attribute to extract from response XPath"`8687// jsonCompiled is the compiled variant88jsonCompiled []*gojq.Code8990// description: |91// Extracts using DSL expressions.92DSL []string `yaml:"dsl,omitempty" json:"dsl,omitempty" jsonschema:"title=dsl expressions to extract,description=Optional attribute to extract from response dsl"`93dslCompiled []*govaluate.EvaluableExpression9495// description: |96// Part is the part of the request response to extract data from.97//98// Each protocol exposes a lot of different parts which are well99// documented in docs for each request type.100// examples:101// - value: "\"body\""102// - value: "\"raw\""103Part string `yaml:"part,omitempty" json:"part,omitempty" jsonschema:"title=part of response to extract data from,description=Part of the request response to extract data from"`104// description: |105// Internal, when set to true will allow using the value extracted106// in the next request for some protocols (like HTTP).107Internal bool `yaml:"internal,omitempty" json:"internal,omitempty" jsonschema:"title=mark extracted value for internal variable use,description=Internal when set to true will allow using the value extracted in the next request for some protocols"`108109// description: |110// CaseInsensitive enables case-insensitive extractions. Default is false.111// values:112// - false113// - true114CaseInsensitive bool `yaml:"case-insensitive,omitempty" json:"case-insensitive,omitempty" jsonschema:"title=use case insensitive extract,description=use case insensitive extract"`115}116117118