-
Notifications
You must be signed in to change notification settings - Fork 90
/
convert.go
105 lines (93 loc) · 2.78 KB
/
convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) Facebook, Inc. and its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package schema
import (
"strings"
nvd "github.com/facebookincubator/nvdtools/cvefeed/nvd/schema"
)
const (
cveDataVersion = "4.0"
)
func (item *Vulnerability) Convert() (*nvd.NVDCVEFeedJSON10DefCVEItem, error) {
nvdItem := nvd.NVDCVEFeedJSON10DefCVEItem{
CVE: &nvd.CVEJSON40{
CVEDataMeta: &nvd.CVEJSON40CVEDataMeta{
ID: item.ID(),
ASSIGNER: "fireeye",
},
DataFormat: "MITRE",
DataType: "CVE",
DataVersion: cveDataVersion,
Description: &nvd.CVEJSON40Description{
DescriptionData: []*nvd.CVEJSON40LangString{
{Lang: "en", Value: item.Title},
},
},
References: item.makeReferences(),
},
Configurations: item.makeConfigurations(),
Impact: &nvd.NVDCVEFeedJSON10DefImpact{
BaseMetricV2: &nvd.NVDCVEFeedJSON10DefImpactBaseMetricV2{
CVSSV2: &nvd.CVSSV20{
BaseScore: extractCVSSBaseScore(item),
TemporalScore: extractCVSSTemporalScore(item),
VectorString: extractCVSSVectorString(item),
},
},
},
LastModifiedDate: convertTime(item.PublishDate),
PublishedDate: convertTime(item.Version1PublishDate),
}
return &nvdItem, nil
}
func (item *Vulnerability) ID() string {
return "fireeye-" + item.ReportID
}
func (item *Vulnerability) makeReferences() *nvd.CVEJSON40References {
var refsData []*nvd.CVEJSON40Reference
addRef := func(name, url string) {
refsData = append(refsData, &nvd.CVEJSON40Reference{
Name: name,
URL: url,
})
}
addRef("FireEye report API link", item.ReportLink)
addRef("FireEye web link", item.WebLink)
for _, cve := range item.CVEIds {
for _, cveid := range strings.Split(cve, ",") {
addRef(cveid, "")
}
}
return &nvd.CVEJSON40References{
ReferenceData: refsData,
}
}
func (item *Vulnerability) makeConfigurations() *nvd.NVDCVEFeedJSON10DefConfigurations {
var matches []*nvd.NVDCVEFeedJSON10DefCPEMatch
for _, cpe := range extractCPEs(item) {
matches = append(matches, &nvd.NVDCVEFeedJSON10DefCPEMatch{
Cpe23Uri: cpe,
Vulnerable: true,
})
}
return &nvd.NVDCVEFeedJSON10DefConfigurations{
CVEDataVersion: cveDataVersion,
Nodes: []*nvd.NVDCVEFeedJSON10DefNode{
&nvd.NVDCVEFeedJSON10DefNode{
CPEMatch: matches,
Operator: "OR",
},
},
}
}