Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/cmd/integration-test/dns.go
2070 views
1
package main
2
3
import (
4
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
5
)
6
7
var dnsTestCases = []TestCaseInfo{
8
{Path: "protocols/dns/a.yaml", TestCase: &dnsBasic{}},
9
{Path: "protocols/dns/aaaa.yaml", TestCase: &dnsBasic{}},
10
{Path: "protocols/dns/cname.yaml", TestCase: &dnsBasic{}},
11
{Path: "protocols/dns/srv.yaml", TestCase: &dnsBasic{}},
12
{Path: "protocols/dns/ns.yaml", TestCase: &dnsBasic{}},
13
{Path: "protocols/dns/txt.yaml", TestCase: &dnsBasic{}},
14
{Path: "protocols/dns/ptr.yaml", TestCase: &dnsPtr{}},
15
{Path: "protocols/dns/caa.yaml", TestCase: &dnsCAA{}},
16
{Path: "protocols/dns/tlsa.yaml", TestCase: &dnsTLSA{}},
17
{Path: "protocols/dns/variables.yaml", TestCase: &dnsVariables{}},
18
{Path: "protocols/dns/payload.yaml", TestCase: &dnsPayload{}},
19
{Path: "protocols/dns/dsl-matcher-variable.yaml", TestCase: &dnsDSLMatcherVariable{}},
20
}
21
22
type dnsBasic struct{}
23
24
// Execute executes a test case and returns an error if occurred
25
func (h *dnsBasic) Execute(filePath string) error {
26
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "one.one.one.one", debug)
27
if err != nil {
28
return err
29
}
30
return expectResultsCount(results, 1)
31
}
32
33
type dnsPtr struct{}
34
35
// Execute executes a test case and returns an error if occurred
36
func (h *dnsPtr) Execute(filePath string) error {
37
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "1.1.1.1", debug)
38
if err != nil {
39
return err
40
}
41
return expectResultsCount(results, 1)
42
}
43
44
type dnsCAA struct{}
45
46
// Execute executes a test case and returns an error if occurred
47
func (h *dnsCAA) Execute(filePath string) error {
48
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "google.com", debug)
49
if err != nil {
50
return err
51
}
52
return expectResultsCount(results, 1)
53
}
54
55
type dnsTLSA struct{}
56
57
// Execute executes a test case and returns an error if occurred
58
func (h *dnsTLSA) Execute(filePath string) error {
59
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "scanme.sh", debug)
60
if err != nil {
61
return err
62
}
63
return expectResultsCount(results, 0)
64
}
65
66
type dnsVariables struct{}
67
68
// Execute executes a test case and returns an error if occurred
69
func (h *dnsVariables) Execute(filePath string) error {
70
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "one.one.one.one", debug)
71
if err != nil {
72
return err
73
}
74
return expectResultsCount(results, 1)
75
}
76
77
type dnsPayload struct{}
78
79
// Execute executes a test case and returns an error if occurred
80
func (h *dnsPayload) Execute(filePath string) error {
81
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "google.com", debug)
82
if err != nil {
83
return err
84
}
85
if err := expectResultsCount(results, 3); err != nil {
86
return err
87
}
88
89
// override payload from CLI
90
results, err = testutils.RunNucleiTemplateAndGetResults(filePath, "google.com", debug, "-var", "subdomain_wordlist=subdomains.txt")
91
if err != nil {
92
return err
93
}
94
return expectResultsCount(results, 4)
95
}
96
97
type dnsDSLMatcherVariable struct{}
98
99
// Execute executes a test case and returns an error if occurred
100
func (h *dnsDSLMatcherVariable) Execute(filePath string) error {
101
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "one.one.one.one", debug)
102
if err != nil {
103
return err
104
}
105
return expectResultsCount(results, 1)
106
}
107
108