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