Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/cmd/integration-test/ssl.go
2070 views
1
package main
2
3
import (
4
"crypto/tls"
5
"net"
6
7
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
8
)
9
10
var sslTestcases = []TestCaseInfo{
11
{Path: "protocols/ssl/basic.yaml", TestCase: &sslBasic{}},
12
{Path: "protocols/ssl/basic-ztls.yaml", TestCase: &sslBasicZtls{}},
13
{Path: "protocols/ssl/custom-cipher.yaml", TestCase: &sslCustomCipher{}},
14
{Path: "protocols/ssl/custom-version.yaml", TestCase: &sslCustomVersion{}},
15
{Path: "protocols/ssl/ssl-with-vars.yaml", TestCase: &sslWithVars{}},
16
{Path: "protocols/ssl/multi-req.yaml", TestCase: &sslMultiReq{}},
17
}
18
19
type sslBasic struct{}
20
21
// Execute executes a test case and returns an error if occurred
22
func (h *sslBasic) Execute(filePath string) error {
23
ts := testutils.NewTCPServer(&tls.Config{}, defaultStaticPort, func(conn net.Conn) {
24
defer func() {
25
_ = conn.Close()
26
}()
27
data := make([]byte, 4)
28
if _, err := conn.Read(data); err != nil {
29
return
30
}
31
})
32
defer ts.Close()
33
34
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
35
if err != nil {
36
return err
37
}
38
39
return expectResultsCount(results, 1)
40
}
41
42
type sslBasicZtls struct{}
43
44
// Execute executes a test case and returns an error if occurred
45
func (h *sslBasicZtls) Execute(filePath string) error {
46
ts := testutils.NewTCPServer(&tls.Config{}, defaultStaticPort, func(conn net.Conn) {
47
defer func() {
48
_ = conn.Close()
49
}()
50
data := make([]byte, 4)
51
if _, err := conn.Read(data); err != nil {
52
return
53
}
54
})
55
defer ts.Close()
56
57
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-ztls")
58
if err != nil {
59
return err
60
}
61
62
return expectResultsCount(results, 1)
63
}
64
65
type sslCustomCipher struct{}
66
67
// Execute executes a test case and returns an error if occurred
68
func (h *sslCustomCipher) Execute(filePath string) error {
69
ts := testutils.NewTCPServer(&tls.Config{CipherSuites: []uint16{tls.TLS_AES_128_GCM_SHA256}}, defaultStaticPort, func(conn net.Conn) {
70
defer func() {
71
_ = conn.Close()
72
}()
73
data := make([]byte, 4)
74
if _, err := conn.Read(data); err != nil {
75
return
76
}
77
})
78
defer ts.Close()
79
80
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
81
if err != nil {
82
return err
83
}
84
85
return expectResultsCount(results, 1)
86
}
87
88
type sslCustomVersion struct{}
89
90
// Execute executes a test case and returns an error if occurred
91
func (h *sslCustomVersion) Execute(filePath string) error {
92
ts := testutils.NewTCPServer(&tls.Config{MinVersion: tls.VersionTLS12, MaxVersion: tls.VersionTLS12}, defaultStaticPort, func(conn net.Conn) {
93
defer func() {
94
_ = conn.Close()
95
}()
96
data := make([]byte, 4)
97
if _, err := conn.Read(data); err != nil {
98
return
99
}
100
})
101
defer ts.Close()
102
103
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
104
if err != nil {
105
return err
106
}
107
108
return expectResultsCount(results, 1)
109
}
110
111
type sslWithVars struct{}
112
113
func (h *sslWithVars) Execute(filePath string) error {
114
ts := testutils.NewTCPServer(&tls.Config{}, defaultStaticPort, func(conn net.Conn) {
115
defer func() {
116
_ = conn.Close()
117
}()
118
data := make([]byte, 4)
119
if _, err := conn.Read(data); err != nil {
120
return
121
}
122
})
123
defer ts.Close()
124
125
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-V", "test=asdasdas")
126
if err != nil {
127
return err
128
}
129
130
return expectResultsCount(results, 1)
131
}
132
133
type sslMultiReq struct{}
134
135
func (h *sslMultiReq) Execute(filePath string) error {
136
//nolint:staticcheck // SSLv3 is intentionally used for testing purposes
137
ts := testutils.NewTCPServer(&tls.Config{
138
MinVersion: tls.VersionSSL30,
139
MaxVersion: tls.VersionTLS11,
140
}, defaultStaticPort, func(conn net.Conn) {
141
defer func() {
142
_ = conn.Close()
143
}()
144
data := make([]byte, 4)
145
if _, err := conn.Read(data); err != nil {
146
return
147
}
148
})
149
defer ts.Close()
150
151
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-V")
152
if err != nil {
153
return err
154
}
155
156
return expectResultsCount(results, 2)
157
}
158
159