|
1 | | -const k8s = require('@kubernetes/client-node'); |
| 1 | +const { startSubsequentSecureCodeBoxScan } = require("./scan-helpers"); |
2 | 2 |
|
3 | | -// configure k8s client |
4 | | -const kc = new k8s.KubeConfig(); |
5 | | -kc.loadFromDefault(); |
6 | | - |
7 | | -const k8sApiCRD = kc.makeApiClient(k8s.CustomObjectsApi); |
8 | | - |
9 | | -async function handle({ |
10 | | - getFindings |
11 | | -}) { |
12 | | - |
| 3 | +async function handle({ scan, getFindings }) { |
13 | 4 | const findings = await getFindings(); |
14 | 5 |
|
15 | 6 | console.log(findings); |
16 | 7 |
|
17 | | - // const sslyzeYaml = k8s.dumpYaml(sslyzeJSONString); |
18 | | - // const sslyzeYaml = k8s.loadYaml(sslyzeScanDefinition); |
19 | | - |
20 | | - console.log(`Found #${findings.length} findings... trying to find possible subsequent security scans.`); |
| 8 | + console.log( |
| 9 | + `Found #${findings.length} findings... trying to find possible subsequent security scans.` |
| 10 | + ); |
21 | 11 |
|
22 | 12 | for (const finding of findings) { |
23 | | - if(finding.category == "Open Port") { |
24 | | - console.log("Found open port finding for service: " + finding.attributes.port); |
25 | | - |
26 | | - if(finding.attributes.state = "open") { |
27 | | - |
28 | | - // search for HTTP ports and start subsequent Nikto Scan |
29 | | - if(finding.attributes.service == "http" ) { |
30 | | - startNiktoScan(finding.attributes.hostname, finding.attributes.port); |
31 | | - } |
32 | | - |
33 | | - // search for HTTPS ports and start subsequent SSLyze Scan |
34 | | - if(finding.attributes.service == "ssl" || finding.attributes.service == "https") { |
35 | | - startSSLyzeScan(finding.attributes.hostname, finding.attributes.port); |
36 | | - |
37 | | - startZAPBaselineScan(finding.attributes.hostname, finding.attributes.port); |
38 | | - } |
39 | | - |
40 | | - // search for HTTPS ports and start subsequent SSH Scan |
41 | | - if(finding.attributes.service == "ssh" ) { |
42 | | - startSSHScan(finding.attributes.hostname, finding.attributes.port); |
43 | | - } |
| 13 | + if ( |
| 14 | + finding.category === "Open Port" && |
| 15 | + finding.attributes.state === "open" |
| 16 | + ) { |
| 17 | + const hostname = finding.attributes.hostname; |
| 18 | + const port = finding.attributes.port; |
| 19 | + |
| 20 | + console.log( |
| 21 | + "Found open port finding for service: " + finding.attributes.port |
| 22 | + ); |
| 23 | + |
| 24 | + // search for HTTP ports and start subsequent Nikto Scan |
| 25 | + if (finding.attributes.service === "http") { |
| 26 | + await startNiktoScan({ |
| 27 | + parentScan: scan, |
| 28 | + hostname, |
| 29 | + port, |
| 30 | + }); |
| 31 | + } |
| 32 | + |
| 33 | + // search for HTTPS ports and start subsequent SSLyze Scan |
| 34 | + if ( |
| 35 | + finding.attributes.service === "ssl" || |
| 36 | + finding.attributes.service === "https" |
| 37 | + ) { |
| 38 | + await startSSLyzeScan({ |
| 39 | + parentScan: scan, |
| 40 | + hostname, |
| 41 | + port, |
| 42 | + }); |
| 43 | + |
| 44 | + await startZAPBaselineScan({ |
| 45 | + parentScan: scan, |
| 46 | + hostname, |
| 47 | + port, |
| 48 | + }); |
| 49 | + } |
| 50 | + |
| 51 | + // search for HTTPS ports and start subsequent SSH Scan |
| 52 | + if (finding.attributes.service === "ssh") { |
| 53 | + await startSSHScan({ |
| 54 | + parentScan: scan, |
| 55 | + hostname, |
| 56 | + port, |
| 57 | + }); |
44 | 58 | } |
45 | 59 | } |
46 | 60 | } |
47 | | - |
48 | | - // const k8sApi = kc.makeApiClient(k8s.CoreV1Api); |
49 | | - |
50 | | - // console.log("list namespaced Pods") |
51 | | - // k8sApi.listNamespacedPod('default').then((res) => { |
52 | | - // console.log(res.body); |
53 | | - // }); |
54 | | - |
55 | | - // const k8sApiCRD = kc.makeApiClient(k8s.CustomObjectsApi); |
56 | | - |
57 | | - // // found at: https://github.com/kubernetes-client/javascript/issues/144 |
58 | | - // console.log("list namespaced CRDs") |
59 | | - // k8sApiCRD.listNamespacedCustomObject( |
60 | | - // 'execution.experimental.securecodebox.io', |
61 | | - // 'v1', |
62 | | - // 'default', |
63 | | - // 'scans', |
64 | | - // 'false' |
65 | | - // ).then((res) => { |
66 | | - // console.log(res.body); |
67 | | - // }); |
68 | 61 | } |
69 | 62 |
|
70 | 63 | /** |
71 | 64 | * Creates a new subsequent SCB ZAP Scan for the given hostname. |
72 | | - * @param {*} hostname The hostname to start a new subsequent ZAP scan for. |
73 | | - * @param {*} port The port to start a new subsequent ZAP scan for. |
| 65 | + * @param {string} hostname The hostname to start a new subsequent ZAP scan for. |
| 66 | + * @param {string} port The port to start a new subsequent ZAP scan for. |
74 | 67 | */ |
75 | | -function startZAPBaselineScan(hostname, port) { |
76 | | - console.log(" --> starting subsequent ZAP Scan for host: " + hostname + ":" + port); |
77 | | - |
78 | | - const zapScanDefinition = { |
79 | | - apiVersion: "execution.experimental.securecodebox.io/v1", |
80 | | - kind: "Scan", |
81 | | - metadata: { |
82 | | - "name": "zap-" + hostname.toLowerCase(), |
83 | | - "labels": { |
84 | | - "organization": "secureCodeBox" |
85 | | - } |
86 | | - }, |
87 | | - spec: { |
88 | | - "scanType": "zap-baseline", |
89 | | - "parameters": [ |
90 | | - "-t", |
91 | | - "https://" + hostname + ":" + port |
92 | | - ] |
93 | | - } |
94 | | - }; |
95 | | - |
96 | | - // Starting another subsequent sslyze scan based on the nmap results |
97 | | - // found at: https://github.com/kubernetes-client/javascript/blob/79736b9a608c18d818de61a6b44503a08ea3a78f/src/gen/api/customObjectsApi.ts#L209 |
98 | | - k8sApiCRD.createNamespacedCustomObject( |
99 | | - 'execution.experimental.securecodebox.io', |
100 | | - 'v1', |
101 | | - 'default', |
102 | | - 'scans', |
103 | | - zapScanDefinition, |
104 | | - 'false' |
105 | | - ).then((res) => { |
106 | | - console.log(res.body); |
107 | | - }) |
108 | | - .catch((e) => { |
109 | | - console.log(e); |
| 68 | +async function startZAPBaselineScan({ parentScan, hostname, port }) { |
| 69 | + console.log( |
| 70 | + " --> starting subsequent ZAP Scan for host: " + hostname + ":" + port |
| 71 | + ); |
| 72 | + |
| 73 | + await startSubsequentSecureCodeBoxScan({ |
| 74 | + parentScan, |
| 75 | + name: `zap-${hostname.toLowerCase()}`, |
| 76 | + scanType: "zap-baseline", |
| 77 | + parameters: ["-t", "https://" + hostname + ":" + port], |
110 | 78 | }); |
111 | 79 | } |
112 | 80 |
|
113 | 81 | /** |
114 | 82 | * Creates a new subsequent SCB SSH Scan for the given hostname. |
115 | | - * @param {*} hostname The hostname to start a new subsequent SSH scan for. |
116 | | - * @param {*} port The port to start a new subsequent SSH scan for. |
| 83 | + * @param {string} hostname The hostname to start a new subsequent SSH scan for. |
| 84 | + * @param {string} port The port to start a new subsequent SSH scan for. |
117 | 85 | */ |
118 | | -function startSSHScan(hostname, port) { |
119 | | - console.log(" --> starting subsequent SSH Scan for host: " + hostname + ":" + port); |
120 | | - |
121 | | - const sshScanDefintion = { |
122 | | - "apiVersion": "execution.experimental.securecodebox.io/v1", |
123 | | - "kind": "Scan", |
124 | | - "metadata": { |
125 | | - "name": "ssh-" + hostname.toLowerCase(), |
126 | | - "labels": { |
127 | | - "organization": "secureCodeBox" |
128 | | - } |
129 | | - }, |
130 | | - "spec": { |
131 | | - "scanType": "ssh-scan", |
132 | | - "parameters": [ |
133 | | - "-t", |
134 | | - hostname |
135 | | - ] |
136 | | - } |
137 | | - }; |
138 | | - |
139 | | - // Starting another subsequent sslyze scan based on the nmap results |
140 | | - // found at: https://github.com/kubernetes-client/javascript/blob/79736b9a608c18d818de61a6b44503a08ea3a78f/src/gen/api/customObjectsApi.ts#L209 |
141 | | - k8sApiCRD.createNamespacedCustomObject( |
142 | | - 'execution.experimental.securecodebox.io', |
143 | | - 'v1', |
144 | | - 'default', |
145 | | - 'scans', |
146 | | - sshScanDefintion, |
147 | | - 'false' |
148 | | - ).then((res) => { |
149 | | - console.log(res.body); |
150 | | - }) |
151 | | - .catch((e) => { |
152 | | - console.log(e); |
| 86 | +async function startSSHScan({ parentScan, hostname, port }) { |
| 87 | + console.log( |
| 88 | + " --> starting subsequent SSH Scan for host: " + hostname + ":" + port |
| 89 | + ); |
| 90 | + |
| 91 | + await startSubsequentSecureCodeBoxScan({ |
| 92 | + parentScan, |
| 93 | + name: `ssh-${hostname.toLowerCase()}`, |
| 94 | + scanType: "ssh-scan", |
| 95 | + parameters: ["-t", hostname], |
153 | 96 | }); |
154 | 97 | } |
155 | 98 |
|
156 | 99 | /** |
157 | 100 | * Creates a new subsequent SCB Nikto Scan for the given hostname. |
158 | | - * @param {*} hostname The hostname to start a new subsequent Nikto scan for. |
159 | | - * @param {*} port The port to start a new subsequent Nikto scan for. |
| 101 | + * @param {string} hostname The hostname to start a new subsequent Nikto scan for. |
| 102 | + * @param {string} port The port to start a new subsequent Nikto scan for. |
160 | 103 | */ |
161 | | -function startNiktoScan(hostname, port) { |
162 | | - console.log(" --> starting subsequent Nikto Scan for host: " + hostname + ":" + port); |
163 | | - |
164 | | - const niktoScanDefinition = { |
165 | | - "apiVersion": "execution.experimental.securecodebox.io/v1", |
166 | | - "kind": "Scan", |
167 | | - "metadata": { |
168 | | - "name": "nikto-" + hostname.toLowerCase(), |
169 | | - "labels": { |
170 | | - "organization": "secureCodeBox" |
171 | | - } |
172 | | - }, |
173 | | - "spec": { |
174 | | - "scanType": "nikto", |
175 | | - "parameters": [ |
176 | | - "-h", |
177 | | - "https://" + hostname, |
178 | | - "-Tuning", |
179 | | - "1,2,3,5,7,b" |
180 | | - ] |
181 | | - } |
182 | | - }; |
183 | | - |
184 | | - // Starting another subsequent sslyze scan based on the nmap results |
185 | | - // found at: https://github.com/kubernetes-client/javascript/blob/79736b9a608c18d818de61a6b44503a08ea3a78f/src/gen/api/customObjectsApi.ts#L209 |
186 | | - k8sApiCRD.createNamespacedCustomObject( |
187 | | - 'execution.experimental.securecodebox.io', |
188 | | - 'v1', |
189 | | - 'default', |
190 | | - 'scans', |
191 | | - niktoScanDefinition, |
192 | | - 'false' |
193 | | - ).then((res) => { |
194 | | - console.log(res.body); |
195 | | - }) |
196 | | - .catch((e) => { |
197 | | - console.log(e); |
| 104 | +async function startNiktoScan({ parentScan, hostname, port }) { |
| 105 | + console.log( |
| 106 | + " --> starting subsequent Nikto Scan for host: " + hostname + ":" + port |
| 107 | + ); |
| 108 | + |
| 109 | + await startSubsequentSecureCodeBoxScan({ |
| 110 | + parentScan, |
| 111 | + name: `nikto-${hostname.toLowerCase()}`, |
| 112 | + scanType: "nikto", |
| 113 | + parameters: ["-h", "https://" + hostname, "-Tuning", "1,2,3,5,7,b"], |
198 | 114 | }); |
199 | 115 | } |
200 | 116 |
|
201 | 117 | /** |
202 | 118 | * Creates a new subsequent SCB SSLyze Scan for the given hostname. |
203 | | - * @param {*} hostname The hostname to start a new subsequent SSLyze scan for. |
204 | | - * @param {*} port The port to start a new subsequent SSLyze scan for. |
| 119 | + * @param {string} hostname The hostname to start a new subsequent SSLyze scan for. |
| 120 | + * @param {string} port The port to start a new subsequent SSLyze scan for. |
205 | 121 | */ |
206 | | -function startSSLyzeScan(hostname, port) { |
207 | | - console.log(" --> starting subsequent SSLyze Scan for host: " + hostname + ":" + port); |
208 | | - |
209 | | - const sslyzeScanDefinition = { |
210 | | - apiVersion: 'execution.experimental.securecodebox.io/v1', |
211 | | - kind: 'Scan', |
212 | | - metadata: { |
213 | | - "name": "sslyze-" + hostname.toLowerCase(), |
214 | | - "labels": { |
215 | | - "organization": "secureCodeBox" |
216 | | - } |
217 | | - }, |
218 | | - "spec": { |
219 | | - "scanType": "sslyze", |
220 | | - "parameters": [ |
221 | | - "--regular", |
222 | | - hostname |
223 | | - ] |
224 | | - } |
225 | | - }; |
226 | | - |
227 | | - // Starting another subsequent sslyze scan based on the nmap results |
228 | | - // found at: https://github.com/kubernetes-client/javascript/blob/79736b9a608c18d818de61a6b44503a08ea3a78f/src/gen/api/customObjectsApi.ts#L209 |
229 | | - k8sApiCRD.createNamespacedCustomObject( |
230 | | - 'execution.experimental.securecodebox.io', |
231 | | - 'v1', |
232 | | - 'default', |
233 | | - 'scans', |
234 | | - sslyzeScanDefinition, |
235 | | - 'false' |
236 | | - ).then((res) => { |
237 | | - console.log(res.body); |
238 | | - }) |
239 | | - .catch((e) => { |
240 | | - console.log(e); |
241 | | - }); |
| 122 | +async function startSSLyzeScan({ parentScan, hostname, port }) { |
| 123 | + console.log( |
| 124 | + " --> starting subsequent SSLyze Scan for host: " + hostname + ":" + port |
| 125 | + ); |
| 126 | + |
| 127 | + await startSubsequentSecureCodeBoxScan({ |
| 128 | + parentScan, |
| 129 | + name: `sslyze-${hostname.toLowerCase()}`, |
| 130 | + scanType: "sslyze", |
| 131 | + parameters: ["--regular", hostname], |
| 132 | + }); |
242 | 133 | } |
243 | 134 |
|
244 | 135 | module.exports.handle = handle; |
0 commit comments