/
main.go
104 lines (83 loc) · 2.52 KB
/
main.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
package main
import (
"log"
v1 "github.com/thought-machine/dracon/api/proto/v1"
"github.com/thought-machine/dracon/producers"
securityhub "github.com/aws/aws-sdk-go-v2/service/securityhub/types"
)
func main() {
if err := producers.ParseFlags(); err != nil {
log.Fatal(err)
}
inFile, err := producers.ReadInFile()
if err != nil {
log.Fatal(err)
}
var results securityHubFindings
if err := producers.ParseJSON(inFile, &results); err != nil {
log.Fatal(err)
}
issues := parseIssues(&results)
if err := producers.WriteDraconOut("securityhub", issues); err != nil {
log.Fatal(err)
}
}
type securityHubFindings struct {
Findings []securityhub.AwsSecurityFinding `json:"Findings"`
}
func parseIssues(shf *securityHubFindings) []*v1.Issue {
severityMap := map[securityhub.SeverityLabel]v1.Severity{
securityhub.SeverityLabelInformational: v1.Severity_SEVERITY_INFO,
securityhub.SeverityLabelLow: v1.Severity_SEVERITY_LOW,
securityhub.SeverityLabelMedium: v1.Severity_SEVERITY_MEDIUM,
securityhub.SeverityLabelHigh: v1.Severity_SEVERITY_HIGH,
securityhub.SeverityLabelCritical: v1.Severity_SEVERITY_CRITICAL,
}
issues := make([]*v1.Issue, len(shf.Findings))
for i, r := range shf.Findings {
issue := &v1.Issue{Confidence: v1.Confidence_CONFIDENCE_MEDIUM}
if r.Title != nil {
issue.Title = *r.Title
}
if r.Description != nil {
issue.Description = *r.Description
}
if r.SourceUrl != nil {
issue.Source = *r.SourceUrl
}
switch {
case r.ProductName != nil && *r.ProductName == "Inspector" && len(r.Resources) > 0:
if r.Resources[0].Details != nil && r.Resources[0].Details.AwsEc2Instance != nil {
issue.Target = *r.Resources[0].Details.AwsEc2Instance.ImageId
}
case len(r.Resources) > 0:
issue.Target = *r.Resources[0].Id
case r.AwsAccountId != nil:
issue.Target = *r.AwsAccountId
}
switch {
case len(r.Types) > 0:
issue.Type = r.Types[0]
case r.ProductName != nil:
issue.Type = *r.ProductName
}
switch {
case r.Severity != nil:
issue.Severity = severityMap[r.Severity.Label]
case r.FindingProviderFields != nil && r.FindingProviderFields.Severity != nil:
issue.Severity = severityMap[r.FindingProviderFields.Severity.Label]
}
if len(r.Vulnerabilities) > 0 {
issue.Cve = *r.Vulnerabilities[0].Id
highestCvss := 0.0
for _, cvss := range r.Vulnerabilities[0].Cvss {
if cvss.BaseScore > highestCvss {
highestCvss = cvss.BaseScore
}
}
issue.Cvss = highestCvss
}
issues[i] = issue
}
return issues
}