This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.go
69 lines (57 loc) · 1.86 KB
/
functions.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
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"time"
)
var httpClient = &http.Client{Timeout: 10 * time.Second}
var cveResponse = new(cveResponseTemplate)
func getJSON(cve string, target interface{}) error {
url := "https://services.nvd.nist.gov/rest/json/cve/1.0/"
cveurl := url + cve
r, err := httpClient.Get(cveurl)
if err != nil {
return err
}
defer r.Body.Close()
return json.NewDecoder(r.Body).Decode(target)
}
//TODO
//func options() {
// cweFlag := flag.Bool("cwe", false, "Display CWE")
// cveFlag := flag.Bool("cve", false, "Display CVE")
//
// flag.Parse()
//
//}
func printCwes() {
Cwe := ("CWE not assigned")
for i := 0; i < len(cveResponse.Result.CVEItems[0].Cve.Problemtype.ProblemtypeData[0].Description); i++ {
Cwe = cveResponse.Result.CVEItems[0].Cve.Problemtype.ProblemtypeData[0].Description[i].Value
fmt.Printf("CWE: %+v\n", Cwe)
}
}
func printInfo() {
if len(cveResponse.Result.CVEItems) <= 0 {
err := fmt.Errorf("CVE was not found")
fmt.Println(err.Error())
os.Exit(1)
}
cve := cveResponse.Result.CVEItems[0].Cve.CVEDataMeta.ID
// Cwes := ("CWE not assigned")
// if len(cveResponse.Result.CVEItems[0].Cve.Problemtype.ProblemtypeData[0].Description) >= 0 {
// Cwes = cveResponse.Result.CVEItems[0].Cve.Problemtype.ProblemtypeData[0].Description[0:]
// }
cvss3Score := cveResponse.Result.CVEItems[0].Impact.BaseMetricV3.CvssV3.BaseScore
cvss3String := cveResponse.Result.CVEItems[0].Impact.BaseMetricV3.CvssV3.VectorString
publishedDate := cveResponse.Result.CVEItems[0].PublishedDate
description := cveResponse.Result.CVEItems[0].Cve.Description.DescriptionData[0].Value
fmt.Printf("\nCVE: %+v\n", cve)
//fmt.Printf("CWEs: %+v\n", Cwes)
printCwes()
fmt.Printf("CVSS3: %+v/%+v\n", cvss3Score, cvss3String)
fmt.Printf("Public Date: %+v\n", publishedDate)
fmt.Printf("Description: \n\n %+v\n\n", description)
}