Skip to content

Commit fa4d76d

Browse files
committed
feat(detector/vuls2): SUSE by vuls2
1 parent ce2855c commit fa4d76d

File tree

4 files changed

+326
-6
lines changed

4 files changed

+326
-6
lines changed

detector/detector.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,12 @@ func Detect(rs []models.ScanResult, dir string) ([]models.ScanResult, error) {
322322
func DetectPkgCves(r *models.ScanResult, ovalCnf config.GovalDictConf, gostCnf config.GostConf, vuls2Conf config.Vuls2Conf, logOpts logging.LogOpts, noProgress bool) error {
323323
if isPkgCvesDetactable(r) {
324324
switch r.Family {
325-
case constant.RedHat, constant.CentOS, constant.Fedora, constant.Alma, constant.Rocky, constant.Oracle, constant.Alpine, constant.Ubuntu:
325+
case constant.RedHat, constant.CentOS, constant.Fedora, constant.Alma, constant.Rocky, constant.Oracle, constant.Alpine, constant.Ubuntu,
326+
constant.OpenSUSE, constant.OpenSUSELeap, constant.SUSEEnterpriseServer, constant.SUSEEnterpriseDesktop:
326327
if err := vuls2.Detect(r, vuls2Conf, noProgress); err != nil {
327328
return xerrors.Errorf("Failed to detect CVE with Vuls2: %w", err)
328329
}
329-
case constant.Amazon, constant.OpenSUSE, constant.OpenSUSELeap, constant.SUSEEnterpriseServer, constant.SUSEEnterpriseDesktop:
330+
case constant.Amazon:
330331
if err := detectPkgsCvesWithOval(ovalCnf, r, logOpts); err != nil {
331332
return xerrors.Errorf("Failed to detect CVE with OVAL: %w", err)
332333
}

detector/vuls2/vendor.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ func advisoryReference(e ecosystemTypes.Ecosystem, s sourceTypes.SourceID, da mo
462462
Source: "UBUNTU",
463463
RefID: da.AdvisoryID,
464464
}, nil
465+
case ecosystemTypes.EcosystemTypeOpenSUSE, ecosystemTypes.EcosystemTypeOpenSUSELeap, ecosystemTypes.EcosystemTypeOpenSUSELeapMicro, ecosystemTypes.EcosystemTypeOpenSUSETumbleweed,
466+
ecosystemTypes.EcosystemTypeSUSEEnterpriseServer, ecosystemTypes.EcosystemTypeSUSEEnterpriseDesktop, ecosystemTypes.EcosystemTypeSUSEEnterpriseMicro:
467+
return models.Reference{
468+
Link: fmt.Sprintf("https://www.suse.com/security/cve/%s.html", da.AdvisoryID),
469+
Source: "SUSE",
470+
RefID: da.AdvisoryID,
471+
}, nil
465472
default:
466473
return models.Reference{}, xerrors.Errorf("unsupported family: %s", et)
467474
}
@@ -479,6 +486,8 @@ func cveContentSourceLink(ccType models.CveContentType, v vulnerabilityTypes.Vul
479486
return fmt.Sprintf("https://ubuntu.com/security/%s", v.Content.ID)
480487
case models.Nvd:
481488
return fmt.Sprintf("https://nvd.nist.gov/vuln/detail/%s", v.Content.ID)
489+
case models.SUSE:
490+
return fmt.Sprintf("https://www.suse.com/security/cve/%s", v.Content.ID)
482491
default:
483492
return ""
484493
}
@@ -765,7 +774,7 @@ func toVuls0Confidence(e ecosystemTypes.Ecosystem, s sourceTypes.SourceID) model
765774
DetectionMethod: models.DetectionMethod("EPELMatch"),
766775
SortOrder: 1,
767776
}
768-
case ecosystemTypes.EcosystemTypeRedHat, ecosystemTypes.EcosystemTypeFedora, ecosystemTypes.EcosystemTypeAlma, ecosystemTypes.EcosystemTypeRocky, ecosystemTypes.EcosystemTypeOracle, ecosystemTypes.EcosystemTypeAlpine:
777+
case ecosystemTypes.EcosystemTypeRedHat, ecosystemTypes.EcosystemTypeFedora, ecosystemTypes.EcosystemTypeAlma, ecosystemTypes.EcosystemTypeRocky, ecosystemTypes.EcosystemTypeOracle, ecosystemTypes.EcosystemTypeAlpine, ecosystemTypes.EcosystemTypeSUSEEnterpriseServer, ecosystemTypes.EcosystemTypeSUSEEnterpriseDesktop, ecosystemTypes.EcosystemTypeSUSEEnterpriseMicro, ecosystemTypes.EcosystemTypeOpenSUSE, ecosystemTypes.EcosystemTypeOpenSUSELeap, ecosystemTypes.EcosystemTypeOpenSUSELeapMicro, ecosystemTypes.EcosystemTypeOpenSUSETumbleweed:
769778
return models.OvalMatch
770779
case ecosystemTypes.EcosystemTypeUbuntu:
771780
switch s {

detector/vuls2/vuls2.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
criteriaTypes "github.com/MaineK00n/vuls-data-update/pkg/extract/types/data/detection/condition/criteria"
2020
criterionTypes "github.com/MaineK00n/vuls-data-update/pkg/extract/types/data/detection/condition/criteria/criterion"
2121
vcAffectedRangeTypes "github.com/MaineK00n/vuls-data-update/pkg/extract/types/data/detection/condition/criteria/criterion/versioncriterion/affected/range"
22+
"github.com/MaineK00n/vuls-data-update/pkg/extract/types/data/detection/condition/criteria/criterion/versioncriterion/fixstatus"
2223
vcPackageTypes "github.com/MaineK00n/vuls-data-update/pkg/extract/types/data/detection/condition/criteria/criterion/versioncriterion/package"
2324
segmentTypes "github.com/MaineK00n/vuls-data-update/pkg/extract/types/data/detection/segment"
2425
ecosystemTypes "github.com/MaineK00n/vuls-data-update/pkg/extract/types/data/detection/segment/ecosystem"
@@ -169,6 +170,7 @@ func detect(sesh *session.Session, sr scanTypes.ScanResult) (detectTypes.DetectR
169170
Detections: []detectTypes.VulnerabilityDataDetection{d},
170171
}
171172

173+
<<<<<<< HEAD
172174
avs, err := sesh.GetVulnerabilityData(rootID, dbTypes.Filter{
173175
Contents: []dbTypes.FilterContentType{
174176
dbTypes.FilterContentTypeAdvisories,
@@ -178,6 +180,8 @@ func detect(sesh *session.Session, sr scanTypes.ScanResult) (detectTypes.DetectR
178180
Ecosystems: []ecosystemTypes.Ecosystem{d.Ecosystem},
179181
DataSources: slices.Collect(maps.Keys(d.Contents)),
180182
})
183+
for rootID, base := range detected {
184+
for d, err := range dbc.GetVulnerabilityData(dbTypes.SearchRoot, string(rootID)) {
181185
if err != nil {
182186
return detectTypes.DetectResult{}, xerrors.Errorf("Failed to get vulnerability data. RootID: %s, err: %w", rootID, err)
183187
}
@@ -494,6 +498,10 @@ func walkCriteria(e ecosystemTypes.Ecosystem, sourceID sourceTypes.SourceID, ca
494498

495499
switch fcn.Criterion.Version.Package.Type {
496500
case vcPackageTypes.PackageTypeBinary, vcPackageTypes.PackageTypeSource:
501+
if !cn.Criterion.Version.Vulnerable {
502+
continue
503+
}
504+
497505
rangeType, fixedIn := func() (vcAffectedRangeTypes.RangeType, string) {
498506
if fcn.Criterion.Version.Affected == nil {
499507
return vcAffectedRangeTypes.RangeTypeUnknown, ""
@@ -513,10 +521,21 @@ func walkCriteria(e ecosystemTypes.Ecosystem, sourceID sourceTypes.SourceID, ca
513521
if fcn.Criterion.Version.FixStatus == nil {
514522
return ""
515523
}
516-
return fixState(e, sourceID, fcn.Criterion.Version.FixStatus.Vendor)
524+
if s := fixState(e, sourceID, fcn.Criterion.Version.FixStatus.Vendor); s != "" {
525+
return s
526+
}
527+
if fcn.Criterion.Version.FixStatus.Class == fixstatus.ClassUnknown {
528+
return "Unknown"
529+
}
530+
return ""
531+
}(),
532+
FixedIn: fixedIn,
533+
NotFixedYet: func() bool {
534+
if cn.Criterion.Version.FixStatus == nil {
535+
return true
536+
}
537+
return cn.Criterion.Version.FixStatus.Class != fixstatus.ClassFixed
517538
}(),
518-
FixedIn: fixedIn,
519-
NotFixedYet: fixedIn == "",
520539
},
521540
})
522541
}

0 commit comments

Comments
 (0)