restuss

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 14 Imported by: 2

README

Restuss

This is a Go package that support part of the Nessus rest(kind of) api.

go get github.com/stefanoj3/restuss

The amount of method supported is extremely small, I actually needed it for a personal project and decided to make a library out of it, so others can reuse it.

Example usage of the library:

auth := restuss.NewKeyAuthProvider(
    "fa74fcdd10db53bf54cd1467c11547efd70af0b526eb0d2b347b1050e1cab639",
    "71ebdf108b4d2fa9fef8c895096ff1a2a7732c215c64edc8d6495053488004d6",
)

c, err := restuss.NewClient(auth, "https://127.0.0.1:8834", true)

if err != nil {
    log.Fatal(err.Error())
}

var lastModificationDate int64 = 0

res, err := c.GetScans(lastModificationDate)

if err != nil {
    log.Fatal(err.Error())
}

Support for basic auth is also planned but not a priority.

For now the available calls are: create scan, launch scan, stop scan, list scans, list scan's templates.

This package has zero dependencies and I plan to keep it like that.

Tested with Nessus 6.10.1

Important note

Since it's in early development the next versions could contain breaking changes.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset added in v1.1.0

type Asset struct {
	ID                 string    `json:"id"`
	Name               string    `json:"name"`
	Types              []string  `json:"types"`
	Sources            []string  `json:"sources"`
	Created            time.Time `json:"created"`
	ObservationSources []struct {
		FirstObserved time.Time `json:"first_observed"`
		LastObserved  time.Time `json:"last_observed"`
		Name          string    `json:"name"`
	} `json:"observation_sources"`
	IsLicensed bool     `json:"is_licensed"`
	Fqdns      []string `json:"fqdns"`
	Tags       []struct {
		ID       string `json:"id"`
		Category string `json:"category"`
		Value    string `json:"value"`
		Type     string `json:"type"`
	} `json:"tags"`
	Network struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"network"`
	FirstObserved time.Time `json:"first_observed"`
	DisplayFqdn   string    `json:"display_fqdn"`
	IsDeleted     bool      `json:"is_deleted"`
	LastObserved  time.Time `json:"last_observed"`
	Updated       time.Time `json:"updated"`
}

Asset represents the asset entity on Tenable.io.

More attributes available at https://developer.tenable.com/docs/common-asset-attributes.

type AuthProvider

type AuthProvider interface {
	AddAuthHeaders(*http.Request)
	Prepare(url string, client *http.Client) error
}

AuthProvider expose the methods necessary to perform authenticated calls

type BasicAuthProvider

type BasicAuthProvider struct {
	// contains filtered or unexported fields
}

BasicAuthProvider represent the basic auth method

func NewBasicAuthProvider

func NewBasicAuthProvider(username string, password string) *BasicAuthProvider

NewBasicAuthProvider returns a new BasicAuthProvider

func (*BasicAuthProvider) AddAuthHeaders

func (b *BasicAuthProvider) AddAuthHeaders(r *http.Request)

AddAuthHeaders add auth headers

func (*BasicAuthProvider) Prepare

func (b *BasicAuthProvider) Prepare(url string, c *http.Client) error

Prepare performs tasks required pre-auth, it should be called before AddAuthHeaders can be used

type Client

type Client interface {
	GetScanTemplates() ([]*ScanTemplate, error)
	LaunchScan(scanID int64) error
	StopScan(scanID int64) error
	DeleteScan(scanID int64) error
	CreateScan(scan *Scan) (*PersistedScan, error)
	GetScans(lastModificationDate int64) ([]*PersistedScan, error)
	GetScanByID(id int64) (*ScanDetail, error)
	GetPluginByID(id int64) (*Plugin, error)
	GetPluginOutput(scanID, hostID, pluginID int64) (*PluginOutputResponse, error)
	GetAssetByName(name string) (*Asset, error)
	GetFindingsByAssetName(name string) ([]Finding, error)
}

Client expose the methods callable on Nessus Api

type Finding added in v1.1.0

type Finding struct {
	Output     string `json:"output"`
	ID         string `json:"id"`
	Severity   int    `json:"severity"`
	Port       int    `json:"port"`
	Protocol   string `json:"protocol"`
	Service    string `json:"service"`
	Definition struct {
		ID          int    `json:"id"` // plugin_id
		Name        string `json:"name"`
		Description string `json:"description"`
		Synopsis    string `json:"synopsis"`
		Solution    string `json"solution"`
		CVSS3       struct {
			BaseScore *float32 `json:"base_score"`
		} `json:"cvss3"`
		CVSS2 struct {
			BaseScore *float32 `json:"base_score"`
		} `json:"cvss2"`
		CWE     []string `json:"cwe"`
		SeeAlso []string `json:"see_also"`
	} `json:"definition"`
}

Finding represents the finding entity on Tenable.io.

More info available at https://developer.tenable.com/docs/tenable-plugin-attributes.

type Host

type Host struct {
	ID       int64  `json:"host_id"`
	Hostname string `json:"hostname"`
}

Host represents a host member of a scan

type Info

type Info struct {
	Status string `json:"status"`
}

Info represents detailed information from a Scan returned by Nessus API

type KeyAuthProvider

type KeyAuthProvider struct {
	// contains filtered or unexported fields
}

KeyAuthProvider represent the key based auth method

func NewKeyAuthProvider

func NewKeyAuthProvider(accessKey string, secretKey string) *KeyAuthProvider

NewKeyAuthProvider returns a new KeyAuthProvider

func (*KeyAuthProvider) AddAuthHeaders

func (k *KeyAuthProvider) AddAuthHeaders(r *http.Request)

AddAuthHeaders add auth headers

func (*KeyAuthProvider) Prepare

func (k *KeyAuthProvider) Prepare(_ string, _ *http.Client) error

Prepare performs tasks required pre-auth, it should be called before AddAuthHeaders can be used

type NessusClient

type NessusClient struct {
	// contains filtered or unexported fields
}

NessusClient implements nessus.Client

func NewClient

func NewClient(auth AuthProvider, url string, allowInsecureConnection bool) (*NessusClient, error)

NewClient returns a new NessusClient

func (*NessusClient) CreateScan

func (c *NessusClient) CreateScan(scan *Scan) (*PersistedScan, error)

CreateScan creates a scan

func (*NessusClient) CreateScanContext

func (c *NessusClient) CreateScanContext(ctx context.Context, scan *Scan) (*PersistedScan, error)

CreateScanContext creates a scan with the given scan data and context.

func (*NessusClient) DeleteScan

func (c *NessusClient) DeleteScan(scanID int64) error

DeleteScan will remove the scan with the given scanID

func (*NessusClient) DeleteScanContext

func (c *NessusClient) DeleteScanContext(ctx context.Context, scanID int64) error

DeleteScanContext will remove the scan with the given scanID and context.

func (*NessusClient) GetAssetByName added in v1.1.0

func (c *NessusClient) GetAssetByName(ctx context.Context, name string) (*Asset, error)

GetAssetByName returns an asset by its name. Returns an error if more than one or none assets are matching.

func (*NessusClient) GetFindingsByAssetName added in v1.1.0

func (c *NessusClient) GetFindingsByAssetName(ctx context.Context, name string) ([]Finding, error)

GetFindingsByAssetName returns all the findings associated to an asset by its name.

func (*NessusClient) GetPluginByID

func (c *NessusClient) GetPluginByID(ID int64) (*Plugin, error)

GetPluginByID retrieves a plugin by ID

func (*NessusClient) GetPluginByIDContext

func (c *NessusClient) GetPluginByIDContext(ctx context.Context, ID int64) (*Plugin, error)

GetPluginByIDContext retrieves a plugin by ID using the given context.

func (*NessusClient) GetPluginOutput

func (c *NessusClient) GetPluginOutput(scanID, hostID, pluginID int64) (*PluginOutputResponse, error)

GetPluginOutput retrieves output from a plugin ran against a target

func (*NessusClient) GetPluginOutputContext

func (c *NessusClient) GetPluginOutputContext(ctx context.Context, scanID, hostID, pluginID int64) (*PluginOutputResponse, error)

GetPluginOutputContext retrieves output from a plugin ran against a target using the given context.

func (*NessusClient) GetPolicyByID

func (c *NessusClient) GetPolicyByID(ID int64) (*Policy, error)

GetPolicyByID retrieves a policy by ID

func (*NessusClient) GetPolicyByIDContext

func (c *NessusClient) GetPolicyByIDContext(ctx context.Context, ID int64) (*Policy, error)

GetPolicyByIDContext retrieves a policy by ID using the given context.

func (*NessusClient) GetScanByID

func (c *NessusClient) GetScanByID(ID int64) (*ScanDetail, error)

GetScanByID retrieve a scan by ID

func (*NessusClient) GetScanByIDContext

func (c *NessusClient) GetScanByIDContext(ctx context.Context, ID int64) (*ScanDetail, error)

GetScanByIDContext retrieve a scan by ID

func (*NessusClient) GetScanTemplates

func (c *NessusClient) GetScanTemplates() ([]*ScanTemplate, error)

GetScanTemplates retrieves Scan Templates

func (*NessusClient) GetScanTemplatesContext

func (c *NessusClient) GetScanTemplatesContext(ctx context.Context) ([]*ScanTemplate, error)

GetScanTemplatesContext retrieves the Scan templates ussing the given context.

func (*NessusClient) GetScans

func (c *NessusClient) GetScans(lastModificationDate int64) ([]*PersistedScan, error)

GetScans get a list of scan matching the provided lastModificationDate (check Nessus documentation)

func (*NessusClient) GetScansContext

func (c *NessusClient) GetScansContext(ctx context.Context, lastModificationDate int64) ([]*PersistedScan, error)

GetScansContext get a list of scan matching the provided lastModificationDate (check Nessus documentation) and context.

func (*NessusClient) LaunchScan

func (c *NessusClient) LaunchScan(scanID int64) error

LaunchScan launch spe scan with the specified scanID

func (*NessusClient) LaunchScanContext

func (c *NessusClient) LaunchScanContext(ctx context.Context, scanID int64) error

LaunchScanContext launch the scan with the specified scanID and context.

func (*NessusClient) StopScan

func (c *NessusClient) StopScan(scanID int64) error

StopScan stops the scan with the given scanID

func (*NessusClient) StopScanContext

func (c *NessusClient) StopScanContext(ctx context.Context, scanID int64) error

StopScanContext stops the scan with the given scanID

type Pagination added in v1.1.0

type Pagination struct {
	Next  string `json:"next"`
	Limit int    `json:"limit"`
	Total int    `json:"total"`
}

Pagination is used to iterate results for some endpoints. If the attribute `Next` has content, needs to be passed as a parameter to the next request.

type PersistedScan

type PersistedScan struct {
	ID                   int64  `json:"id"`
	UUID                 string `json:"uuid"`
	Name                 string `json:"name"`
	Status               string `json:"status"`
	CreationDate         int64  `json:"creation_date"`
	LastModificationDate int64  `json:"last_modification_date"`
	Owner                string `json:"owner"`
}

PersistedScan represents a Persisted Scan on Nessus API

type Plugin

type Plugin struct {
	ID         int64             `json:"id"`
	Name       string            `json:"name"`
	FamilyName string            `json:"family_name"`
	Attributes []PluginAttribute `json:"attributes"`
}

Plugin represents a plugin returned by Nessus API

type PluginAttribute

type PluginAttribute struct {
	Name  string `json:"attribute_name"`
	Value string `json:"attribute_value"`
}

PluginAttribute represents an attribute for a plugin returned by Nessus API

type PluginOutput

type PluginOutput struct {
	Hosts    string      `json:"hosts"`
	Ports    interface{} `json:"ports"`
	Output   string      `json:"plugin_output"`
	Severity int         `json:"severity"`
}

PluginOutput represents the output of a plugin returned by Nessus API

type PluginOutputResponse

type PluginOutputResponse struct {
	Output []PluginOutput `json:"outputs"`
}

PluginOutputResponse represents the output of a plugin returned by Nessus API

type Policy

type Policy struct {
	ID       int64
	UUID     string         `json:"uuid"`
	Settings PolicySettings `json:"settings"`
}

Policy represents a policy returned by Nessus API

type PolicySettings

type PolicySettings struct {
	Name string `json:"name"`
}

PolicySettings represents a setting for policy returned by Nessus API

type Scan

type Scan struct {
	TemplateUUID string       `json:"uuid"`
	Settings     ScanSettings `json:"settings"`
}

Scan represents a Scan to be posted to Nessus API

type ScanDetail

type ScanDetail struct {
	ID              int64
	Info            Info            `json:"info"`
	Hosts           []Host          `json:"hosts"`
	Vulnerabilities []Vulnerability `json:"vulnerabilities"`
}

ScanDetail represents Details from a Scan returned by Nessus API

type ScanSettings

type ScanSettings struct {
	Name     string `json:"name"`
	Enabled  bool   `json:"enabled"`
	Targets  string `json:"text_targets"`
	PolicyID int64  `json:"policy_id"`
}

ScanSettings represents settings for a Scan to be posted to Nessus API

type ScanTemplate

type ScanTemplate struct {
	UUID             string `json:"uuid"`
	Name             string `json:"name"`
	Title            string `json:"title"`
	Description      string `json:"description"`
	CloudOnly        bool   `json:"cloud_only"`
	SubscriptionOnly bool   `json:"subscription_only"`
	IsAgent          bool   `json:"is_agent"`
	Info             string `json:"more_info"`
}

ScanTemplate represents a Template for a Scan returned by Nessus API

type Vulnerability

type Vulnerability struct {
	VulnerabilityIndex int64  `json:"vuln_index"`
	Severity           int64  `json:"severity"`
	PluginName         string `json:"plugin_name"`
	Count              int64  `json:"count"`
	PluginID           int64  `json:"plugin_id"`
	PluginFamily       string `json:"plugin_family"`
}

Vulnerability represents a Vulnerability returned by Nessus API

Jump to

Keyboard shortcuts

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