2020-12-21 14:31:32 +05:30
|
|
|
package protocols
|
|
|
|
|
|
2020-12-23 20:46:42 +05:30
|
|
|
import (
|
2021-09-07 17:31:46 +03:00
|
|
|
"go.uber.org/ratelimit"
|
|
|
|
|
|
2021-02-26 13:13:11 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/catalog"
|
2021-07-12 17:20:01 +03:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
2021-02-06 00:36:43 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
|
2020-12-24 20:47:41 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
|
2020-12-23 20:46:42 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
2021-03-09 17:19:03 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/progress"
|
2020-12-29 01:30:07 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/projectfile"
|
2021-08-16 21:24:37 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/hosterrorscache"
|
2021-04-16 16:56:41 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/interactsh"
|
2021-02-21 16:31:34 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/headless/engine"
|
2021-03-22 14:03:05 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/reporting"
|
2020-12-23 20:46:42 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
|
|
|
|
)
|
2020-12-23 16:16:16 +05:30
|
|
|
|
2020-12-25 20:33:52 +05:30
|
|
|
// Executer is an interface implemented any protocol based request executer.
|
2020-12-23 20:46:42 +05:30
|
|
|
type Executer interface {
|
2020-12-25 20:33:52 +05:30
|
|
|
// Compile compiles the execution generators preparing any requests possible.
|
2020-12-25 20:39:09 +05:30
|
|
|
Compile() error
|
2020-12-22 03:54:55 +05:30
|
|
|
// Requests returns the total number of requests the rule will perform
|
2020-12-29 15:38:14 +05:30
|
|
|
Requests() int
|
2020-12-25 20:33:52 +05:30
|
|
|
// Execute executes the protocol group and returns true or false if results were found.
|
2020-12-23 20:46:42 +05:30
|
|
|
Execute(input string) (bool, error)
|
|
|
|
|
// ExecuteWithResults executes the protocol requests and returns results instead of writing them.
|
2021-01-01 19:36:21 +05:30
|
|
|
ExecuteWithResults(input string, callback OutputEventCallback) error
|
2020-12-21 14:31:32 +05:30
|
|
|
}
|
2020-12-23 16:16:16 +05:30
|
|
|
|
2020-12-23 20:46:42 +05:30
|
|
|
// ExecuterOptions contains the configuration options for executer clients
|
|
|
|
|
type ExecuterOptions struct {
|
2020-12-25 02:24:55 +05:30
|
|
|
// TemplateID is the ID of the template for the request
|
|
|
|
|
TemplateID string
|
2020-12-29 12:08:46 +05:30
|
|
|
// TemplatePath is the path of the template for the request
|
|
|
|
|
TemplatePath string
|
2020-12-25 02:24:55 +05:30
|
|
|
// TemplateInfo contains information block of the template request
|
2021-07-12 17:20:01 +03:00
|
|
|
TemplateInfo model.Info
|
2020-12-23 20:46:42 +05:30
|
|
|
// Output is a writer interface for writing output events from executer.
|
|
|
|
|
Output output.Writer
|
2020-12-24 01:42:04 +05:30
|
|
|
// Options contains configuration options for the executer.
|
2020-12-23 20:46:42 +05:30
|
|
|
Options *types.Options
|
2021-02-02 12:10:47 +05:30
|
|
|
// IssuesClient is a client for nuclei issue tracker reporting
|
2021-03-22 14:03:05 +05:30
|
|
|
IssuesClient *reporting.Client
|
2020-12-25 20:33:52 +05:30
|
|
|
// Progress is a progress client for scan reporting
|
2021-03-09 17:19:03 +05:30
|
|
|
Progress progress.Progress
|
2020-12-24 01:42:04 +05:30
|
|
|
// RateLimiter is a rate-limiter for limiting sent number of requests.
|
|
|
|
|
RateLimiter ratelimit.Limiter
|
2021-02-26 13:13:11 +05:30
|
|
|
// Catalog is a template catalog implementation for nuclei
|
|
|
|
|
Catalog *catalog.Catalog
|
2020-12-29 01:30:07 +05:30
|
|
|
// ProjectFile is the project file for nuclei
|
|
|
|
|
ProjectFile *projectfile.ProjectFile
|
2021-02-21 16:31:34 +05:30
|
|
|
// Browser is a browser engine for running headless templates
|
|
|
|
|
Browser *engine.Browser
|
2021-04-16 16:56:41 +05:30
|
|
|
// Interactsh is a client for interactsh oob polling server
|
|
|
|
|
Interactsh *interactsh.Client
|
2021-08-16 21:24:37 +05:30
|
|
|
// HostErrorsCache is an optional cache for handling host errors
|
|
|
|
|
HostErrorsCache *hosterrorscache.Cache
|
2021-02-06 00:36:43 +05:30
|
|
|
|
|
|
|
|
Operators []*operators.Operators // only used by offlinehttp module
|
2021-07-15 13:41:41 +03:00
|
|
|
|
|
|
|
|
WorkflowLoader model.WorkflowLoader
|
2020-12-23 16:16:16 +05:30
|
|
|
}
|
2020-12-25 20:33:52 +05:30
|
|
|
|
2021-10-27 16:50:36 +05:30
|
|
|
// Copy returns a copy of the executeroptions structure
|
|
|
|
|
func (e ExecuterOptions) Copy() ExecuterOptions {
|
|
|
|
|
copy := e
|
|
|
|
|
return copy
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-25 20:33:52 +05:30
|
|
|
// Request is an interface implemented any protocol based request generator.
|
|
|
|
|
type Request interface {
|
|
|
|
|
// Compile compiles the request generators preparing any requests possible.
|
2020-12-25 20:39:09 +05:30
|
|
|
Compile(options *ExecuterOptions) error
|
2020-12-25 20:33:52 +05:30
|
|
|
// Requests returns the total number of requests the rule will perform
|
2020-12-29 15:38:14 +05:30
|
|
|
Requests() int
|
2021-01-16 14:10:24 +05:30
|
|
|
// GetID returns the ID for the request if any. IDs are used for multi-request
|
|
|
|
|
// condition matching. So, two requests can be sent and their match can
|
|
|
|
|
// be evaluated from the third request by using the IDs for both requests.
|
|
|
|
|
GetID() string
|
2021-09-29 19:43:46 +03:00
|
|
|
// Match performs matching operation for a matcher on model and returns:
|
|
|
|
|
// true and a list of matched snippets if the matcher type is supports it
|
|
|
|
|
// otherwise false and an empty string slice
|
|
|
|
|
Match(data map[string]interface{}, matcher *matchers.Matcher) (bool, []string)
|
2021-09-07 17:31:46 +03:00
|
|
|
// Extract performs extracting operation for an extractor on model and returns true or false.
|
2020-12-25 20:33:52 +05:30
|
|
|
Extract(data map[string]interface{}, matcher *extractors.Extractor) map[string]struct{}
|
|
|
|
|
// ExecuteWithResults executes the protocol requests and returns results instead of writing them.
|
2021-01-16 14:10:24 +05:30
|
|
|
ExecuteWithResults(input string, dynamicValues, previous output.InternalEvent, callback OutputEventCallback) error
|
2021-10-06 21:53:03 +03:00
|
|
|
// MakeResultEventItem creates a result event from internal wrapped event. Intended to be used by MakeResultEventItem internally
|
|
|
|
|
MakeResultEventItem(wrapped *output.InternalWrappedEvent) *output.ResultEvent
|
|
|
|
|
// MakeResultEvent creates a flat list of result events from an internal wrapped event, based on successful matchers and extracted data
|
2021-10-01 16:52:38 +03:00
|
|
|
MakeResultEvent(wrapped *output.InternalWrappedEvent) []*output.ResultEvent
|
|
|
|
|
// GetCompiledOperators returns a list of the compiled operators
|
|
|
|
|
GetCompiledOperators() []*operators.Operators
|
2020-12-25 20:33:52 +05:30
|
|
|
}
|
2021-01-01 19:36:21 +05:30
|
|
|
|
|
|
|
|
// OutputEventCallback is a callback event for any results found during scanning.
|
|
|
|
|
type OutputEventCallback func(result *output.InternalWrappedEvent)
|
2021-10-06 21:53:03 +03:00
|
|
|
|
|
|
|
|
func MakeDefaultResultEvent(request Request, wrapped *output.InternalWrappedEvent) []*output.ResultEvent {
|
|
|
|
|
if len(wrapped.OperatorsResult.DynamicValues) > 0 && !wrapped.OperatorsResult.Matched {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
results := make([]*output.ResultEvent, 0, len(wrapped.OperatorsResult.Matches)+1)
|
|
|
|
|
|
|
|
|
|
// If we have multiple matchers with names, write each of them separately.
|
|
|
|
|
if len(wrapped.OperatorsResult.Matches) > 0 {
|
|
|
|
|
for matcherNames := range wrapped.OperatorsResult.Matches {
|
|
|
|
|
data := request.MakeResultEventItem(wrapped)
|
|
|
|
|
data.MatcherName = matcherNames
|
|
|
|
|
results = append(results, data)
|
|
|
|
|
}
|
|
|
|
|
} else if len(wrapped.OperatorsResult.Extracts) > 0 {
|
|
|
|
|
for k, v := range wrapped.OperatorsResult.Extracts {
|
|
|
|
|
data := request.MakeResultEventItem(wrapped)
|
|
|
|
|
data.ExtractorName = k
|
|
|
|
|
data.ExtractedResults = v
|
|
|
|
|
results = append(results, data)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
data := request.MakeResultEventItem(wrapped)
|
|
|
|
|
results = append(results, data)
|
|
|
|
|
}
|
|
|
|
|
return results
|
|
|
|
|
}
|