-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (94 loc) · 2.97 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
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/securityhub"
"github.com/common-nighthawk/go-figure"
)
func main() {
fmt.Println()
myFigure := figure.NewFigure("AWS SECOPS", "isometric1", true)
myFigure.Print()
fmt.Printf("\n\n")
awsRegion, awsKey, awsSecret := "", "", ""
awsRegion = os.Getenv("AWS_REGION")
awsKey = os.Getenv("AWS_ACCESS_KEY_ID")
awsSecret = os.Getenv("AWS_SECRET_ACCESS_KEY")
var awsSession *session.Session
if awsRegion != "" && awsKey != "" && awsSecret != "" {
//Read region and keys from env vars (mainly for docker mode)
sess, err := session.NewSession(&aws.Config{
Region: aws.String(awsRegion),
Credentials: credentials.NewStaticCredentials(awsKey, awsSecret, "")},
)
if err != nil {
fmt.Println("Got error initializing session:")
fmt.Println(err.Error())
return
}
awsSession = sess
} else {
//Read region and keys from ~/.aws/config and ~/.aws/credentials (for local usage)
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
awsSession = sess
}
lowVuln := 0
mediumVuln := 0
highVuln := 0
//Creating new security hub service session
svc := securityhub.New(awsSession)
initialToken := ""
orderField := "Title"
sortOrder := "ASC"
maxResultsPerCall := int64(100)
filter := securityhub.SortCriterion{Field: &orderField, SortOrder: &sortOrder}
var filterList []*securityhub.SortCriterion = []*securityhub.SortCriterion{&filter} //Order results by title asc
for {
// Retrieve SecurityHub Findings
input := &securityhub.GetFindingsInput{NextToken: &initialToken,
MaxResults: &maxResultsPerCall,
SortCriteria: filterList}
resp, err := svc.GetFindings(input)
if err != nil {
fmt.Println("Got error calling GetFindings:")
fmt.Println(err.Error())
return
}
for _, finding := range resp.Findings {
switch gravity := *finding.Severity.Original; gravity {
case "LOW":
lowVuln += 1
colored := fmt.Sprintf("\x1b[%dm%s\x1b[0m", 32, gravity)
fmt.Println("GRAVITY: ", colored)
case "MEDIUM":
mediumVuln += 1
colored := fmt.Sprintf("\x1b[%dm%s\x1b[0m", 33, gravity)
fmt.Println("GRAVITY: ", colored)
case "HIGH":
highVuln += 1
colored := fmt.Sprintf("\x1b[%dm%s\x1b[0m", 31, gravity)
fmt.Println("GRAVITY: ", colored)
default:
lowVuln += 1
colored := fmt.Sprintf("\x1b[%dm%s\x1b[0m", 32, "LOW")
fmt.Println("GRAVITY: ", colored)
}
fmt.Printf("[%v]\n%v%v ===> %v\n\n", *finding.Title, *finding.Description,
*finding.Remediation.Recommendation.Text, *finding.Remediation.Recommendation.Url)
}
if resp.NextToken != nil {
initialToken = *resp.NextToken
} else {
initialToken = ""
}
if initialToken == "" {
break
}
}
fmt.Printf("\n\nVULNERABILITY RECAP: FOUND %v LOW, %v MEDIUM AND %v HIGH\n\n", lowVuln, mediumVuln, highVuln)
}