Documentation
¶
Overview ¶
Package vulners provides a Go client for the Vulners vulnerability database API.
Basic usage:
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
results, err := client.Search().SearchBulletins(ctx, "cve-2021-44228")
if err != nil {
log.Fatal(err)
}
The client supports functional options for customization:
client, err := vulners.NewClient("your-api-key",
vulners.WithTimeout(60 * time.Second),
vulners.WithRetries(5),
)
Example (ErrorHandling) ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Handle errors appropriately
_, err = client.Search().GetBulletin(ctx, "NONEXISTENT-CVE")
if err != nil {
switch {
case errors.Is(err, vulners.ErrNotFound):
fmt.Println("Bulletin not found")
case errors.Is(err, vulners.ErrRateLimited):
fmt.Println("Rate limit exceeded, retry later")
case errors.Is(err, vulners.ErrUnauthorized):
fmt.Println("Invalid API key")
default:
// Check for API errors with status codes
var apiErr *vulners.APIError
if errors.As(err, &apiErr) {
fmt.Printf("API error %d: %s\n", apiErr.StatusCode, apiErr.Message)
}
}
}
Index ¶
- Constants
- Variables
- type AIScore
- type APIError
- type AffectedSoftware
- type ArchiveService
- type AuditItem
- type AuditOption
- type AuditReason
- type AuditResult
- type AuditService
- func (s *AuditService) GetSupportedOS(ctx context.Context) ([]string, error)
- func (s *AuditService) Host(ctx context.Context, os, osVersion string, packages []AuditItem, ...) (*SoftwareAuditResult, error)
- func (s *AuditService) KBAudit(ctx context.Context, os string, kbList []string, opts ...AuditOption) (*AuditResult, error)
- func (s *AuditService) LinuxAudit(ctx context.Context, osName, osVersion string, packages []string, ...) (*AuditResult, error)
- func (s *AuditService) SBOMAudit(ctx context.Context, r io.Reader, opts ...AuditOption) (*SBOMAuditResult, error)
- func (s *AuditService) Software(ctx context.Context, software []AuditItem, opts ...AuditOption) (*SoftwareAuditResult, error)
- func (s *AuditService) WinAudit(ctx context.Context, os, osVersion string, kbList []string, ...) (*AuditResult, error)
- type AuditVuln
- type Bulletin
- type CPEOption
- type CPEResult
- type CPESearchResult
- type CVSS
- type CVSS3
- type Client
- func (c *Client) Archive() *ArchiveService
- func (c *Client) Audit() *AuditService
- func (c *Client) Misc() *MiscService
- func (c *Client) Report() *ReportService
- func (c *Client) Search() *SearchService
- func (c *Client) Stix() *StixService
- func (c *Client) Subscription() *SubscriptionService
- func (c *Client) Webhook() *WebhookService
- type CollectionType
- type EnchantmentsScore
- type Epss
- type Exploitation
- type ExploitationSource
- type HistoryEntry
- type HostVuln
- type IPSummary
- type LinuxAuditRequest
- type MiscService
- func (s *MiscService) GetAIScore(ctx context.Context, text string) (*AIScore, error)
- func (s *MiscService) GetSuggestion(ctx context.Context, fieldName string) ([]string, error)
- func (s *MiscService) QueryAutocomplete(ctx context.Context, query string) ([]string, error)
- func (s *MiscService) SearchCPE(ctx context.Context, product, vendor string, opts ...CPEOption) (*CPESearchResult, error)
- type Option
- func WithAllowInsecure() Option
- func WithBaseURL(baseURL string) Option
- func WithHTTPClient(client *http.Client) Option
- func WithProxy(proxyURL string) Option
- func WithRateLimit(rate float64, burst int) Option
- func WithRetries(maxRetries int) Option
- func WithTimeout(timeout time.Duration) Option
- func WithUserAgent(userAgent string) Option
- type RateLimiter
- type ReportOption
- type ReportService
- func (s *ReportService) HostVulns(ctx context.Context, opts ...ReportOption) ([]HostVuln, error)
- func (s *ReportService) IPSummaryReport(ctx context.Context, opts ...ReportOption) (*IPSummary, error)
- func (s *ReportService) ScanList(ctx context.Context, opts ...ReportOption) ([]ScanItem, error)
- func (s *ReportService) VulnsList(ctx context.Context, opts ...ReportOption) ([]VulnItem, error)
- func (s *ReportService) VulnsSummaryReport(ctx context.Context, opts ...ReportOption) (*VulnsSummary, error)
- type SBOMAdvisory
- type SBOMAuditResult
- type SBOMMetrics
- type SBOMPackageResult
- type ScanItem
- type SearchOption
- type SearchResult
- type SearchService
- func (s *SearchService) GetBulletin(ctx context.Context, id string, opts ...SearchOption) (*Bulletin, error)
- func (s *SearchService) GetBulletinHistory(ctx context.Context, id string) ([]HistoryEntry, error)
- func (s *SearchService) GetBulletinReferences(ctx context.Context, id string) ([]string, error)
- func (s *SearchService) GetMultipleBulletins(ctx context.Context, ids []string, opts ...SearchOption) (map[string]Bulletin, error)
- func (s *SearchService) SearchBulletins(ctx context.Context, query string, opts ...SearchOption) (*SearchResult, error)
- func (s *SearchService) SearchBulletinsAll(ctx context.Context, query string, opts ...SearchOption) ([]Bulletin, error)
- func (s *SearchService) SearchExploits(ctx context.Context, query string, opts ...SearchOption) (*SearchResult, error)
- type SoftwareAuditItem
- type SoftwareAuditResult
- type StixBundle
- type StixOption
- type StixService
- type Subscription
- type SubscriptionRequest
- type SubscriptionService
- func (s *SubscriptionService) Create(ctx context.Context, req *SubscriptionRequest) (*Subscription, error)
- func (s *SubscriptionService) Delete(ctx context.Context, id string) error
- func (s *SubscriptionService) Enable(ctx context.Context, id string, active bool) error
- func (s *SubscriptionService) Get(ctx context.Context, id string) (*Subscription, error)
- func (s *SubscriptionService) List(ctx context.Context) ([]Subscription, error)
- func (s *SubscriptionService) Update(ctx context.Context, id string, req *SubscriptionRequest) (*Subscription, error)
- type Time
- type VulnItem
- type Vulnerability
- type VulnsSummary
- type Webhook
- type WebhookData
- type WebhookService
- func (s *WebhookService) Add(ctx context.Context, query string) (*Webhook, error)
- func (s *WebhookService) Delete(ctx context.Context, id string) error
- func (s *WebhookService) Enable(ctx context.Context, id string, active bool) error
- func (s *WebhookService) GetByID(ctx context.Context, id string) (*Webhook, error)
- func (s *WebhookService) List(ctx context.Context) ([]Webhook, error)
- func (s *WebhookService) Read(ctx context.Context, id string, newestOnly bool) (*WebhookData, error)
- type WinAuditItem
Examples ¶
- Package (ErrorHandling)
- ArchiveService.FetchCollection
- ArchiveService.FetchCollectionUpdate
- AuditService.KBAudit
- AuditService.LinuxAudit
- AuditService.SBOMAudit
- MiscService.SearchCPE
- NewClient
- NewClient (WithOptions)
- ReportService.VulnsSummaryReport
- SearchService.GetBulletin
- SearchService.SearchBulletins
- SearchService.SearchExploits
- StixService.MakeBundleByID
- WebhookService.Add
Constants ¶
const DefaultFields = "id,title,description,type,bulletinFamily,cvss,published,modified,href,sourceHref,sourceData,cvelist"
DefaultFields is the default set of fields returned in search results.
Variables ¶
var ( // ErrAPIKeyRequired is returned when an API key is required but not provided. ErrAPIKeyRequired = errors.New("vulners: API key is required") // ErrInvalidInput is returned when a required parameter is missing or invalid. ErrInvalidInput = errors.New("vulners: invalid input") // ErrNotFound is returned when a requested resource is not found. ErrNotFound = errors.New("vulners: resource not found") // ErrRateLimited is returned when the rate limit has been exceeded. ErrRateLimited = errors.New("vulners: rate limit exceeded") ErrUnauthorized = errors.New("vulners: unauthorized - invalid or expired API key") // ErrBadRequest is returned when the request is malformed. ErrBadRequest = errors.New("vulners: bad request") // ErrServerError is returned when the server returns a 5xx error. ErrServerError = errors.New("vulners: server error") )
Sentinel errors for common error conditions.
Functions ¶
This section is empty.
Types ¶
type AIScore ¶
type AIScore struct {
Value float64 `json:"value,omitempty"`
Uncertainty float64 `json:"uncertainty,omitempty"`
}
AIScore represents AI-generated vulnerability scoring.
Fields match the SBOM audit endpoint response format: {"value": 10.0, "uncertainty": 0.1}.
type APIError ¶
type APIError struct {
// StatusCode is the HTTP status code.
StatusCode int `json:"statusCode,omitempty"`
// Message is the error message from the API.
Message string `json:"error,omitempty"`
// ErrorCode is an optional error code from the API.
ErrorCode string `json:"errorCode,omitempty"`
}
APIError represents an error response from the Vulners API.
func NewAPIError ¶
NewAPIError creates a new APIError with the given parameters.
type AffectedSoftware ¶
type AffectedSoftware struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Vendor string `json:"vendor,omitempty"`
CPE string `json:"cpe,omitempty"`
Operator string `json:"operator,omitempty"`
}
AffectedSoftware represents software affected by a vulnerability.
type ArchiveService ¶
type ArchiveService struct {
// contains filtered or unexported fields
}
ArchiveService provides methods for fetching vulnerability collections.
func (*ArchiveService) FetchCollection ¶
func (s *ArchiveService) FetchCollection(ctx context.Context, collType CollectionType) ([]Bulletin, error)
FetchCollection fetches all bulletins for a given collection type.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Fetch the entire CVE collection (use with caution - large dataset)
bulletins, err := client.Archive().FetchCollection(ctx, vulners.CollectionCVE)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Fetched %d CVE bulletins\n", len(bulletins))
func (*ArchiveService) FetchCollectionUpdate ¶
func (s *ArchiveService) FetchCollectionUpdate(ctx context.Context, collType CollectionType, after time.Time) ([]Bulletin, error)
FetchCollectionUpdate fetches bulletins updated after a given timestamp. The after parameter must be within the last 25 hours per API requirements.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Fetch CVEs updated in the last 24 hours
since := time.Now().Add(-24 * time.Hour)
bulletins, err := client.Archive().FetchCollectionUpdate(ctx, vulners.CollectionCVE, since)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d updated CVEs\n", len(bulletins))
type AuditItem ¶
type AuditItem struct {
Software string `json:"software"`
Version string `json:"version"`
Type string `json:"type,omitempty"`
}
AuditItem represents a software item for auditing.
type AuditOption ¶
type AuditOption func(*auditConfig)
AuditOption is a functional option for audit operations.
func WithIncludeCandidates ¶ added in v1.1.5
func WithIncludeCandidates(v bool) AuditOption
WithIncludeCandidates controls whether advisories still awaiting vendor evaluation are included in the results. The API default is true (include everything). Pass false to drop "needs evaluation" items.
type AuditReason ¶
type AuditReason struct {
Package string `json:"package,omitempty"`
ProvidedVersion string `json:"providedVersion,omitempty"`
BulletinVersion string `json:"bulletinVersion,omitempty"`
BulletinID string `json:"bulletinID,omitempty"`
Operator string `json:"operator,omitempty"`
CVEList []string `json:"cvelist,omitempty"`
}
AuditReason represents a reason for a vulnerability match.
type AuditResult ¶
type AuditResult struct {
Vulnerabilities []Vulnerability `json:"vulnerabilities,omitempty"`
Reasons []AuditReason `json:"reasons,omitempty"`
CVEList []string `json:"cvelist,omitempty"`
CVSSScore float64 `json:"cvss,omitempty"`
CumulativeFix string `json:"cumulativeFix,omitempty"`
ID string `json:"id,omitempty"`
}
AuditResult represents an audit response from the API.
type AuditService ¶
type AuditService struct {
// contains filtered or unexported fields
}
AuditService provides methods for vulnerability auditing.
func (*AuditService) GetSupportedOS ¶ added in v1.2.0
func (s *AuditService) GetSupportedOS(ctx context.Context) ([]string, error)
GetSupportedOS returns the list of operating system identifiers that are valid inputs for Linux-package audit requests.
func (*AuditService) Host ¶
func (s *AuditService) Host(ctx context.Context, os, osVersion string, packages []AuditItem, opts ...AuditOption) (*SoftwareAuditResult, error)
Host performs a host audit using the v4 API. It checks the OS and installed packages for vulnerabilities.
func (*AuditService) KBAudit ¶
func (s *AuditService) KBAudit(ctx context.Context, os string, kbList []string, opts ...AuditOption) (*AuditResult, error)
KBAudit performs a Windows KB audit. It checks installed Windows KB updates for vulnerabilities.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Audit Windows systems by installed KB updates
kbList := []string{
"KB5009586",
"KB5009624",
}
result, err := client.Audit().KBAudit(ctx, "Windows Server 2019", kbList)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d vulnerabilities\n", len(result.Vulnerabilities))
func (*AuditService) LinuxAudit ¶
func (s *AuditService) LinuxAudit(ctx context.Context, osName, osVersion string, packages []string, opts ...AuditOption) (*AuditResult, error)
LinuxAudit performs a Linux-specific audit. It checks packages installed on a Linux system for vulnerabilities.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Audit installed packages on a Linux system
packages := []string{
"openssl-1.1.1f-1ubuntu2",
"nginx-1.18.0-0ubuntu1",
}
result, err := client.Audit().LinuxAudit(ctx, "Ubuntu", "20.04", packages)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d CVEs\n", len(result.CVEList))
fmt.Printf("Maximum CVSS Score: %.1f\n", result.CVSSScore)
func (*AuditService) SBOMAudit ¶ added in v1.1.0
func (s *AuditService) SBOMAudit(ctx context.Context, r io.Reader, opts ...AuditOption) (*SBOMAuditResult, error)
SBOMAudit performs an SBOM-based audit by uploading an SBOM file. The reader r should provide the SBOM content in SPDX or CycloneDX JSON format (e.g., an os.File or bytes.Buffer).
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Open an SBOM file (SPDX or CycloneDX JSON format)
f, err := os.Open("sbom.spdx.json")
if err != nil {
log.Fatal(err)
}
defer func() { _ = f.Close() }()
result, err := client.Audit().SBOMAudit(ctx, f)
if err != nil {
log.Fatal(err)
}
for _, pkg := range result.Packages {
fmt.Printf("%s@%s: %d advisories\n", pkg.Package, pkg.Version, len(pkg.ApplicableAdvisories))
}
func (*AuditService) Software ¶
func (s *AuditService) Software(ctx context.Context, software []AuditItem, opts ...AuditOption) (*SoftwareAuditResult, error)
Software performs a software audit using the v4 API. It checks the provided software items for known vulnerabilities.
func (*AuditService) WinAudit ¶
func (s *AuditService) WinAudit(ctx context.Context, os, osVersion string, kbList []string, software []WinAuditItem, opts ...AuditOption) (*AuditResult, error)
WinAudit performs a comprehensive Windows audit. It checks both KB updates and installed software for vulnerabilities.
type AuditVuln ¶
type AuditVuln struct {
Package string `json:"package,omitempty"`
ProvidedVersion string `json:"providedVersion,omitempty"`
BulletinVersion string `json:"bulletinVersion,omitempty"`
ProvidedPackage string `json:"providedPackage,omitempty"`
BulletinPackage string `json:"bulletinPackage,omitempty"`
Operator string `json:"operator,omitempty"`
BulletinID string `json:"id,omitempty"`
CVEList []string `json:"cvelist,omitempty"`
Fix string `json:"fix,omitempty"`
CVSS *CVSS `json:"cvss,omitempty"`
}
AuditVuln represents a vulnerability found for a package.
type Bulletin ¶
type Bulletin struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
BulletinFamily string `json:"bulletinFamily,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Published *Time `json:"published,omitempty"`
Modified *Time `json:"modified,omitempty"`
CVSS *CVSS `json:"cvss,omitempty"`
CVSS2 *CVSS `json:"cvss2,omitempty"`
CVSS3 *CVSS3 `json:"cvss3,omitempty"`
CVEList []string `json:"cvelist,omitempty"`
Href string `json:"href,omitempty"`
SourceHref string `json:"sourceHref,omitempty"`
SourceData json.RawMessage `json:"sourceData,omitempty"`
Reporter string `json:"reporter,omitempty"`
References []string `json:"references,omitempty"`
Enchantments json.RawMessage `json:"enchantments,omitempty"`
Epss []Epss `json:"epss,omitempty"`
AffectedSoftware []AffectedSoftware `json:"affectedSoftware,omitempty"`
// Additional fields that may be present
Assigned *Time `json:"assigned,omitempty"`
VulnStatus string `json:"vulnStatus,omitempty"`
AI *AIScore `json:"ai,omitempty"`
CVSS4 *CVSS `json:"cvss4,omitempty"`
History []HistoryEntry `json:"history,omitempty"`
ObjectVersion string `json:"objectVersion,omitempty"`
LastSeenAt *Time `json:"lastseen,omitempty"`
// Search-result metadata (present only in search responses)
VHref string `json:"vhref,omitempty"`
ViewCount int `json:"viewCount,omitempty"`
SourceAvailable bool `json:"sourceAvailable,omitempty"`
}
Bulletin represents a vulnerability bulletin from the Vulners database.
func (*Bulletin) GetEnchantmentsScore ¶ added in v1.1.4
func (b *Bulletin) GetEnchantmentsScore() *EnchantmentsScore
GetEnchantmentsScore extracts the AI score from the Enchantments raw JSON. Returns nil if enchantments is empty or does not contain a score.
func (*Bulletin) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler for Bulletin. It handles underscore-prefixed fields used in search results.
type CPEOption ¶
type CPEOption func(*cpeConfig)
CPEOption is a functional option for CPE search operations.
func WithCPESize ¶
WithCPESize sets the maximum number of CPE results to return.
func WithMaxSize
deprecated
func WithVendor ¶
WithVendor sets the vendor name for CPE search.
type CPEResult ¶
type CPEResult struct {
CPE string `json:"cpe,omitempty"`
Vendor string `json:"vendor,omitempty"`
Product string `json:"product,omitempty"`
Version string `json:"version,omitempty"`
}
CPEResult represents a CPE search result.
type CPESearchResult ¶
type CPESearchResult struct {
BestMatch string // Best matching CPE string
CPEs []string // List of matching CPE strings
}
CPESearchResult represents the result of a CPE search.
type CVSS ¶
type CVSS struct {
Score float64 `json:"score,omitempty"`
Vector string `json:"vector,omitempty"`
Version string `json:"version,omitempty"`
Severity string `json:"severity,omitempty"`
Source string `json:"source,omitempty"`
// CVSS v3 specific fields
AttackVector string `json:"attackVector,omitempty"`
AttackComplexity string `json:"attackComplexity,omitempty"`
PrivilegesRequired string `json:"privilegesRequired,omitempty"`
UserInteraction string `json:"userInteraction,omitempty"`
Scope string `json:"scope,omitempty"`
ConfidentialityImpact string `json:"confidentialityImpact,omitempty"`
IntegrityImpact string `json:"integrityImpact,omitempty"`
AvailabilityImpact string `json:"availabilityImpact,omitempty"`
}
CVSS represents CVSS scoring information.
type CVSS3 ¶ added in v1.1.4
type CVSS3 struct {
CVSS
}
CVSS3 wraps CVSS to handle NVD-style nested CVSS v3 responses.
The API returns cvss3 as {"cvssV3": {"baseScore":9.8, "baseSeverity":"CRITICAL", "vectorString":"CVSS:3.1/...", ...}}. This type transparently flattens that into the embedded CVSS fields.
func (*CVSS3) UnmarshalJSON ¶ added in v1.1.4
UnmarshalJSON implements json.Unmarshaler for CVSS3. It handles both the NVD wrapper format {"cvssV3": {...}} and flat CVSS format.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main entry point for the Vulners API.
func NewClient ¶
NewClient creates a new Vulners API client. An API key is required for most operations.
Example ¶
// Create a new client with default settings
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
_ = client // use client for API calls
Example (WithOptions) ¶
// Create a client with custom settings
client, err := vulners.NewClient("your-api-key",
vulners.WithTimeout(60*time.Second),
vulners.WithRetries(5),
vulners.WithRateLimit(10.0, 20),
vulners.WithUserAgent("my-app/1.0"),
)
if err != nil {
log.Fatal(err)
}
_ = client
func (*Client) Archive ¶
func (c *Client) Archive() *ArchiveService
Archive returns the ArchiveService for fetching collections.
func (*Client) Audit ¶
func (c *Client) Audit() *AuditService
Audit returns the AuditService for vulnerability auditing.
func (*Client) Misc ¶
func (c *Client) Misc() *MiscService
Misc returns the MiscService for miscellaneous operations.
func (*Client) Report ¶
func (c *Client) Report() *ReportService
Report returns the ReportService for vulnerability reports.
func (*Client) Search ¶
func (c *Client) Search() *SearchService
Search returns the SearchService for searching bulletins.
func (*Client) Stix ¶
func (c *Client) Stix() *StixService
Stix returns the StixService for STIX bundle generation.
func (*Client) Subscription ¶
func (c *Client) Subscription() *SubscriptionService
Subscription returns the SubscriptionService for subscription management.
func (*Client) Webhook ¶
func (c *Client) Webhook() *WebhookService
Webhook returns the WebhookService for webhook management.
type CollectionType ¶
type CollectionType string
CollectionType represents a type of vulnerability collection.
const ( CollectionCVE CollectionType = "cve" CollectionExploit CollectionType = "exploit" CollectionNVD CollectionType = "nvd" CollectionCisco CollectionType = "cisco" CollectionDebian CollectionType = "debian" CollectionUbuntu CollectionType = "ubuntu" CollectionRedhat CollectionType = "redhat" CollectionFedora CollectionType = "fedora" CollectionSuse CollectionType = "suse" CollectionOracle CollectionType = "oracle" CollectionAmazon CollectionType = "amazon" CollectionGentoo CollectionType = "gentoo" CollectionArch CollectionType = "arch" CollectionAlpine CollectionType = "alpine" CollectionFreeBSD CollectionType = "freebsd" CollectionMicrosoft CollectionType = "microsoft" CollectionApple CollectionType = "apple" CollectionVMware CollectionType = "vmware" )
Collection types supported by the Vulners API.
type EnchantmentsScore ¶ added in v1.1.4
type EnchantmentsScore struct {
Value float64 `json:"value,omitempty"`
Uncertainty float64 `json:"uncertanity,omitempty"` //nolint:misspell // API typo preserved
Vector string `json:"vector,omitempty"`
}
EnchantmentsScore represents the AI score from the enchantments field.
type Epss ¶
type Epss struct {
Cve string `json:"cve,omitempty"`
Epss float64 `json:"epss,omitempty"`
Percentile float64 `json:"percentile,omitempty"`
Date string `json:"date,omitempty"`
}
Epss represents EPSS (Exploit Prediction Scoring System) data.
type Exploitation ¶ added in v1.1.2
type Exploitation struct {
WildExploited bool `json:"wildExploited"`
WildExploitedSources []ExploitationSource `json:"wildExploitedSources,omitempty"`
}
Exploitation describes whether a vulnerability is exploited in the wild.
type ExploitationSource ¶ added in v1.1.3
type ExploitationSource struct {
Type string `json:"type,omitempty"`
IDList []string `json:"idList,omitempty"`
}
ExploitationSource identifies a source that reported wild exploitation.
type HistoryEntry ¶
type HistoryEntry struct {
Date *Time `json:"date,omitempty"`
Description string `json:"description,omitempty"`
Changes json.RawMessage `json:"changes,omitempty"`
}
HistoryEntry represents a change history entry.
type HostVuln ¶
type HostVuln struct {
ID string `json:"id,omitempty"`
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
Protocol string `json:"protocol,omitempty"`
VulnID string `json:"vulnId,omitempty"`
Title string `json:"title,omitempty"`
Severity string `json:"severity,omitempty"`
CVSS float64 `json:"cvss,omitempty"`
CVEList []string `json:"cvelist,omitempty"`
}
HostVuln represents a vulnerability found on a host.
type IPSummary ¶
type IPSummary struct {
Total int `json:"total,omitempty"`
WithVulns int `json:"withVulns,omitempty"`
Critical int `json:"critical,omitempty"`
High int `json:"high,omitempty"`
Medium int `json:"medium,omitempty"`
Low int `json:"low,omitempty"`
}
IPSummary represents an IP summary report.
type LinuxAuditRequest ¶
type LinuxAuditRequest struct {
OS string `json:"os"`
Version string `json:"version"`
Packages []string `json:"package"`
}
LinuxAuditRequest represents a Linux audit request.
type MiscService ¶
type MiscService struct {
// contains filtered or unexported fields
}
MiscService provides miscellaneous API operations.
func (*MiscService) GetAIScore ¶
GetAIScore gets an AI-generated vulnerability score for the given text.
func (*MiscService) GetSuggestion ¶
GetSuggestion gets suggestions for a specific field.
func (*MiscService) QueryAutocomplete ¶
QueryAutocomplete provides query autocomplete suggestions.
func (*MiscService) SearchCPE ¶
func (s *MiscService) SearchCPE(ctx context.Context, product, vendor string, opts ...CPEOption) (*CPESearchResult, error)
SearchCPE searches for CPE (Common Platform Enumeration) entries. Both product and vendor are required parameters per the API spec.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Search for CPE entries
result, err := client.Misc().SearchCPE(ctx, "chrome", "google")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Best match: %s\n", result.BestMatch)
fmt.Printf("Found %d CPEs\n", len(result.CPEs))
type Option ¶
type Option func(*clientConfig)
Option is a functional option for configuring the Client.
func WithAllowInsecure ¶
func WithAllowInsecure() Option
WithAllowInsecure allows using HTTP instead of HTTPS. WARNING: This is insecure and should only be used for local testing. Using HTTP will expose your API key to network attackers.
func WithBaseURL ¶
WithBaseURL sets a custom base URL for the API.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
Note: When using a custom HTTP client, several built-in protections are bypassed:
- The WithTimeout option is ignored; configure timeouts directly on your http.Client.
- The WithProxy option is ignored; configure proxy on your http.Client's Transport.
- The default redirect protection (which prevents API key leakage to different hosts) is bypassed. If your use case involves redirects, consider setting CheckRedirect on your http.Client to prevent the API key from being sent to untrusted hosts.
Example with custom redirect protection:
httpClient := &http.Client{
Timeout: 60 * time.Second,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
// Block redirects to prevent API key leakage
return http.ErrUseLastResponse
},
}
client, err := vulners.NewClient("key", vulners.WithHTTPClient(httpClient))
func WithRateLimit ¶
WithRateLimit sets the rate limit (requests per second) and burst size.
func WithRetries ¶
WithRetries sets the maximum number of retries for failed requests.
func WithTimeout ¶
WithTimeout sets the HTTP request timeout.
func WithUserAgent ¶
WithUserAgent sets a custom User-Agent header.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements a token bucket rate limiter.
func NewRateLimiter ¶
func NewRateLimiter(rate float64, burst int) *RateLimiter
NewRateLimiter creates a new rate limiter with the specified rate and burst. rate is the number of requests allowed per second (minimum 0.001). burst is the maximum number of tokens (requests) that can accumulate.
func (*RateLimiter) TryAcquire ¶
func (r *RateLimiter) TryAcquire() bool
TryAcquire attempts to acquire a token without blocking. Returns true if a token was acquired, false otherwise.
func (*RateLimiter) UpdateBurst ¶
func (r *RateLimiter) UpdateBurst(burst int)
UpdateBurst updates the rate limiter's burst size. Burst must be at least 1; values < 1 are ignored.
func (*RateLimiter) UpdateRate ¶
func (r *RateLimiter) UpdateRate(rate float64)
UpdateRate updates the rate limiter's rate. This is useful when the API returns rate limit headers. Rate must be positive; values <= 0 are ignored.
func (*RateLimiter) Wait ¶
func (r *RateLimiter) Wait()
Wait blocks until a token is available. For context-aware waiting, use WaitContext instead.
func (*RateLimiter) WaitContext ¶
func (r *RateLimiter) WaitContext(ctx context.Context) error
WaitContext blocks until a token is available or the context is cancelled. Returns nil if a token was acquired, or the context error if cancelled.
type ReportOption ¶
type ReportOption func(*reportConfig)
ReportOption is a functional option for report operations.
func WithFilter ¶
func WithFilter(filter map[string]interface{}) ReportOption
WithFilter sets a filter for the report.
func WithReportLimit ¶
func WithReportLimit(limit int) ReportOption
WithReportLimit sets the limit for the report.
func WithReportOffset ¶
func WithReportOffset(offset int) ReportOption
WithReportOffset sets the offset for the report.
func WithReportSort ¶
func WithReportSort(field string, ascending bool) ReportOption
WithReportSort sets the sort field and order for the report.
type ReportService ¶
type ReportService struct {
// contains filtered or unexported fields
}
ReportService provides methods for vulnerability reporting.
func (*ReportService) HostVulns ¶
func (s *ReportService) HostVulns(ctx context.Context, opts ...ReportOption) ([]HostVuln, error)
HostVulns gets vulnerabilities for hosts.
func (*ReportService) IPSummaryReport ¶
func (s *ReportService) IPSummaryReport(ctx context.Context, opts ...ReportOption) (*IPSummary, error)
IPSummaryReport gets a summary of IP addresses.
func (*ReportService) ScanList ¶
func (s *ReportService) ScanList(ctx context.Context, opts ...ReportOption) ([]ScanItem, error)
ScanList gets a list of scans.
func (*ReportService) VulnsList ¶
func (s *ReportService) VulnsList(ctx context.Context, opts ...ReportOption) ([]VulnItem, error)
VulnsList gets a list of vulnerabilities.
func (*ReportService) VulnsSummaryReport ¶
func (s *ReportService) VulnsSummaryReport(ctx context.Context, opts ...ReportOption) (*VulnsSummary, error)
VulnsSummaryReport gets a summary of vulnerabilities.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Get a summary of vulnerabilities
summary, err := client.Report().VulnsSummaryReport(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total vulnerabilities: %d\n", summary.Total)
fmt.Printf("Critical: %d\n", summary.Critical)
fmt.Printf("High: %d\n", summary.High)
type SBOMAdvisory ¶ added in v1.1.0
type SBOMAdvisory struct {
ID string `json:"id"`
Type string `json:"type"`
Match string `json:"match"`
Title string `json:"title"`
Description string `json:"description"`
AIDescription string `json:"aiDescription,omitempty"`
Published *Time `json:"published"`
CVEList []string `json:"cvelist,omitempty"`
EPSS []Epss `json:"epss,omitempty"`
AIScore *AIScore `json:"aiScore,omitempty"`
Metrics *SBOMMetrics `json:"metrics,omitempty"`
Exploitation *Exploitation `json:"exploitation,omitempty"`
Enchantments json.RawMessage `json:"enchantments,omitempty"`
WebApplicability json.RawMessage `json:"webApplicability,omitempty"`
References []string `json:"references,omitempty"`
Exploits json.RawMessage `json:"exploits,omitempty"`
}
SBOMAdvisory represents a security advisory applicable to an SBOM package.
func (*SBOMAdvisory) GetEnchantmentsScore ¶ added in v1.1.4
func (a *SBOMAdvisory) GetEnchantmentsScore() *EnchantmentsScore
GetEnchantmentsScore extracts the AI score from the Enchantments raw JSON. Returns nil if enchantments is empty or does not contain a score.
type SBOMAuditResult ¶ added in v1.1.0
type SBOMAuditResult struct {
Packages []SBOMPackageResult `json:"result"`
}
SBOMAuditResult represents the response from the SBOM audit endpoint.
type SBOMMetrics ¶ added in v1.1.2
type SBOMMetrics struct {
CVSS *CVSS `json:"cvss,omitempty"`
EPSS []string `json:"epss,omitempty"`
}
SBOMMetrics contains CVSS scoring information for an SBOM advisory.
type SBOMPackageResult ¶ added in v1.1.0
type SBOMPackageResult struct {
Package string `json:"package"`
Version string `json:"version"`
FixedVersion *string `json:"fixedVersion"`
ApplicableAdvisories []SBOMAdvisory `json:"applicableAdvisories"`
}
SBOMPackageResult represents audit findings for a single package in an SBOM.
type ScanItem ¶
type ScanItem struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
StartedAt *Time `json:"startedAt,omitempty"`
FinishedAt *Time `json:"finishedAt,omitempty"`
HostCount int `json:"hostCount,omitempty"`
VulnCount int `json:"vulnCount,omitempty"`
}
ScanItem represents a scan in the scan list.
type SearchOption ¶
type SearchOption func(*searchConfig)
SearchOption is a functional option for search operations.
func WithFields ¶
func WithFields(fields ...string) SearchOption
WithFields sets the fields to return in results.
func WithLimit ¶
func WithLimit(limit int) SearchOption
WithLimit sets the maximum number of results to return. For SearchBulletins, this controls the page size (default 20). For SearchBulletinsAll, this controls the total result count:
- limit > 0: return at most this many results
- limit = 0: return empty result immediately (no API calls)
- limit < 0 or not set: return all matching results
func WithOffset ¶
func WithOffset(offset int) SearchOption
WithOffset sets the offset for pagination.
func WithSort ¶
func WithSort(field string, ascending bool) SearchOption
WithSort sets the sort field for results.
type SearchResult ¶
type SearchResult struct {
Total int `json:"total,omitempty"`
Bulletins []Bulletin `json:"search,omitempty"`
Took int `json:"took,omitempty"`
}
SearchResult represents a search response from the API.
type SearchService ¶
type SearchService struct {
// contains filtered or unexported fields
}
SearchService provides methods for searching the Vulners database.
func (*SearchService) GetBulletin ¶
func (s *SearchService) GetBulletin(ctx context.Context, id string, opts ...SearchOption) (*Bulletin, error)
GetBulletin retrieves a single bulletin by ID.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Get a specific vulnerability by ID
bulletin, err := client.Search().GetBulletin(ctx, "CVE-2021-44228")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Title: %s\n", bulletin.Title)
if bulletin.CVSS != nil {
fmt.Printf("CVSS Score: %.1f\n", bulletin.CVSS.Score)
}
func (*SearchService) GetBulletinHistory ¶
func (s *SearchService) GetBulletinHistory(ctx context.Context, id string) ([]HistoryEntry, error)
GetBulletinHistory retrieves the change history for a bulletin.
func (*SearchService) GetBulletinReferences ¶
GetBulletinReferences retrieves references for a bulletin.
func (*SearchService) GetMultipleBulletins ¶
func (s *SearchService) GetMultipleBulletins(ctx context.Context, ids []string, opts ...SearchOption) (map[string]Bulletin, error)
GetMultipleBulletins retrieves multiple bulletins by their IDs.
func (*SearchService) SearchBulletins ¶
func (s *SearchService) SearchBulletins(ctx context.Context, query string, opts ...SearchOption) (*SearchResult, error)
SearchBulletins searches for bulletins using Lucene query syntax.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
// Search for CVEs related to log4j
results, err := client.Search().SearchBulletins(ctx, "log4j",
vulners.WithLimit(10),
vulners.WithFields("id", "title", "cvss", "published"),
)
cancel() // Clean up context
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d results\n", results.Total)
for _, b := range results.Bulletins {
fmt.Printf("- %s: %s\n", b.ID, b.Title)
}
func (*SearchService) SearchBulletinsAll ¶
func (s *SearchService) SearchBulletinsAll(ctx context.Context, query string, opts ...SearchOption) ([]Bulletin, error)
SearchBulletinsAll returns all results for a query using pagination. Use with caution as this may make many API calls for large result sets.
The limit can be controlled with WithLimit:
- WithLimit(n) where n > 0: return at most n results
- WithLimit(0): return empty result (no API calls made)
- No WithLimit option: return all matching results (unlimited)
func (*SearchService) SearchExploits ¶
func (s *SearchService) SearchExploits(ctx context.Context, query string, opts ...SearchOption) (*SearchResult, error)
SearchExploits searches specifically for exploits.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Search for exploits only
results, err := client.Search().SearchExploits(ctx, "apache",
vulners.WithLimit(5),
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d exploits\n", results.Total)
type SoftwareAuditItem ¶ added in v1.2.0
type SoftwareAuditItem struct {
Input json.RawMessage `json:"input,omitempty"`
MatchedCriteria string `json:"matched_criteria,omitempty"`
Vulnerabilities []Bulletin `json:"vulnerabilities,omitempty"`
}
SoftwareAuditItem represents a single software item's audit results from the v4 API.
type SoftwareAuditResult ¶ added in v1.2.0
type SoftwareAuditResult struct {
Items []SoftwareAuditItem `json:"items,omitempty"`
}
SoftwareAuditResult represents the response from the v4 software and host audit endpoints.
type StixBundle ¶
type StixBundle struct {
Type string `json:"type"`
ID string `json:"id"`
Objects []json.RawMessage `json:"objects"`
}
StixBundle represents a STIX bundle.
type StixOption ¶
type StixOption func(*stixConfig)
StixOption is a functional option for STIX operations.
func WithSTIXVersion ¶
func WithSTIXVersion(version string) StixOption
WithSTIXVersion sets the STIX version for the bundle.
type StixService ¶
type StixService struct {
// contains filtered or unexported fields
}
StixService provides methods for STIX bundle generation.
func (*StixService) MakeBundleByCVE ¶
func (s *StixService) MakeBundleByCVE(ctx context.Context, cveID string, opts ...StixOption) (*StixBundle, error)
MakeBundleByCVE generates a STIX bundle for a given CVE ID.
func (*StixService) MakeBundleByID ¶
func (s *StixService) MakeBundleByID(ctx context.Context, bulletinID string, opts ...StixOption) (*StixBundle, error)
MakeBundleByID generates a STIX bundle for a given bulletin ID.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Generate a STIX bundle for a vulnerability
bundle, err := client.Stix().MakeBundleByID(ctx, "CVE-2021-44228")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Bundle type: %s\n", bundle.Type)
fmt.Printf("Bundle ID: %s\n", bundle.ID)
type Subscription ¶
type Subscription struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Active bool `json:"active,omitempty"`
Query string `json:"query,omitempty"`
Config json.RawMessage `json:"config,omitempty"`
Created *Time `json:"created,omitempty"`
Modified *Time `json:"modified,omitempty"`
}
Subscription represents a v4 subscription.
type SubscriptionRequest ¶
type SubscriptionRequest struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Active bool `json:"active,omitempty"`
Query string `json:"query,omitempty"`
Config json.RawMessage `json:"config,omitempty"`
}
SubscriptionRequest represents a request to create/update a subscription.
type SubscriptionService ¶
type SubscriptionService struct {
// contains filtered or unexported fields
}
SubscriptionService provides methods for managing v4 subscriptions.
func (*SubscriptionService) Create ¶
func (s *SubscriptionService) Create(ctx context.Context, req *SubscriptionRequest) (*Subscription, error)
Create creates a new subscription.
func (*SubscriptionService) Delete ¶
func (s *SubscriptionService) Delete(ctx context.Context, id string) error
Delete removes a subscription.
func (*SubscriptionService) Get ¶
func (s *SubscriptionService) Get(ctx context.Context, id string) (*Subscription, error)
Get retrieves a subscription by ID.
func (*SubscriptionService) List ¶
func (s *SubscriptionService) List(ctx context.Context) ([]Subscription, error)
List returns all subscriptions.
func (*SubscriptionService) Update ¶
func (s *SubscriptionService) Update(ctx context.Context, id string, req *SubscriptionRequest) (*Subscription, error)
Update updates an existing subscription.
type Time ¶
Time is a custom time type that handles various time formats from the API.
func (Time) MarshalJSON ¶
MarshalJSON implements json.Marshaler for Time.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler for Time.
type VulnItem ¶
type VulnItem struct {
ID string `json:"id,omitempty"`
Title string `json:"title,omitempty"`
Severity string `json:"severity,omitempty"`
CVSS float64 `json:"cvss,omitempty"`
CVEList []string `json:"cvelist,omitempty"`
Published *Time `json:"published,omitempty"`
HostCount int `json:"hostCount,omitempty"`
}
VulnItem represents an individual vulnerability in a list.
type Vulnerability ¶
type Vulnerability struct {
Package string `json:"package,omitempty"`
Operator string `json:"operator,omitempty"`
Version string `json:"providedVersion,omitempty"`
BulletinID string `json:"bulletinID,omitempty"`
CVEList []string `json:"cvelist,omitempty"`
CVSS *CVSS `json:"cvss,omitempty"`
Fix string `json:"fix,omitempty"`
}
Vulnerability represents a vulnerability found during audit.
type VulnsSummary ¶
type VulnsSummary struct {
Total int `json:"total,omitempty"`
Critical int `json:"critical,omitempty"`
High int `json:"high,omitempty"`
Medium int `json:"medium,omitempty"`
Low int `json:"low,omitempty"`
Info int `json:"info,omitempty"`
Severities map[string]int `json:"severities,omitempty"`
}
VulnsSummary represents a vulnerability summary.
type Webhook ¶
type Webhook struct {
ID string `json:"id,omitempty"`
Query string `json:"query,omitempty"`
Active bool `json:"active,omitempty"`
Created *Time `json:"created,omitempty"`
Modified *Time `json:"modified,omitempty"`
}
Webhook represents a webhook configuration.
type WebhookData ¶
type WebhookData struct {
ID string `json:"id,omitempty"`
Data []Bulletin `json:"data,omitempty"`
NewCount int `json:"new_count,omitempty"`
}
WebhookData represents data from a webhook.
type WebhookService ¶
type WebhookService struct {
// contains filtered or unexported fields
}
WebhookService provides methods for webhook management.
func (*WebhookService) Add ¶
Add creates a new webhook with the given query.
Example ¶
client, err := vulners.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Create a webhook for critical CVEs
webhook, err := client.Webhook().Add(ctx, "type:cve AND cvss.score:[9 TO 10]")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created webhook: %s\n", webhook.ID)
func (*WebhookService) Delete ¶
func (s *WebhookService) Delete(ctx context.Context, id string) error
Delete removes a webhook.
func (*WebhookService) List ¶
func (s *WebhookService) List(ctx context.Context) ([]Webhook, error)
List returns all configured webhooks.
func (*WebhookService) Read ¶
func (s *WebhookService) Read(ctx context.Context, id string, newestOnly bool) (*WebhookData, error)
Read retrieves data from a webhook. If newestOnly is true, only the newest data since the last read is returned.
type WinAuditItem ¶
WinAuditItem represents a Windows software item for auditing.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
audit
command
Example: Auditing software for vulnerabilities using the Vulners API.
|
Example: Auditing software for vulnerabilities using the Vulners API. |
|
search
command
Example: Searching for vulnerabilities using the Vulners API.
|
Example: Searching for vulnerabilities using the Vulners API. |
|
vscanner
command
Example: Using VScanner for vulnerability scanning.
|
Example: Using VScanner for vulnerability scanning. |
|
Package vscanner provides a Go client for the Vulners VScanner vulnerability scanning API.
|
Package vscanner provides a Go client for the Vulners VScanner vulnerability scanning API. |