Moved to an enum for TemplateType in protocols

This commit is contained in:
Ice3man543 2021-11-03 19:53:45 +05:30
parent 390ca8b3c6
commit 645ae30a47
13 changed files with 94 additions and 46 deletions

View File

@ -32,7 +32,7 @@ type Request struct {
// - value: "\"{{FQDN}}\""
Name string `yaml:"name,omitempty" jsonschema:"title=hostname to make dns request for,description=Name is the Hostname to make DNS request for"`
// description: |
// Type is the type of DNS request to make.
// RequestType is the type of DNS request to make.
// values:
// - "A"
// - "NS"
@ -43,7 +43,7 @@ type Request struct {
// - "MX"
// - "TXT"
// - "AAAA"
Type string `yaml:"type,omitempty" jsonschema:"title=type of dns request to make,description=Type is the type of DNS request to make,enum=A,enum=NS,enum=DS,enum=CNAME,enum=SOA,enum=PTR,enum=MX,enum=TXT,enum=AAAA"`
RequestType string `yaml:"type,omitempty" jsonschema:"title=type of dns request to make,description=Type is the type of DNS request to make,enum=A,enum=NS,enum=DS,enum=CNAME,enum=SOA,enum=PTR,enum=MX,enum=TXT,enum=AAAA"`
// description: |
// Class is the class of the DNS request.
//
@ -111,7 +111,7 @@ func (request *Request) Compile(options *protocols.ExecuterOptions) error {
}
request.class = classToInt(request.Class)
request.options = options
request.question = questionTypeToInt(request.Type)
request.question = questionTypeToInt(request.RequestType)
return nil
}

View File

@ -27,12 +27,12 @@ func TestDNSCompileMake(t *testing.T) {
testutils.Init(options)
const templateID = "testing-dns"
request := &Request{
Type: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
RequestType: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
}
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
ID: templateID,

View File

@ -23,12 +23,12 @@ func TestResponseToDSLMap(t *testing.T) {
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
Type: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
RequestType: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
}
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
ID: templateID,
@ -55,12 +55,12 @@ func TestDNSOperatorMatch(t *testing.T) {
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
Type: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
RequestType: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
}
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
ID: templateID,
@ -166,12 +166,12 @@ func TestDNSOperatorExtract(t *testing.T) {
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
Type: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
RequestType: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
}
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
ID: templateID,
@ -223,12 +223,12 @@ func TestDNSMakeResult(t *testing.T) {
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
Type: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
RequestType: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
Operators: operators.Operators{
Matchers: []*matchers.Matcher{{
Name: "test",

View File

@ -12,10 +12,16 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/eventcreator"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/responsehighlighter"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
)
var _ protocols.Request = &Request{}
// Type returns the type of the protocol request
func (request *Request) Type() templateTypes.ProtocolType {
return templateTypes.DNSProtocol
}
// ExecuteWithResults executes the protocol requests and returns results instead of writing them.
func (request *Request) ExecuteWithResults(input string, metadata /*TODO review unused parameter*/, previous output.InternalEvent, callback protocols.OutputEventCallback) error {
// Parse the URL and return domain if URL.

View File

@ -20,12 +20,12 @@ func TestDNSExecuteWithResults(t *testing.T) {
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
Type: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
RequestType: "A",
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Name: "{{FQDN}}",
Operators: operators.Operators{
Matchers: []*matchers.Matcher{{
Name: "test",

View File

@ -15,10 +15,16 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/eventcreator"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/responsehighlighter"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/tostring"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
)
var _ protocols.Request = &Request{}
// Type returns the type of the protocol request
func (request *Request) Type() templateTypes.ProtocolType {
return templateTypes.FileProtocol
}
// ExecuteWithResults executes the protocol requests and returns results instead of writing them.
func (request *Request) ExecuteWithResults(input string, metadata /*TODO review unused parameter*/, previous output.InternalEvent, callback protocols.OutputEventCallback) error {
wg := sizedwaitgroup.New(request.options.Options.BulkSize)

View File

@ -12,10 +12,16 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/eventcreator"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/responsehighlighter"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
)
var _ protocols.Request = &Request{}
// Type returns the type of the protocol request
func (request *Request) Type() templateTypes.ProtocolType {
return templateTypes.HeadlessProtocol
}
// ExecuteWithResults executes the protocol requests and returns results instead of writing them.
func (request *Request) ExecuteWithResults(inputURL string, metadata, previous output.InternalEvent /*TODO review unused parameter*/, callback protocols.OutputEventCallback) error {
instance, err := request.options.Browser.NewInstance()

View File

@ -28,12 +28,18 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/interactsh"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/tostring"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/http/httpclientpool"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
"github.com/projectdiscovery/rawhttp"
"github.com/projectdiscovery/stringsutil"
)
const defaultMaxWorkers = 150
// Type returns the type of the protocol request
func (request *Request) Type() templateTypes.ProtocolType {
return templateTypes.HTTPProtocol
}
// executeRaceRequest executes race condition request for a URL
func (request *Request) executeRaceRequest(reqURL string, previous output.InternalEvent, callback protocols.OutputEventCallback) error {
var generatedRequests []*generatedRequest

View File

@ -21,10 +21,16 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/responsehighlighter"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/interactsh"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/replacer"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
)
var _ protocols.Request = &Request{}
// Type returns the type of the protocol request
func (request *Request) Type() templateTypes.ProtocolType {
return templateTypes.NetworkProtocol
}
// ExecuteWithResults executes the protocol requests and returns results instead of writing them.
func (request *Request) ExecuteWithResults(input string, metadata /*TODO review unused parameter*/, previous output.InternalEvent, callback protocols.OutputEventCallback) error {
var address string

View File

@ -15,12 +15,18 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/eventcreator"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/tostring"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
)
var _ protocols.Request = &Request{}
const maxSize = 5 * 1024 * 1024
// Type returns the type of the protocol request
func (request *Request) Type() templateTypes.ProtocolType {
return templateTypes.HTTPProtocol
}
// ExecuteWithResults executes the protocol requests and returns results instead of writing them.
func (request *Request) ExecuteWithResults(input string, metadata /*TODO review unused parameter*/, previous output.InternalEvent, callback protocols.OutputEventCallback) error {
wg := sizedwaitgroup.New(request.options.Options.BulkSize)

View File

@ -21,6 +21,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/eventcreator"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/responsehighlighter"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/network/networkclientpool"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
)
@ -163,12 +164,17 @@ func (request *Request) GetCompiledOperators() []*operators.Operators {
return []*operators.Operators{request.CompiledOperators}
}
// Type returns the type of the protocol request
func (request *Request) Type() templateTypes.ProtocolType {
return templateTypes.SSLProtocol
}
func (request *Request) MakeResultEventItem(wrapped *output.InternalWrappedEvent) *output.ResultEvent {
data := &output.ResultEvent{
TemplateID: types.ToString(request.options.TemplateID),
TemplatePath: types.ToString(request.options.TemplatePath),
Info: request.options.TemplateInfo,
Type: "ssl",
Type: request.Type().String(),
Host: types.ToString(wrapped.InternalEvent["host"]),
Matched: types.ToString(wrapped.InternalEvent["host"]),
Metadata: wrapped.OperatorsResult.PayloadValues,

View File

@ -25,6 +25,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/eventcreator"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/responsehighlighter"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/network/networkclientpool"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
)
@ -355,7 +356,7 @@ func (request *Request) MakeResultEventItem(wrapped *output.InternalWrappedEvent
TemplateID: types.ToString(request.options.TemplateID),
TemplatePath: types.ToString(request.options.TemplatePath),
Info: request.options.TemplateInfo,
Type: "websocket",
Type: request.Type().String(),
Host: types.ToString(wrapped.InternalEvent["host"]),
Matched: types.ToString(wrapped.InternalEvent["host"]),
Metadata: wrapped.OperatorsResult.PayloadValues,
@ -367,3 +368,8 @@ func (request *Request) MakeResultEventItem(wrapped *output.InternalWrappedEvent
}
return data
}
// Type returns the type of the protocol request
func (request *Request) Type() templateTypes.ProtocolType {
return templateTypes.WebsocketProtocol
}

View File

@ -37,11 +37,11 @@ var (
_ = exampleNormalHTTPRequest
exampleNormalDNSRequest = &dns.Request{
Name: "{{FQDN}}",
Type: "CNAME",
Class: "inet",
Retries: 2,
Recursion: true,
Name: "{{FQDN}}",
RequestType: "CNAME",
Class: "inet",
Retries: 2,
Recursion: true,
Operators: operators.Operators{
Extractors: []*extractors.Extractor{
{Type: "regex", Regex: []string{"ec2-[-\\d]+\\.compute[-\\d]*\\.amazonaws\\.com", "ec2-[-\\d]+\\.[\\w\\d\\-]+\\.compute[-\\d]*\\.amazonaws\\.com"}},