-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(nvd): use struct from nvd api 2.0 (#78)
* refactor: use struct from nvd api 2.0 * refactor: use only NVD cvss metrics
- Loading branch information
1 parent
f0d3519
commit a509330
Showing
6 changed files
with
472 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,7 @@ func generateVulnPages() { | |
wg.Add(1) | ||
|
||
log.Printf("generating vuln year: %s\n", year) | ||
nvdDir := fmt.Sprintf("vuln-list-nvd/feed/%s/", year) | ||
nvdDir := fmt.Sprintf("vuln-list-nvd/api/%s/", year) | ||
cweDir := "vuln-list/cwe" | ||
|
||
go func(year string) { | ||
|
@@ -405,35 +405,50 @@ func parseVulnerabilityJSONFile(fileName string) (VulnerabilityPost, error) { | |
if err != nil { | ||
return VulnerabilityPost{}, err | ||
} | ||
vuln.Description = strings.NewReplacer(`"`, ``, `\`, ``, `'`, ``).Replace(string(v.GetStringBytes("cve", "description", "description_data", "0", "value"))) | ||
vuln.ID = string(v.GetStringBytes("cve", "CVE_data_meta", "ID")) | ||
vuln.CWEID = string(v.GetStringBytes("cve", "problemtype", "problemtype_data", "0", "description", "0", "value")) | ||
vuln.CVSS = CVSS{ | ||
V2Vector: string(v.GetStringBytes("impact", "baseMetricV2", "cvssV2", "vectorString")), | ||
V2Score: v.GetFloat64("impact", "baseMetricV2", "cvssV2", "baseScore"), | ||
V3Vector: string(v.GetStringBytes("impact", "baseMetricV3", "cvssV3", "vectorString")), | ||
V3Score: v.GetFloat64("impact", "baseMetricV3", "cvssV3", "baseScore"), | ||
vuln.Description = strings.NewReplacer(`"`, ``, `\`, ``, `'`, ``).Replace(string(v.GetStringBytes("descriptions", "0", "value"))) | ||
vuln.ID = string(v.GetStringBytes("id")) | ||
if cwe := string(v.GetStringBytes("weaknesses", "0", "description", "0", "value")); cwe != "NVD-CWE-noinfo" { | ||
vuln.CWEID = cwe | ||
} | ||
|
||
vuln.NVDSeverityV2 = string(v.GetStringBytes("impact", "baseMetricV2", "severity")) | ||
vuln.NVDSeverityV3 = string(v.GetStringBytes("impact", "baseMetricV3", "cvssV3", "baseSeverity")) | ||
for _, metricV2 := range v.GetArray("metrics", "cvssMetricV2") { | ||
source := string(metricV2.GetStringBytes("source")) | ||
// Save only NVD metric | ||
if source == "[email protected]" { | ||
vuln.CVSS.V2Score = metricV2.GetFloat64("cvssData", "baseScore") | ||
vuln.CVSS.V2Vector = string(metricV2.GetStringBytes("cvssData", "vectorString")) | ||
vuln.NVDSeverityV2 = string(metricV2.GetStringBytes("baseSeverity")) | ||
} | ||
} | ||
|
||
// Save NVD metric from v3.1, | ||
// if it doesn't exist - save NVD metric from v3.0 | ||
for _, metricV3 := range append(v.GetArray("metrics", "cvssMetricV31"), v.GetArray("metrics", "cvssMetricV30")...) { | ||
source := string(metricV3.GetStringBytes("source")) | ||
// Save only NVD metric | ||
if source == "[email protected]" { | ||
vuln.CVSS.V3Score = metricV3.GetFloat64("cvssData", "baseScore") | ||
vuln.CVSS.V3Vector = string(metricV3.GetStringBytes("cvssData", "vectorString")) | ||
vuln.NVDSeverityV3 = string(metricV3.GetStringBytes("cvssData", "baseSeverity")) | ||
} | ||
} | ||
|
||
publishedDate, _ := time.Parse("2006-01-02T04:05Z", string(v.GetStringBytes("publishedDate"))) | ||
modifiedDate, _ := time.Parse("2006-01-02T04:05Z", string(v.GetStringBytes("lastModifiedDate"))) | ||
publishedDate, _ := time.Parse("2006-01-02T15:04:05", string(v.GetStringBytes("published"))) | ||
modifiedDate, _ := time.Parse("2006-01-02T15:04:05", string(v.GetStringBytes("lastModified"))) | ||
vuln.Dates = Dates{ | ||
Published: publishedDate.UTC().Format("2006-01-02 03:04:05 -0700"), | ||
Modified: modifiedDate.UTC().Format("2006-01-02 03:04:05 -0700"), | ||
} | ||
|
||
var refs []string | ||
for _, r := range v.GetArray("cve", "references", "reference_data") { | ||
for _, r := range v.GetArray("references") { | ||
refs = append(refs, strings.ReplaceAll(r.Get("url").String(), `"`, ``)) | ||
} | ||
vuln.References = refs | ||
|
||
affectedSoftwares := v.GetArray("configurations", "nodes", "0", "cpe_match") // TODO: This logic should be improved to iterate over list of lists | ||
affectedSoftwares := v.GetArray("configurations", "0", "nodes", "0", "cpeMatch") // TODO: This logic should be improved to iterate over list of lists | ||
for _, as := range affectedSoftwares { | ||
uri := string(as.GetStringBytes("cpe23Uri")) | ||
uri := string(as.GetStringBytes("criteria")) | ||
item, err := cpe.NewItemFromFormattedString(uri) | ||
if err != nil { | ||
continue | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.