Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default fields for DNS requests #1284

Merged
merged 4 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions v2/pkg/protocols/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type Request struct {

// description: |
// Recursion determines if resolver should recurse all records to get fresh results.
Recursion bool `yaml:"recursion,omitempty" jsonschema:"title=recurse all servers,description=Recursion determines if resolver should recurse all records to get fresh results"`
Recursion *bool `yaml:"recursion,omitempty" jsonschema:"title=recurse all servers,description=Recursion determines if resolver should recurse all records to get fresh results"`
// Resolvers to use for the dns requests
Resolvers []string `yaml:"resolvers,omitempty" jsonschema:"title=Resolvers,description=Define resolvers to use within the template"`
}
Expand All @@ -99,6 +99,13 @@ func (request *Request) GetID() string {

// Compile compiles the protocol request for further execution.
func (request *Request) Compile(options *protocols.ExecuterOptions) error {
if request.Retries == 0 {
request.Retries = 3
}
if request.Recursion == nil {
recursion := true
request.Recursion = &recursion
}
dnsClientOptions := &dnsclientpool.Configuration{
Retries: request.Retries,
}
Expand Down Expand Up @@ -162,7 +169,7 @@ func (request *Request) Make(domain string) (*dns.Msg, error) {
// Build a request on the specified URL
req := new(dns.Msg)
req.Id = dns.Id()
req.RecursionDesired = request.Recursion
req.RecursionDesired = *request.Recursion

var q dns.Question

Expand Down
3 changes: 2 additions & 1 deletion v2/pkg/protocols/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ func TestGenerateDNSVariables(t *testing.T) {
func TestDNSCompileMake(t *testing.T) {
options := testutils.DefaultOptions

recursion := false
testutils.Init(options)
const templateID = "testing-dns"
request := &Request{
RequestType: DNSRequestTypeHolder{DNSRequestType: A},
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Recursion: &recursion,
Name: "{{FQDN}}",
}
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
Expand Down
12 changes: 8 additions & 4 deletions v2/pkg/protocols/dns/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
func TestResponseToDSLMap(t *testing.T) {
options := testutils.DefaultOptions

recursion := false
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
RequestType: DNSRequestTypeHolder{DNSRequestType: A},
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Recursion: &recursion,
Name: "{{FQDN}}",
}
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
Expand All @@ -52,14 +53,15 @@ func TestResponseToDSLMap(t *testing.T) {
func TestDNSOperatorMatch(t *testing.T) {
options := testutils.DefaultOptions

recursion := false
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
RequestType: DNSRequestTypeHolder{DNSRequestType: A},
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Recursion: &recursion,
Name: "{{FQDN}}",
}
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
Expand Down Expand Up @@ -163,14 +165,15 @@ func TestDNSOperatorMatch(t *testing.T) {
func TestDNSOperatorExtract(t *testing.T) {
options := testutils.DefaultOptions

recursion := false
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
RequestType: DNSRequestTypeHolder{DNSRequestType: A},
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Recursion: &recursion,
Name: "{{FQDN}}",
}
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
Expand Down Expand Up @@ -220,14 +223,15 @@ func TestDNSOperatorExtract(t *testing.T) {
func TestDNSMakeResult(t *testing.T) {
options := testutils.DefaultOptions

recursion := false
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
RequestType: DNSRequestTypeHolder{DNSRequestType: A},
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Recursion: &recursion,
Name: "{{FQDN}}",
Operators: operators.Operators{
Matchers: []*matchers.Matcher{{
Expand Down
3 changes: 2 additions & 1 deletion v2/pkg/protocols/dns/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import (
func TestDNSExecuteWithResults(t *testing.T) {
options := testutils.DefaultOptions

recursion := false
testutils.Init(options)
templateID := "testing-dns"
request := &Request{
RequestType: DNSRequestTypeHolder{DNSRequestType: A},
Class: "INET",
Retries: 5,
ID: templateID,
Recursion: false,
Recursion: &recursion,
Name: "{{FQDN}}",
Operators: operators.Operators{
Matchers: []*matchers.Matcher{{
Expand Down
3 changes: 2 additions & 1 deletion v2/pkg/templates/templates_doc_examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ var (
}
_ = exampleNormalHTTPRequest

recursion = false
exampleNormalDNSRequest = &dns.Request{
Name: "{{FQDN}}",
RequestType: dns.DNSRequestTypeHolder{DNSRequestType: dns.CNAME},
Class: "inet",
Retries: 2,
Recursion: true,
Recursion: &recursion,
Operators: operators.Operators{
Extractors: []*extractors.Extractor{
{Type: extractors.TypeHolder{ExtractorType: extractors.RegexExtractor}, Regex: []string{"ec2-[-\\d]+\\.compute[-\\d]*\\.amazonaws\\.com", "ec2-[-\\d]+\\.[\\w\\d\\-]+\\.compute[-\\d]*\\.amazonaws\\.com"}},
Expand Down