Created
March 30, 2023 12:20
-
-
Save yosignals/51577e5d4583264adfef8f2625a28039 to your computer and use it in GitHub Desktop.
Generate random CVSS 3.1 vector strings
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
package main | |
import ( | |
"flag" | |
"fmt" | |
"math/rand" | |
"strings" | |
"time" | |
) | |
const ( | |
cvssBase = "CVSS:3.1/" | |
) | |
func main() { | |
rand.Seed(time.Now().UnixNano()) | |
numVectors := flag.Int("n", 1, "Number of CVSS 3.1 vectors to generate") | |
flag.Parse() | |
for i := 0; i < *numVectors; i++ { | |
fmt.Println(generateCVSSVector()) | |
} | |
} | |
func generateCVSSVector() string { | |
var sb strings.Builder | |
sb.WriteString(cvssBase) | |
sb.WriteString("AV:") | |
sb.WriteString(getRandomElem([]string{"N", "A", "L", "P"})) | |
sb.WriteString("/AC:") | |
sb.WriteString(getRandomElem([]string{"L", "H"})) | |
sb.WriteString("/PR:") | |
sb.WriteString(getRandomElem([]string{"N", "L", "H"})) | |
sb.WriteString("/UI:") | |
sb.WriteString(getRandomElem([]string{"N", "R"})) | |
sb.WriteString("/S:") | |
sb.WriteString(getRandomElem([]string{"U", "C"})) | |
sb.WriteString("/C:") | |
sb.WriteString(getRandomElem([]string{"N", "L", "H"})) | |
sb.WriteString("/I:") | |
sb.WriteString(getRandomElem([]string{"N", "L", "H"})) | |
sb.WriteString("/A:") | |
sb.WriteString(getRandomElem([]string{"N", "L", "H"})) | |
return sb.String() | |
} | |
func getRandomElem(arr []string) string { | |
return arr[rand.Intn(len(arr))] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment