goNessus

package module
v0.0.0-...-8045baa Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2016 License: Apache-2.0 Imports: 20 Imported by: 0

README

go-nessus

Nessus 6 API Client written in Golang

Example target file:

requestid:  1
method: default
192.168.0.5/32

Example target file for multiple hosts:

requestid:  2
method: atomic
192.168.0.5/32
192.168.0.6/32
192.168.0.7/32
192.168.0.8/32
192.168.0.9/32
192.168.0.10/32

Documentation

Overview

Package goNessus provides a Golang based interface to Nessus 6

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckErr

func CheckErr(e error)

Used to check if an error is not equal to nil. If it is, throw a fatal error using the log package.

func ConnectToMySqlDatabase

func ConnectToMySqlDatabase(username string, password string, database string, server string, INFO map[string]string, secure bool) *sql.DB

Generates a secure or insecure TCP MySQL database connection on port 3306

func ConnectToSqliteDatabase

func ConnectToSqliteDatabase(sqlite_db string) *sql.DB

Generates a file connection to an SQLite3 database connection

func CopyFile

func CopyFile(source, dest string) (int64, error)

func CopyTargetFileToArchiveDirectory

func CopyTargetFileToArchiveDirectory(fileLocations FileLocations, targetFileName string)

Creates a copy of the target file and puts it in the archive directory as definied in ConstructFileLocations. The target file is the file stating which type of scan will be used and what hosts will be scanned.

func CreateNecessaryDirectories

func CreateNecessaryDirectories(fileLocations FileLocations)

Create any directories with 755 permissions from ConstructFileLocations which do not exist.

func IsScanReady

func IsScanReady(nessus *Nessus, url string) bool

func MoveTargetFileToTempDirectory

func MoveTargetFileToTempDirectory(fileLocations FileLocations, targetFileName string)

Moves target file to temporary directory as defined in ConstructFileLocations. Target file is the file stating which type of scan will be used and what hosts will be scanned.

func ProcessIncomingFilesDir

func ProcessIncomingFilesDir(fileLocations FileLocations, accessKey string, secretKey string, sqlite_db string)

Processes each target file in the incoming directory as defined by ConstructFileLocations. This takes each file, parses it, creates a JSON object to send to Nessus to create a scan, creates the scan, launches the scan, and records the information about the scan in an SQLite database.

func RetreieveLaunchedScanResults

func RetreieveLaunchedScanResults(fileLocations FileLocations, accessKey string, secretKey string, sqlite_db string)

RetreieveLaunchedScanResults works through the SQLite database from ProcessIncomingFilesDir, exports each scan, waits for the export to finish, then downloads the scan and saves it to the results directory from ConstructFileLocations

func ScpRemoteResultsToLocal

func ScpRemoteResultsToLocal(client *ssh.Client, remoteFilePath string, localFilePath string)

Connects to a remote scanner over SSH, creates a list of all available result files, then SCP's each of them (*.csv) to the local machine.

Example:

scpKeyFile := goScp.SshKeyfile{Path: "/Users/example/.ssh", Filename: "id_rsa.pub"}
scpCredentials := goScp.SshCredentials{Username: "example"}
scpRemoteMachine := goScp.RemoteMachine{Host: "192.168.0.1", Port: "8022"}

client, err := goScp.Connect(scpKeyFile, scpCredentials, scpRemoteMachine, false)
if err != nil {
	log.Fatal("Failed to connect: " + err.Error())
}

remoteFilePath := "/opt/scanner/results"
localFilePath := "/Users/example/nessusResults"
goNessus.ScpRemoteResultsToLocal(client, remoteFilePath, localFilePath)

Types

type CreateScan

type CreateScan struct {
	Uuid     string             `json:"uuid"`
	Settings CreateScanSettings `json:"settings"`
}

CreateScan is the JSON object used to create a new scan in Nessus 6.

type CreateScanResponse

type CreateScanResponse struct {
	Scan struct {
		ContainerID          int         `json:"container_id"`
		CreationDate         int         `json:"creation_date"`
		CustomTargets        string      `json:"custom_targets"`
		DashboardFile        interface{} `json:"dashboard_file"`
		DefaultPermisssions  int         `json:"default_permisssions"`
		Description          string      `json:"description"`
		Emails               string      `json:"emails"`
		Enabled              bool        `json:"enabled"`
		ID                   int         `json:"id"`
		LastModificationDate int         `json:"last_modification_date"`
		Name                 string      `json:"name"`
		NotificationFilters  interface{} `json:"notification_filters"`
		Owner                string      `json:"owner"`
		OwnerID              int         `json:"owner_id"`
		PolicyID             int         `json:"policy_id"`
		Rrules               interface{} `json:"rrules"`
		ScanTimeWindow       interface{} `json:"scan_time_window"`
		ScannerID            int         `json:"scanner_id"`
		Shared               int         `json:"shared"`
		Sms                  interface{} `json:"sms"`
		Starttime            interface{} `json:"starttime"`
		TagID                int         `json:"tag_id"`
		Timezone             string      `json:"timezone"`
		Type                 string      `json:"type"`
		UseDashboard         bool        `json:"use_dashboard"`
		UserPermissions      int         `json:"user_permissions"`
		UUID                 string      `json:"uuid"`
	} `json:"scan"`
}

CreateScanResponse maps to the JSON object returned by Nessus 6 when you successfully create a new scan.

type CreateScanSettings

type CreateScanSettings struct {
	Name         string `json:"name"`
	Description  string `json:"description"`
	Folder_id    string `json:"folder_id"`
	Scanner_id   string `json:"scanner_id"`
	Policy_id    string `json:"policy_id"`
	Text_targets string `json:"text_targets"`
	File_targets string `json:"file_targets"`
	Launch       string `json:"launch"`
	Enabled      bool   `json:"enabled"`
	Launch_now   bool   `json:"launch_now"`
	Emails       string `json:"emails"`
}

CreateScanSettings is the sub-JSON structure used in CreateScan when generating a new scan in Nessus 6.

type DatabaseRow

type DatabaseRow struct {
	Request_id int
	Method     string
	Scan_uuid  string
	Scan_id    string
}

DatabaseRow is used to represent a single row in the SQLite3 database

type ExportScanResponse

type ExportScanResponse struct {
	File int `json:"file"`
}

ExportScanResponse represents the JSON received from Nessus when exporting a scan

type ExportScanStatusResponse

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

ExportScanStatusResponse represents the JSON received from Nessus when checking the status of a scan export.

type FileLocations

type FileLocations struct {
	Base_directory     string
	Temp_directory     string
	Archive_directory  string
	Incoming_directory string
	Results_directory  string
}

FileLocations represents where files will be found on a system. Specifically we have the temporary directory where we store stuff while processing, archive directory where we store processed files, incoming directory where target files are stored prior to being processed, and results directory where we store scan result CSV files.

func ConstructFileLocations

func ConstructFileLocations() FileLocations

Construct file locations of of scanner resources based on the operating system.

Example:

fileLocations := goNessus.ConstructFileLocations()

type LaunchScanResponse

type LaunchScanResponse struct {
	ScanUUID string `json:"scan_uuid"`
}

type Nessus

type Nessus struct {
	Ip        string
	Port      string
	AccessKey string
	SecretKey string
	Token     string
}

Nessus struct is used to contain information about a Nessus scanner. This will be used to connect to the scanner and make API requests.

func MakeClient

func MakeClient(host, port, accessKey, secretKey string) *Nessus

Creates a new Nessus client struct which can be used to make Nessus API calls

func (*Nessus) AsyncBuildCreateScanJson

func (nessus *Nessus) AsyncBuildCreateScanJson(target_scan_ch chan *TargetScan,
	json_ch chan string, filename_ch chan string, num_of_files int)

Builds the JSON object to send to Nessus when creating a scan.

@param name [string] The name of the to be created Nessus Scan @param description [string] The description of the scan @param policy_id [string] The policy which should be used to create the custom scan @param text_targets [string] The IP Addresses which should be scanned

func (*Nessus) AsyncCreateScan

func (nessus *Nessus) AsyncCreateScan(json_ch chan string, new_scan_ch chan CreateScanResponse, num_of_files int)

Creates a new scan on the Nessus server.

@param nessus Nessus The Nessus client struct @param json_ch [chan string] The channel that we will receive JSON create opts on

func (*Nessus) AsyncDownloadScan

func (nessus *Nessus) AsyncDownloadScan(scan_id string,
	file_exported_ch chan ExportScanResponse, scan_result_ch chan string, scan_id_ch chan string)

func (*Nessus) AsyncExportScan

func (nessus *Nessus) AsyncExportScan(scan_id string, export_scan_ch chan ExportScanResponse)

func (*Nessus) AsyncLaunchCreated

func (nessus *Nessus) AsyncLaunchCreated(new_scan_ch chan CreateScanResponse,
	scan_id_ch chan int, launched_scan_ch chan LaunchScanResponse, num_of_files int)

func (*Nessus) AsyncSaveDownloadedScan

func (nessus *Nessus) AsyncSaveDownloadedScan(path string, scan_result_ch chan string, scan_id_ch chan string, file_ch chan bool)

func (*Nessus) AsyncSaveLaunchedScan

func (nessus *Nessus) AsyncSaveLaunchedScan(database_name string, scan_id_chan chan int,
	launched_scan_ch chan LaunchScanResponse, filename_ch chan string, fileLocations FileLocations, num_of_files int)

func (*Nessus) AsyncWaitForScan

func (nessus *Nessus) AsyncWaitForScan(scan_id string, export_scan_ch chan ExportScanResponse,
	file_exported_ch chan ExportScanResponse)

func (*Nessus) LaunchCreated

func (nessus *Nessus) LaunchCreated(scan CreateScanResponse, scan_id int) (int, LaunchScanResponse)

func (*Nessus) ListAgents

func (nessus *Nessus) ListAgents(scanner_id int, str_ch chan string)

Returns the agent list for the given scanner.

This request requires standard user permissions. Users with this role can create scans, policies, and reports.

func (Nessus) PerformGet

func (nessus Nessus) PerformGet(url string, str_ch chan string)

func (Nessus) PerformPost

func (nessus Nessus) PerformPost(url string, channel chan string)

func (Nessus) PerformPostWithArgs

func (nessus Nessus) PerformPostWithArgs(url string, opts string,
	str_ch chan string)

func (*Nessus) ProcessTargetFiles

func (nessus *Nessus) ProcessTargetFiles(fileLocations FileLocations, targetFiles *TargetFiles, target_scan_ch chan *TargetScan)

func (*Nessus) TargetFilesOnDisk

func (nessus *Nessus) TargetFilesOnDisk(base_path string) *TargetFiles

type TargetFiles

type TargetFiles struct {
	Filepaths []string
	FileNum   int
}

type TargetScan

type TargetScan struct {
	RequestID string
	Method    string
	FileName  string
	IPs       []string
}

Directories

Path Synopsis
Godeps
_workspace/src/github.com/go-sql-driver/mysql
Go MySQL Driver - A MySQL-Driver for Go's database/sql package The driver should be used via the database/sql package: import "database/sql" import _ "github.com/go-sql-driver/mysql" db, err := sql.Open("mysql", "user:password@/dbname") See https://github.com/go-sql-driver/mysql#usage for details
Go MySQL Driver - A MySQL-Driver for Go's database/sql package The driver should be used via the database/sql package: import "database/sql" import _ "github.com/go-sql-driver/mysql" db, err := sql.Open("mysql", "user:password@/dbname") See https://github.com/go-sql-driver/mysql#usage for details
_workspace/src/github.com/mattn/go-sqlite3
Package sqlite3 provides interface to SQLite3 databases.
Package sqlite3 provides interface to SQLite3 databases.
_workspace/src/github.com/parnurzeal/gorequest
Package gorequest inspired by Nodejs SuperAgent provides easy-way to write http client
Package gorequest inspired by Nodejs SuperAgent provides easy-way to write http client
_workspace/src/golang.org/x/crypto/curve25519
Package curve25519 provides an implementation of scalar multiplication on the elliptic curve known as curve25519.
Package curve25519 provides an implementation of scalar multiplication on the elliptic curve known as curve25519.
_workspace/src/golang.org/x/crypto/ssh
Package ssh implements an SSH client and server.
Package ssh implements an SSH client and server.
_workspace/src/golang.org/x/crypto/ssh/agent
Package agent implements a client to an ssh-agent daemon.
Package agent implements a client to an ssh-agent daemon.
_workspace/src/golang.org/x/crypto/ssh/terminal
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
_workspace/src/golang.org/x/crypto/ssh/test
This package contains integration tests for the golang.org/x/crypto/ssh package.
This package contains integration tests for the golang.org/x/crypto/ssh package.
_workspace/src/golang.org/x/net/publicsuffix
Package publicsuffix provides a public suffix list based on data from http://publicsuffix.org/.
Package publicsuffix provides a public suffix list based on data from http://publicsuffix.org/.

Jump to

Keyboard shortcuts

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