Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to make Windows CVE analyzed #8

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions gost/microsoft.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (ms Microsoft) DetectCVEs(r *models.ScanResult, _ bool) (nCVEs int, err err
applied = r.WindowsKB.Applied
unapplied = r.WindowsKB.Unapplied
}
supersedMap := make(map[string][]string)
if ms.driver == nil {
u, err := util.URLPathJoin(ms.baseURL, "microsoft", "kbs")
if err != nil {
Expand Down Expand Up @@ -70,6 +71,16 @@ func (ms Microsoft) DetectCVEs(r *models.ScanResult, _ bool) (nCVEs int, err err
applied = r.Applied
unapplied = r.Unapplied
} else {

for _, unap := range unapplied {
var superSed []string
_, superSed, _ = ms.driver.GetExpandKB(nil, []string{unap})
for _, supers := range superSed {
supersedMap[supers] = append(supersedMap[supers], unap)
}

}
logging.Log.Infof("cve Id %+v", supersedMap)
applied, unapplied, err = ms.driver.GetExpandKB(applied, unapplied)
if err != nil {
return 0, xerrors.Errorf("Failed to detect CVEs. err: %w", err)
Expand Down Expand Up @@ -234,7 +245,9 @@ func (ms Microsoft) DetectCVEs(r *models.ScanResult, _ bool) (nCVEs int, err err

cveCont, mitigations := ms.ConvertToModel(&cve)
uniqKB := map[string]struct{}{}
kbFound := []string{}
var stats models.PackageFixStatuses

for _, p := range cve.Products {
for _, kb := range p.KBs {
if _, err := strconv.Atoi(kb.Article); err != nil {
Expand All @@ -248,16 +261,25 @@ func (ms Microsoft) DetectCVEs(r *models.ScanResult, _ bool) (nCVEs int, err err
if kb.FixedBuild == "" {
s.FixState = "unknown"
}

stats = append(stats, s)
default:
stats = append(stats, models.PackageFixStatus{
Name: p.Name,
FixState: "unknown",
FixedIn: kb.FixedBuild,
})

}
} else {

stats = append(stats, models.PackageFixStatus{
Name: p.Name,
FixState: "fixed",
FixedIn: kb.Article,
})
uniqKB[fmt.Sprintf("KB%s", kb.Article)] = struct{}{}
kbFound = append(kbFound, supersedMap[kb.Article]...)
}
}
}
Expand Down Expand Up @@ -295,6 +317,7 @@ func (ms Microsoft) DetectCVEs(r *models.ScanResult, _ bool) (nCVEs int, err err
Mitigations: mitigations,
AffectedPackages: stats,
WindowsKBFixedIns: maps.Keys(uniqKB),
WindowsKBFound: kbFound,
}
}
return nCVEs, nil
Expand Down
1 change: 1 addition & 0 deletions models/vulninfos.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ type VulnInfo struct {
WindowsKBFixedIns []string `json:"windowsKBFixedIns,omitempty"`
VulnType string `json:"vulnType,omitempty"`
DiffStatus DiffStatus `json:"diffStatus,omitempty"`
WindowsKBFound []string `json:"windowsKBFound,omitempty"`
}

// Alert has CERT alert information
Expand Down
4 changes: 2 additions & 2 deletions oval/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type defPacks struct {

type fixStat struct {
notFixedYet bool
fixState string
fixState string
fixedIn string
isSrcPack bool
srcPackName string
Expand All @@ -56,7 +56,7 @@ func (e defPacks) toPackStatuses() (ps models.PackageFixStatuses) {
ps = append(ps, models.PackageFixStatus{
Name: name,
NotFixedYet: stat.notFixedYet,
FixState: stat.fixState,
FixState: stat.fixState,
FixedIn: stat.fixedIn,
VersionFound: stat.versionFound,
})
Expand Down
Loading