From 492cae6dffaca1d8ea2be275cd52026ad5873dd3 Mon Sep 17 00:00:00 2001 From: MaineK00n Date: Mon, 1 Jul 2024 14:16:50 +0900 Subject: [PATCH] feat(contrib/trivy): support CVSS v4.0 --- contrib/trivy/parser/v2/parser_test.go | 24 +++++++++++++++--------- contrib/trivy/pkg/converter.go | 7 ++++--- go.mod | 2 ++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/contrib/trivy/parser/v2/parser_test.go b/contrib/trivy/parser/v2/parser_test.go index af2e9f781b..aed28c522a 100644 --- a/contrib/trivy/parser/v2/parser_test.go +++ b/contrib/trivy/parser/v2/parser_test.go @@ -1949,7 +1949,7 @@ var oneCVEtoNVulnerabilityTrivy = []byte(` ], "VendorSeverity": { "ghsa": 2, - "nvd": 2, + "nvd": 3, "ruby-advisory-db": 2 }, "CVSS": { @@ -1958,6 +1958,8 @@ var oneCVEtoNVulnerabilityTrivy = []byte(` "V3Score": 5.9 }, "nvd": { + "V40Vector": "CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N", + "V40Score": 8.9, "V3Vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N", "V3Score": 5.9 } @@ -2027,7 +2029,7 @@ var oneCVEtoNVulnerabilityTrivy = []byte(` ], "VendorSeverity": { "ghsa": 2, - "nvd": 2, + "nvd": 3, "ruby-advisory-db": 2 }, "CVSS": { @@ -2036,6 +2038,8 @@ var oneCVEtoNVulnerabilityTrivy = []byte(` "V3Score": 5.9 }, "nvd": { + "V40Vector": "CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N", + "V40Score": 8.9, "V3Vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N", "V3Score": 5.9 } @@ -2545,7 +2549,7 @@ var oneCVEtoNVulnerabilitySR = &models.ScanResult{ CveID: "CVE-2023-26154", Title: "pubnub Insufficient Entropy vulnerability", Summary: "Versions of the package pubnub before 7.4.0; all versions of the package com.pubnub:pubnub; versions of the package pubnub before 6.19.0; all versions of the package github.com/pubnub/go; versions of the package github.com/pubnub/go/v7 before 7.2.0; versions of the package pubnub before 7.3.0; versions of the package pubnub/pubnub before 6.1.0; versions of the package pubnub before 5.3.0; versions of the package pubnub before 0.4.0; versions of the package pubnub/c-core before 4.5.0; versions of the package com.pubnub:pubnub-kotlin before 7.7.0; versions of the package pubnub/swift before 6.2.0; versions of the package pubnub before 5.2.0; versions of the package pubnub before 4.3.0 are vulnerable to Insufficient Entropy via the getKey function, due to inefficient implementation of the AES-256-CBC cryptographic algorithm. The provided encrypt function is less secure when hex encoding and trimming are applied, leaving half of the bits in the key always the same for every encoded message or file.\r\r**Note:**\r\rIn order to exploit this vulnerability, the attacker needs to invest resources in preparing the attack and brute-force the encryption.", - Cvss3Severity: "MEDIUM", + Cvss3Severity: "HIGH", References: models.References{ { Source: "trivy", @@ -2648,12 +2652,14 @@ var oneCVEtoNVulnerabilitySR = &models.ScanResult{ LastModified: time.Date(2023, time.December, 11, 17, 48, 3, 653, time.UTC), }, { - Type: "trivy:nvd", - CveID: "CVE-2023-26154", - Title: "pubnub Insufficient Entropy vulnerability", - Summary: "Versions of the package pubnub before 7.4.0; all versions of the package com.pubnub:pubnub; versions of the package pubnub before 6.19.0; all versions of the package github.com/pubnub/go; versions of the package github.com/pubnub/go/v7 before 7.2.0; versions of the package pubnub before 7.3.0; versions of the package pubnub/pubnub before 6.1.0; versions of the package pubnub before 5.3.0; versions of the package pubnub before 0.4.0; versions of the package pubnub/c-core before 4.5.0; versions of the package com.pubnub:pubnub-kotlin before 7.7.0; versions of the package pubnub/swift before 6.2.0; versions of the package pubnub before 5.2.0; versions of the package pubnub before 4.3.0 are vulnerable to Insufficient Entropy via the getKey function, due to inefficient implementation of the AES-256-CBC cryptographic algorithm. The provided encrypt function is less secure when hex encoding and trimming are applied, leaving half of the bits in the key always the same for every encoded message or file.\r\r**Note:**\r\rIn order to exploit this vulnerability, the attacker needs to invest resources in preparing the attack and brute-force the encryption.", - Cvss3Score: 5.9, - Cvss3Vector: "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N", + Type: "trivy:nvd", + CveID: "CVE-2023-26154", + Title: "pubnub Insufficient Entropy vulnerability", + Summary: "Versions of the package pubnub before 7.4.0; all versions of the package com.pubnub:pubnub; versions of the package pubnub before 6.19.0; all versions of the package github.com/pubnub/go; versions of the package github.com/pubnub/go/v7 before 7.2.0; versions of the package pubnub before 7.3.0; versions of the package pubnub/pubnub before 6.1.0; versions of the package pubnub before 5.3.0; versions of the package pubnub before 0.4.0; versions of the package pubnub/c-core before 4.5.0; versions of the package com.pubnub:pubnub-kotlin before 7.7.0; versions of the package pubnub/swift before 6.2.0; versions of the package pubnub before 5.2.0; versions of the package pubnub before 4.3.0 are vulnerable to Insufficient Entropy via the getKey function, due to inefficient implementation of the AES-256-CBC cryptographic algorithm. The provided encrypt function is less secure when hex encoding and trimming are applied, leaving half of the bits in the key always the same for every encoded message or file.\r\r**Note:**\r\rIn order to exploit this vulnerability, the attacker needs to invest resources in preparing the attack and brute-force the encryption.", + Cvss3Score: 5.9, + Cvss3Vector: "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N", + Cvss40Score: 8.9, + Cvss40Vector: "CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N", References: models.References{ { Source: "trivy", diff --git a/contrib/trivy/pkg/converter.go b/contrib/trivy/pkg/converter.go index c0193e7302..03ab89a978 100644 --- a/contrib/trivy/pkg/converter.go +++ b/contrib/trivy/pkg/converter.go @@ -82,8 +82,7 @@ func Convert(results types.Results) (result *models.ScanResult, err error) { } } } - slices.SortFunc(severities, trivydbTypes.CompareSeverityString) - slices.Reverse(severities) + slices.SortFunc(severities, func(a, b string) int { return -trivydbTypes.CompareSeverityString(a, b) }) vulnInfo.CveContents[models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source))] = []models.CveContent{{ Type: models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source)), @@ -100,7 +99,7 @@ func Convert(results types.Results) (result *models.ScanResult, err error) { for source, cvss := range vuln.CVSS { if cs, ok := vulnInfo.CveContents[models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source))]; ok && slices.ContainsFunc(cs, func(c models.CveContent) bool { - return c.Cvss2Score == cvss.V2Score && c.Cvss2Vector == cvss.V2Vector && c.Cvss3Score == cvss.V3Score && c.Cvss3Vector == cvss.V3Vector + return c.Cvss2Score == cvss.V2Score && c.Cvss2Vector == cvss.V2Vector && c.Cvss3Score == cvss.V3Score && c.Cvss3Vector == cvss.V3Vector && c.Cvss40Score == cvss.V40Score && c.Cvss40Vector == cvss.V40Vector }) { continue } @@ -114,6 +113,8 @@ func Convert(results types.Results) (result *models.ScanResult, err error) { Cvss2Vector: cvss.V2Vector, Cvss3Score: cvss.V3Score, Cvss3Vector: cvss.V3Vector, + Cvss40Score: cvss.V40Score, + Cvss40Vector: cvss.V40Vector, Published: published, LastModified: lastModified, References: references, diff --git a/go.mod b/go.mod index 1c6b36b9e3..ba18e261b5 100644 --- a/go.mod +++ b/go.mod @@ -367,3 +367,5 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) + +replace github.com/aquasecurity/trivy-db => ../trivy-db \ No newline at end of file