host

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeWindowsOS added in v1.5.2

func NormalizeWindowsOS(caption, buildNumber string) string

NormalizeWindowsOS converts the raw Win32_OperatingSystem Caption (and the numeric BuildNumber) into the OS identifier expected by the Vulners audit API (e.g. "Windows 10", "Windows 11", "Windows Server 2022").

Returns "Windows" when the caption cannot be confidently mapped so that the caller surfaces the API's rejection rather than silently miscategorizing.

func ParseWindowsSoftware added in v1.5.2

func ParseWindowsSoftware(lines []string) []vulners.WinAuditItem

ParseWindowsSoftware converts "name\tversion" lines (tab-separated by the PowerShell collector) into WinAuditItem values. Lines without a tab are treated as name-only with an empty version.

Types

type Executor

type Executor interface {
	// Execute runs a command and returns its standard output as a string.
	// It should return an error if the command fails to execute or exits with a non-zero status.
	Execute(ctx context.Context, cmd string) (string, error)

	// Close cleans up any resources associated with the executor.
	Close() error
}

Executor defines an interface for running commands on a target host.

func NewExecutorFromURI

func NewExecutorFromURI(ctx context.Context, target string, opts ExecutorOptions) (Executor, error)

NewExecutorFromURI creates a new Executor based on the provided target URI and options.

type ExecutorOptions

type ExecutorOptions struct {
	IdentityFile string
	PasswordEnv  string
	AskPass      bool
	Insecure     bool
	Timeout      time.Duration
}

ExecutorOptions holds configuration for creating an Executor.

type LocalExecutor

type LocalExecutor struct{}

LocalExecutor executes commands on the local machine.

func NewLocalExecutor

func NewLocalExecutor() *LocalExecutor

NewLocalExecutor returns a new LocalExecutor.

func (*LocalExecutor) Close

func (e *LocalExecutor) Close() error

Close is a no-op for LocalExecutor.

func (*LocalExecutor) Execute

func (e *LocalExecutor) Execute(ctx context.Context, cmd string) (string, error)

Execute runs the given command locally using the appropriate shell.

type OSFamily

type OSFamily string

OSFamily represents the package management family of an OS.

const (
	FamilyDeb     OSFamily = "debian"
	FamilyRPM     OSFamily = "rpm"
	FamilyAlpine  OSFamily = "alpine"
	FamilyWindows OSFamily = "windows"
	FamilyUnknown OSFamily = "unknown"
)

type OSInfo

type OSInfo struct {
	Family  OSFamily
	Distro  string // For Linux: ID from os-release
	Version string // Linux: VERSION_ID from os-release; Windows: full version (e.g. "10.0.19045")
	OSName  string // For Windows: Caption (raw, e.g. "Microsoft Windows 10 Pro")

	// BuildNumber is the Windows build segment used to disambiguate Windows 10
	// vs Windows 11 (captions report "Windows 10" for both).
	BuildNumber string
}

OSInfo holds the fingerprinted operating system data.

type SSHExecutor

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

SSHExecutor executes commands on a remote host via SSH.

func NewSSHExecutor

func NewSSHExecutor(opts SSHOptions) (*SSHExecutor, error)

NewSSHExecutor connects to an SSH server and returns an SSHExecutor.

func (*SSHExecutor) Close

func (e *SSHExecutor) Close() error

Close closes the underlying SSH connection.

func (*SSHExecutor) Execute

func (e *SSHExecutor) Execute(ctx context.Context, cmd string) (string, error)

Execute runs the command on the remote host over SSH.

type SSHOptions

type SSHOptions struct {
	Host         string
	Port         string
	User         string
	IdentityFile string
	Password     string //nolint:gosec // false positive for struct field name
	Insecure     bool
	Timeout      time.Duration
}

SSHOptions holds the configuration for an SSH connection.

type Scanner

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

Scanner performs host inventory scanning.

func NewScanner

func NewScanner(exec Executor, logger *slog.Logger) *Scanner

NewScanner creates a new Scanner using the provided Executor. A nil logger discards diagnostic output.

func (*Scanner) DetectOS

func (s *Scanner) DetectOS(ctx context.Context) (*OSInfo, error)

DetectOS attempts to determine the target's operating system using the executor.

func (*Scanner) GatherPackages

func (s *Scanner) GatherPackages(ctx context.Context, info *OSInfo) ([]string, error)

GatherPackages retrieves the list of installed Linux packages for the detected OS family. Use GatherWindows for Windows hosts.

func (*Scanner) GatherWindows added in v1.5.2

func (s *Scanner) GatherWindows(ctx context.Context, _ *OSInfo) ([]string, []vulners.WinAuditItem, error)

GatherWindows retrieves installed KBs and software inventory from a Windows host. Software is collected via Get-Package first, falling back to the Uninstall registry keys when Get-Package returns nothing or fails.

type WinRMExecutor

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

WinRMExecutor executes commands on a remote Windows host via WinRM.

func NewWinRMExecutor

func NewWinRMExecutor(opts WinRMOptions) (*WinRMExecutor, error)

NewWinRMExecutor connects to a WinRM endpoint and returns a WinRMExecutor.

func (*WinRMExecutor) Close

func (e *WinRMExecutor) Close() error

Close is a no-op for WinRMExecutor as the client does not maintain an active TCP connection pool.

func (*WinRMExecutor) Execute

func (e *WinRMExecutor) Execute(ctx context.Context, cmd string) (string, error)

Execute runs the command on the remote host over WinRM.

type WinRMOptions

type WinRMOptions struct {
	Host     string
	Port     string
	User     string
	Password string //nolint:gosec // false positive for struct field name
	HTTPS    bool
	Insecure bool
	Timeout  time.Duration
}

WinRMOptions holds the configuration for a WinRM connection.

Jump to

Keyboard shortcuts

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