Skip to content

Commit

Permalink
🐛 Add id to CVSS score (#5163)
Browse files Browse the repository at this point in the history
* 🐛 Add id to CVSS score

This fixes issues with the vulnmgmt resources, where the score might show as 0.

Signed-off-by: Christian Zunker <christian@mondoo.com>
  • Loading branch information
czunker authored Feb 10, 2025
1 parent ec225d2 commit 3830244
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions providers/os/resources/asset_vuln.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package resources
import (
"context"
"errors"
"fmt"
"time"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -152,7 +153,9 @@ func (a *mqlPlatformAdvisories) cvss() (*mqlAuditCvss, error) {
return nil, err
}

id := fmt.Sprintf("%d", report.Stats.Score)
obj, err := CreateResource(a.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(report.Stats.Score) / 10),
"vector": llx.StringData(""), // TODO: we need to extend the report to include the vector in the report
})
Expand Down Expand Up @@ -180,7 +183,9 @@ func (a *mqlPlatformAdvisories) list() ([]interface{}, error) {
worstScore = &cvss.Cvss{Score: 0.0, Vector: ""}
}

id := fmt.Sprintf("%.1f-%s", worstScore.Score, worstScore.Vector)
cvssScore, err := CreateResource(a.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(worstScore.Score)),
"vector": llx.StringData(worstScore.Vector),
})
Expand Down Expand Up @@ -256,7 +261,9 @@ func (a *mqlPlatformCves) list() ([]interface{}, error) {
worstScore = &cvss.Cvss{Score: 0.0, Vector: ""}
}

id := fmt.Sprintf("%.1f-%s", worstScore.Score, worstScore.Vector)
cvssScore, err := CreateResource(a.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(worstScore.Score)),
"vector": llx.StringData(worstScore.Vector),
})
Expand Down Expand Up @@ -313,7 +320,9 @@ func (a *mqlPlatformCves) cvss() (*mqlAuditCvss, error) {
}
}

id := fmt.Sprintf("%.1f-", score)
obj, err := CreateResource(a.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(int(score*10)) / 10),
"vector": llx.StringData(""),
})
Expand Down
7 changes: 7 additions & 0 deletions providers/os/resources/vulnmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package resources

import (
"errors"
"fmt"
"time"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -117,7 +118,9 @@ func (v *mqlVulnmgmt) populateData() error {
} else {
parsedModified = &modified
}
id := fmt.Sprintf("%d-%s", a.CvssScore.Value, a.CvssScore.Vector)
cvssScore, err := CreateResource(v.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(a.CvssScore.Value) / 10),
"vector": llx.StringData(a.CvssScore.Vector),
})
Expand Down Expand Up @@ -155,7 +158,9 @@ func (v *mqlVulnmgmt) populateData() error {
} else {
parsedModified = &modified
}
id := fmt.Sprintf("%d-%s", c.CvssScore.Value, c.CvssScore.Vector)
cvssScore, err := CreateResource(v.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(c.CvssScore.Value) / 10),
"vector": llx.StringData(c.CvssScore.Vector),
})
Expand Down Expand Up @@ -190,7 +195,9 @@ func (v *mqlVulnmgmt) populateData() error {
mqlVulnPackages[i] = mqlVulnPackage
}

id := fmt.Sprintf("%d-%s", vulnReport.Stats.Score.Value, vulnReport.Stats.Score.Vector)
res, err := CreateResource(v.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(vulnReport.Stats.Score.Value) / 10),
"vector": llx.StringData(vulnReport.Stats.Score.Vector),
})
Expand Down
7 changes: 7 additions & 0 deletions providers/vsphere/resources/vulnmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package resources

import (
"errors"
"fmt"
"time"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -98,7 +99,9 @@ func (v *mqlVulnmgmt) populateData() error {
if err != nil {
return err
}
id := fmt.Sprintf("%d-%s", a.CvssScore.Value, a.CvssScore.Vector)
cvssScore, err := CreateResource(v.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(a.CvssScore.Value) / 10),
"vector": llx.StringData(a.CvssScore.Vector),
})
Expand Down Expand Up @@ -129,7 +132,9 @@ func (v *mqlVulnmgmt) populateData() error {
if err != nil {
return err
}
id := fmt.Sprintf("%d-%s", c.CvssScore.Value, c.CvssScore.Vector)
cvssScore, err := CreateResource(v.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(c.CvssScore.Value) / 10),
"vector": llx.StringData(c.CvssScore.Vector),
})
Expand All @@ -148,7 +153,9 @@ func (v *mqlVulnmgmt) populateData() error {
mqlVulnCves[i] = mqlVulnCve
}

id := fmt.Sprintf("%d-%s", vulnReport.Stats.Score.Value, vulnReport.Stats.Score.Vector)
res, err := CreateResource(v.MqlRuntime, "audit.cvss", map[string]*llx.RawData{
"__id": llx.StringData(id),
"score": llx.FloatData(float64(vulnReport.Stats.Score.Value) / 10),
"vector": llx.StringData(vulnReport.Stats.Score.Vector),
})
Expand Down

0 comments on commit 3830244

Please sign in to comment.