1+ // SPDX-FileCopyrightText: the secureCodeBox authors
2+ //
3+ // SPDX-License-Identifier: Apache-2.0
4+
15const templates = {
26 delCritical : {
37 kex : {
@@ -85,14 +89,60 @@ const templates = {
8589 name : "SSH Encryption Algorithms must be changed" ,
8690 description : "Weak SSH encryption algorithms in use" ,
8791 hint : "Change these encryption algorithms"
92+ } ,
93+
94+ addCritical : {
95+ kex : {
96+ name : "SSH KEX Algorithms must be added" ,
97+ description : "SSH key exchange algorithms missing" ,
98+ hint : "Add these KEX algorithms"
99+ } ,
100+ key : {
101+ name : "SSH Key Algorithms must be added" ,
102+ description : "SSH key algorithms missing" ,
103+ hint : "Add these key algorithms"
104+ } ,
105+ mac : {
106+ name : "SSH MAC Algorithms must be added" ,
107+ description : "SSH message authentication code algorithms missing" ,
108+ hint : "Add these MAC algorithms"
109+ } ,
110+ enc : {
111+ name : "SSH Encryption Algorithms must be added" ,
112+ description : "SSH encryption algorithms missing" ,
113+ hint : "Add these encryption algorithms"
114+ }
115+ } ,
116+ addWarning : {
117+ kex : {
118+ name : "SSH KEX Algorithms must be added" ,
119+ description : "SSH key exchange algorithms missing" ,
120+ hint : "Add these KEX algorithms"
121+ } ,
122+ key : {
123+ name : "SSH Key Algorithms must be added" ,
124+ description : "SSH key algorithms missing" ,
125+ hint : "Add these key algorithms"
126+ } ,
127+ mac : {
128+ name : "SSH MAC Algorithms must be added" ,
129+ description : "SSH message authentication code algorithms missing" ,
130+ hint : "Add these MAC algorithms"
131+ } ,
132+ enc : {
133+ name : "SSH Encryption Algorithms must be added" ,
134+ description : "SSH encryption algorithms missing" ,
135+ hint : "Add these encryption algorithms"
136+ }
88137 }
89138 }
90139}
91140
92141
93142/**
94- * Transforms a recommendation string from thessh-audit Tools into a SSH Policy Violation Findings
95- *
143+ * Transforms recommendations from the ssh-audit scanner into SSH Policy Violation Findings
144+ * @param {String } recommendationSeverityLevel
145+ * @param {{} } value
96146 */
97147function transformRecommendationToFinding ( recommendationSeverityLevel , value ) {
98148 // SSH audit has critical and warnings as recommendations.
@@ -102,19 +152,19 @@ function transformRecommendationToFinding(recommendationSeverityLevel, value) {
102152 if ( recommendationSeverityLevel == "critical" ) severity = 'HIGH'
103153 if ( recommendationSeverityLevel == "warning" ) severity = 'MEDIUM'
104154 const findingTemplate = null ;
105- // recommendationAction = del
155+ // recommendationAction = del/chg/add
106156 Object . entries ( value ) . map ( ( [ recommendationAction , algorithms ] ) => {
107157 //algorithmType = kex/ key/ mac, , algorithmNames = {name+note}
108158 Object . entries ( algorithms ) . map ( ( [ algorithmType , algorithmData ] ) => {
109159 const algorithmNames = [ ]
110160 Object . entries ( algorithmData ) . flatMap ( ( [ keyNames , content ] ) => { algorithmNames . push ( Object . values ( content ) ) } )
111- //console.log(algorithmNames)
112- //console.log(algorithmData)
113161 var action = "" ;
114162 if ( recommendationAction == "del" && recommendationSeverityLevel == "critical" ) action = "delCritical"
115163 else if ( recommendationAction == "del" && recommendationSeverityLevel == "warning" ) action = "delWarning"
116164 else if ( recommendationAction == "chg" && recommendationSeverityLevel == "critical" ) action = "chgCritical"
117165 else if ( recommendationAction == "chg" && recommendationSeverityLevel == "warning" ) action = "chgWarning"
166+ else if ( recommendationAction == "add" && recommendationSeverityLevel == "critical" ) action = "addCritical"
167+ else if ( recommendationAction == "add" && recommendationSeverityLevel == "warning" ) action = "addWarning"
118168 const findingTemplate = templates [ action ] [ algorithmType ] || null ;
119169
120170 if ( findingTemplate != null && typeof ( findingTemplate ) != "undefined" ) {
@@ -127,26 +177,25 @@ function transformRecommendationToFinding(recommendationSeverityLevel, value) {
127177 else combinedAlgorithmNames . push ( ( algName + " (Note: " + note + ")" ) )
128178 } )
129179
130- //console.log(combinedAlgorithmNames)
131180 findingTemplate [ 'algorithms' ] = combinedAlgorithmNames . flat ( )
132- //console.log("algorithmType\n\n\n",algorithmType)
133- //console.log("algorithmNames\n\n\n",algorithmNames)
134181 policyViolationFindings . push ( findingTemplate )
135- //console.log(findingTemplate)
136182 }
137183 } )
138184 } )
139185
140186 return policyViolationFindings ;
141187}
142188
189+ /**
190+ * Transforms cves's from the ssh-audit scanner into SSH Violation Findings
191+ * @param {{} } cves
192+ */
143193function transformCVEtoFinding ( cves ) {
144- //console.log(Object.values(cves))
194+
145195 const cvesArray = Object . values ( cves )
146196 const cvesFindings = [ ]
147197 var severity = ''
148198 Object . values ( cvesArray ) . flatMap ( ( { cvssv2, description, name} ) => {
149- //console.log(cvssv2, description, name )
150199 const findingTemplate = { }
151200 if ( cvssv2 < 4 ) severity = "LOW"
152201 else if ( cvssv2 < 7 ) severity = "MEDIUM"
@@ -156,30 +205,35 @@ function transformCVEtoFinding(cves) {
156205 findingTemplate [ 'category' ] = "SSH Violation"
157206 findingTemplate [ 'severity' ] = severity
158207 findingTemplate [ 'cvssv2' ] = cvssv2
208+
159209 findingTemplate [ 'references' ] = [ ]
160210 findingTemplate [ 'references' ] . push ( { 'type' :'CVE' , 'value' :`${ name } ` } )
161211 findingTemplate [ 'references' ] . push ( { 'type' :'URL' , 'value' :`https://nvd.nist.gov/vuln/detail/${ name } ` } )
162- //findingTemplate['references']['type'] = `URL`
163- //findingTemplate['references']['value'] = `https://nvd.nist.gov/vuln/detail/${name}`
164212 cvesFindings . push ( findingTemplate )
165213 } )
166214 return cvesFindings ;
167215}
168216
217+ /**
218+ *
219+ * Parses the raw results from the ssh-audit scanner into Findings
220+ */
169221async function parse ( fileContent ) {
170- //{ target, banner, enc, kex, key, mac, compression, fingerprints, recommendations, cves}
222+
171223 const host = fileContent ;
172224 if ( typeof ( host ) === "string" ) return [ ]
225+
173226 const recommendationsArray = Object . entries ( host . recommendations )
174227 const policyViolationFindings = [ ] ;
228+
175229 recommendationsArray . map ( ( [ recommendationSeverityLevel , value ] ) => {
176230 policyViolationFindings . push ( transformRecommendationToFinding ( recommendationSeverityLevel , value ) )
177231 } )
232+
178233 const policyViolationFinding = policyViolationFindings . flat ( )
179-
180234 const cvesFindings = transformCVEtoFinding ( host . cves )
181235
182-
236+ // informational findings
183237 const destination = host . target . split ( ":" )
184238 const serviceFinding = {
185239 name : "SSH Service" ,
@@ -202,11 +256,7 @@ async function parse(fileContent) {
202256 }
203257 } ;
204258 return [ serviceFinding , ...policyViolationFinding , ...cvesFindings ] ;
205- //return [serviceFinding];
206259
207260}
208- const test = { "banner" : { "comments" : "Ubuntu-4ubuntu2.8" , "protocol" : [ 2 , 0 ] , "raw" : "SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.8" , "software" : "OpenSSH_7.2p2" } , "compression" : [ "none" , "zlib@openssh.com" ] , "cves" : [ { "cvssv2" : 7.0 , "description" : "privilege escalation via supplemental groups" , "name" : "CVE-2021-41617" } , { "cvssv2" : 7.8 , "description" : "command injection via anomalous argument transfers" , "name" : "CVE-2020-15778" } , { "cvssv2" : 5.3 , "description" : "username enumeration via GS2" , "name" : "CVE-2018-15919" } , { "cvssv2" : 5.3 , "description" : "enumerate usernames due to timing discrepancies" , "name" : "CVE-2018-15473" } , { "cvssv2" : 5.3 , "description" : "enumerate usernames via challenge response" , "name" : "CVE-2016-20012" } , { "cvssv2" : 7.8 , "description" : "cause DoS via long password string (crypt CPU consumption)" , "name" : "CVE-2016-6515" } , { "cvssv2" : 7.2 , "description" : "privilege escalation via triggering crafted environment" , "name" : "CVE-2015-8325" } ] , "enc" : [ "chacha20-poly1305@openssh.com" , "aes128-ctr" , "aes192-ctr" , "aes256-ctr" , "aes128-gcm@openssh.com" , "aes256-gcm@openssh.com" ] , "fingerprints" : [ { "hash" : "eLwgzyjvrpwDbDr+pDbIfUhlNANB4DPH9/0w1vGa87E" , "hash_alg" : "SHA256" , "hostkey" : "ssh-ed25519" } , { "hash" : "c8:65:6b:d1:59:03:56:21:d9:0f:84:83:ce:ac:40:86" , "hash_alg" : "MD5" , "hostkey" : "ssh-ed25519" } , { "hash" : "MbRX/CgQyN6/p8/ZjORurfaJqDhu4VEIWfXo0BnxaCE" , "hash_alg" : "SHA256" , "hostkey" : "ssh-rsa" } , { "hash" : "a5:6f:62:26:81:03:b7:5e:06:48:10:04:79:4b:ac:32" , "hash_alg" : "MD5" , "hostkey" : "ssh-rsa" } ] , "kex" : [ { "algorithm" : "curve25519-sha256@libssh.org" } , { "algorithm" : "ecdh-sha2-nistp256" } , { "algorithm" : "ecdh-sha2-nistp384" } , { "algorithm" : "ecdh-sha2-nistp521" } , { "algorithm" : "diffie-hellman-group-exchange-sha256" , "keysize" : 2048 } , { "algorithm" : "diffie-hellman-group14-sha1" } ] , "key" : [ { "algorithm" : "ssh-rsa" , "keysize" : 2048 } , { "algorithm" : "rsa-sha2-512" , "keysize" : 2048 } , { "algorithm" : "rsa-sha2-256" , "keysize" : 2048 } , { "algorithm" : "ecdsa-sha2-nistp256" } , { "algorithm" : "ssh-ed25519" } ] , "mac" : [ "umac-64-etm@openssh.com" , "umac-128-etm@openssh.com" , "hmac-sha2-256-etm@openssh.com" , "hmac-sha2-512-etm@openssh.com" , "hmac-sha1-etm@openssh.com" , "umac-64@openssh.com" , "umac-128@openssh.com" , "hmac-sha2-256" , "hmac-sha2-512" , "hmac-sha1" ] , "recommendations" : { "critical" : { "del" : { "kex" : [ { "name" : "diffie-hellman-group14-sha1" , "notes" : "" } , { "name" : "ecdh-sha2-nistp256" , "notes" : "" } , { "name" : "ecdh-sha2-nistp384" , "notes" : "" } , { "name" : "ecdh-sha2-nistp521" , "notes" : "" } ] , "key" : [ { "name" : "ecdsa-sha2-nistp256" , "notes" : "" } , { "name" : "ssh-rsa" , "notes" : "" } ] , "mac" : [ { "name" : "hmac-sha1" , "notes" : "" } , { "name" : "hmac-sha1-etm@openssh.com" , "notes" : "" } ] } } , "warning" : { "chg" : { "key" : [ { "name" : "rsa-sha2-256" , "notes" : "increase modulus size to 3072 bits or larger" } , { "name" : "rsa-sha2-512" , "notes" : "increase modulus size to 3072 bits or larger" } ] } , "del" : { "mac" : [ { "name" : "hmac-sha2-256" , "notes" : "" } , { "name" : "hmac-sha2-512" , "notes" : "" } , { "name" : "umac-128@openssh.com" , "notes" : "" } , { "name" : "umac-64-etm@openssh.com" , "notes" : "" } , { "name" : "umac-64@openssh.com" , "notes" : "" } ] } } } , "target" : "dummy-ssh.default.svc:22" }
209261
210- //console.log(parse(test))
211- //parse(test)
212262module . exports . parse = parse ;
0 commit comments