vulndb

package
v0.0.0-...-e85a4bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package vulndb provides an API to the vulnerability database.

Index

Constants

View Source
const TimeLayout = nvd.TimeLayout

TimeLayout is the layout of NVD CVE JSON timestamps.

Variables

This section is empty.

Functions

func InitSchemaSQL

func InitSchemaSQL(ctx context.Context, db *sql.DB) error

InitSchemaSQL is auto-generated. Executes each SQL statement from schema.sql.

func ParseTime

func ParseTime(s string) (time.Time, error)

ParseTime parses s using TimeLayout.

func SchemaSQL

func SchemaSQL() []string

SchemaSQL is auto-generated. Returns each SQL statement from schema.sql.

Types

type CustomDataDeleter

type CustomDataDeleter struct {
	DB         *sql.DB
	Provider   string
	FilterCVEs []string
}

CustomDataDeleter is a helper for deleting custom data.

func (CustomDataDeleter) Delete

func (o CustomDataDeleter) Delete(ctx context.Context) error

Delete deletes custom data from the database.

type CustomDataExporter

type CustomDataExporter struct {
	DB         *sql.DB
	Provider   string
	FilterCVEs []string
}

CustomDataExporter is a helper for exporting custom data.

func (CustomDataExporter) CSV

func (o CustomDataExporter) CSV(ctx context.Context, w io.Writer, header bool) error

CSV writes custom data records to w.

func (CustomDataExporter) JSON

func (o CustomDataExporter) JSON(ctx context.Context, w io.Writer, indent string) error

JSON writes NVD CVE JSON to w.

type CustomDataImporter

type CustomDataImporter struct {
	DB       *sql.DB
	Owner    string
	Provider string
}

CustomDataImporter is a helper for importing custom data.

func (CustomDataImporter) ImportFile

func (o CustomDataImporter) ImportFile(ctx context.Context, name string) error

ImportFile imports NVD CVE JSON 1.0 optionally gzipped from file.

func (CustomDataImporter) ImportJSON

func (o CustomDataImporter) ImportJSON(ctx context.Context, r io.Reader) error

ImportJSON imports NVD CVE JSON 1.0 optionally gzipped.

type CustomDataRecord

type CustomDataRecord struct {
	Owner     string    `sql:"owner"`
	Provider  string    `sql:"provider"`
	CVE       string    `sql:"cve_id"`
	Published time.Time `sql:"published"`
	Modified  time.Time `sql:"modified"`
	BaseScore float64   `sql:"base_score"`
	Summary   string    `sql:"summary"`
	JSON      []byte    `sql:"cve_json"`
}

CustomDataRecord represents a db record of the `custom_data` table.

type DataExporter

type DataExporter struct {
	DB              *sql.DB
	FilterProviders []string
	FilterCVEs      []string
}

DataExporter is a helper for exporting vulnerability records from the db.

func (DataExporter) CSV

func (exp DataExporter) CSV(ctx context.Context, w io.Writer, header bool) error

CSV exports data to w.

func (DataExporter) JSON

func (exp DataExporter) JSON(ctx context.Context, w io.Writer, indent string) error

JSON exports NVD CVE JSON to w.

type SnoozeCreator

type SnoozeCreator struct {
	DB        *sql.DB
	Owner     string
	Collector string
	Provider  string
	Deadline  time.Time
	Metadata  []byte
}

SnoozeCreator is a helper for creating snoozes.

func (SnoozeCreator) Create

func (s SnoozeCreator) Create(ctx context.Context, cve ...string) error

Create creates a snooze.

type SnoozeDeleter

type SnoozeDeleter struct {
	DB         *sql.DB
	Collector  string
	Provider   string
	FilterCVEs []string
}

SnoozeDeleter deletes snoozes from the database.

func (SnoozeDeleter) Delete

func (s SnoozeDeleter) Delete(ctx context.Context) error

Delete deletes snooze data from the database.

type SnoozeGetter

type SnoozeGetter struct {
	DB         *sql.DB
	Collector  string
	Provider   string
	FilterCVEs []string
}

SnoozeGetter gets data from the database.

func (SnoozeGetter) CSV

func (s SnoozeGetter) CSV(ctx context.Context, w io.Writer, header bool) error

CSV writes snooze records to w.

type SnoozeRecord

type SnoozeRecord struct {
	Owner     string           `sql:"owner"`
	Collector string           `sql:"collector"`
	Provider  string           `sql:"provider"`
	CVE       string           `sql:"cve_id"`
	Deadline  sqlutil.NullTime `sql:"deadline"`
	Metadata  []byte           `sql:"metadata"`
}

SnoozeRecord represents a database record of the `snooze` table.

type SummaryExporter

type SummaryExporter struct {
	DB *sql.DB
}

SummaryExporter is a helper for exporting database summary.

func (SummaryExporter) CSV

func (exp SummaryExporter) CSV(ctx context.Context, w io.Writer, header bool) error

CSV writes summary records to w.

func (SummaryExporter) SummaryRecords

func (exp SummaryExporter) SummaryRecords(ctx context.Context) ([]SummaryRecord, error)

SummaryRecords retrieves the summary from the DB and returns it as a list of records

type SummaryRecord

type SummaryRecord struct {
	DataType  string    `sql:"data_type"`
	Provider  string    `sql:"provider"`
	Version   string    `sql:"version"`
	CVEs      int64     `sql:"cves"`
	Published time.Time `sql:"published"`
	Modified  time.Time `sql:"modified"`
}

SummaryRecord represents a record of the `summary` query

type VendorDataExporter

type VendorDataExporter struct {
	DB         *sql.DB
	Provider   string
	FilterCVEs []string
}

VendorDataExporter is a helper for exporting vendor data.

func (VendorDataExporter) CSV

func (v VendorDataExporter) CSV(ctx context.Context, w io.Writer, header bool) error

CSV writes vendor data records to w.

func (VendorDataExporter) JSON

func (v VendorDataExporter) JSON(ctx context.Context, w io.Writer, indent string) error

JSON writes NVD CVE JSON to w.

type VendorDataImporter

type VendorDataImporter struct {
	DB       *sql.DB
	Owner    string
	Provider string
	OnFile   func(filename string)
}

VendorDataImporter is a helper for importing an entire dataset from multiple files.

func (VendorDataImporter) ImportFiles

func (v VendorDataImporter) ImportFiles(ctx context.Context, files ...string) (*VendorRecord, error)

ImportFiles creates a new dataset version and imports all files into it Files must be formatted as NVD CVE JSON 1.0 optionally gzipped.

type VendorDataRecord

type VendorDataRecord struct {
	Version   int64     `sql:"version"`
	CVE       string    `sql:"cve_id"`
	Published time.Time `sql:"published"`
	Modified  time.Time `sql:"modified"`
	BaseScore float64   `sql:"base_score"`
	Summary   string    `sql:"summary"`
	JSON      []byte    `sql:"cve_json"`
}

VendorDataRecord represents a db record of the `vendor_data` table.

func VendorDataFromFile

func VendorDataFromFile(vendor *VendorRecord, name string) ([]VendorDataRecord, error)

VendorDataFromFile loads vendor data from NVD CVE JSON files.

type VendorDataTrimmer

type VendorDataTrimmer struct {
	DB                  *sql.DB
	FilterProviders     []string
	DeleteLatestVersion bool // TODO: support keeping up to N versions
}

VendorDataTrimmer is a helper for trimming vendor data.

It deletes all versions but the latest.

Deleting would be easier in common scenarions, but we have some hard constraints:

  • Vendor data is versioned
  • No foreign key between vendor_data and vendor tables
  • MySQL in safe mode forbids deleting from SELECT queries, wants values
  • Must keep the binlog smaller than 500M, not enough for the NVD database

Therefore, deletion works as follows:

  • Select versions from the vendor table based on the provided settings
  • Operate on vendor records with ready=true or older versions
  • By default, delete all versions but the latest, for each provider
  • Delete from vendor table first, effectively making data records orphans
  • Delete any orphan records from vendor_data, effectively crowd sourcing deletions
  • Delete data in chunks, keeping binlog small

Deletion operations are expensive.

func (VendorDataTrimmer) Trim

func (v VendorDataTrimmer) Trim(ctx context.Context) error

Trim deletes vendor data versions from the database.

type VendorRecord

type VendorRecord struct {
	Version  int64     `sql:"version"`
	TS       time.Time `sql:"ts"`
	Ready    bool      `sql:"ready"`
	Owner    string    `sql:"owner"`
	Provider string    `sql:"provider"`
}

VendorRecord represents a db record of the `vendor` table.

Directories

Path Synopsis
Package debug provides debugging utilities.
Package debug provides debugging utilities.
Package mysql provides a connector to vulndb via MySQL.
Package mysql provides a connector to vulndb via MySQL.
Package sqlutil provides utilities for database/sql for dealing with SQL queries and database records.
Package sqlutil provides utilities for database/sql for dealing with SQL queries and database records.
b64schema
b64schema converts a SQL schema file into base64 encoded strings as Go code.
b64schema converts a SQL schema file into base64 encoded strings as Go code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL