Thanks to visit codestin.com
Credit goes to github.com

Skip to content

vulncheck-oss/sdk-go-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VulnCheck Logo

The VulnCheck SDK For Go

Bring the VulnCheck API to your Go applications.

Installation

go get github.com/vulncheck-oss/sdk-go-v2/v2

Examples

Connecting to the API

package main

import (
  "context"
  "fmt"
  "log"
  "os"

  vulncheck "github.com/vulncheck-oss/sdk-go-v2/v2"
)

func main() {
  configuration := vulncheck.NewConfiguration()
  configuration.Scheme = "https"
  configuration.Host = "api.vulncheck.com"

  client := vulncheck.NewAPIClient(configuration)

  token := os.Getenv("VULNCHECK_API_TOKEN")
  auth := context.WithValue(
    context.Background(),
    vulncheck.ContextAPIKeys,
    map[string]vulncheck.APIKey{
    "Bearer": {Key: token},
    },
  )
  resp, httpRes, err := client.EndpointsAPI.OpenapiGet(auth).Execute()

  if err != nil || httpRes.StatusCode != 200 {
    log.Fatal(err)
  }

  fmt.Printf("%+v", resp)
}

Available Methods

PURL

Get the CVE's for a given PURL

req := client.EndpointsAPI.PurlGet(auth).Purl("pkg:hex/[email protected]")
resp, httpRes, err := req.Execute()
if err != nil {
  log.Fatal(err)
}

data := resp.GetData()

fmt.Println(data.GetCves())

CPE

Get all CPE's related to a CVE

req := client.EndpointsAPI.CpeGet(auth).Cpe("cpe:/a:microsoft:internet_explorer:8.0.6001:beta")
resp, httpRes, err := req.Execute()
if err != nil {
  log.Fatal(err)
}

for _, v := range resp.GetData() {
  fmt.Println(v)
}

Backup

Download the backup for an index

req := client.EndpointsAPI.BackupIndexGet(auth, "initial-access")
resp, httpRes, err := req.Execute()
if err != nil {
  log.Fatal(err)
}

data := resp.GetData()

for _, v := range data {
  fmt.Println(v.GetUrl())
}

Indices

Get all available indices

req := client.EndpointsAPI.IndexGet(auth)
resp, httpRes, err := req.Execute()
if err != nil {
  log.Fatal(err)
}

for _, v := range resp.GetData() {
  fmt.Println(v.GetName())
}

Index

Query VulnCheck-NVD2 for CVE-2019-19781

req := client.
  IndicesAPI.
  IndexVulncheckNvd2Get(auth).
  Cve("CVE-2019-19781")

resp, _, err := req.Execute()
if err != nil {
  log.Fatal(err)
}

vuln := resp.GetData()[0]

fmt.Printf("Name: %q\n", vuln.GetCisaVulnerabilityName())

descriptions := vuln.GetDescriptions()
for _, desc := range descriptions {
  if desc.GetLang() == "en" {
    fmt.Printf("Description: %s\n", desc.GetValue())
  }
}

if metrics, ok := vuln.GetMetricsOk(); !ok {
  fmt.Println("")
} else {
  fmt.Printf("Base Score: %f\n", metrics.CvssMetricV31[0].CvssData.GetBaseScore())
}

Pagination

Paginate over results for a query to VulnCheck-KEV using cursor

var queryLimit int32 = 300
req := client.
  IndicesAPI.
  IndexVulncheckKevGet(auth).
  StartCursor("true").
  Limit(queryLimit)

resp, httpRes, err := req.Execute()
if err != nil {
  log.Fatal(err)
}

var nextCursor string
var count int
var total int32

nextCursor = resp.Meta.GetNextCursor()
total = resp.Meta.GetTotalDocuments()
count += len(resp.Data)
fmt.Printf("Total Items: %d/%d\n", count, total)

count += len(resp.Data)

for range 10 {
  req := client.
    IndicesAPI.
    IndexVulncheckKevGet(auth).
    Cursor(nextCursor).
    Limit(queryLimit)

  resp, httpRes, err := req.Execute()
  if err != nil {
    log.Fatal(err)
  }

  nextCursor = resp.Meta.GetNextCursor()
  count += len(resp.Data)
  fmt.Printf("Total Items: %d/%d\n", count, total)
}

License

Apache License 2.0. Please see License File for more information.

About

A generated Go SDK from VulnCheck's OpenAPI specification

Topics

Resources

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •