channel

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeoutOpsSeconds is the default time value for operations -- 60 seconds.
	DefaultTimeoutOpsSeconds = 60
	// DefaultReadDelayMicroSeconds is the default value for the delay between reads of the
	// transport -- 5 microseconds.
	DefaultReadDelayMicroSeconds = 5
	// DefaultReturnChar is the character used to send an "enter" key to the device, "\n".
	DefaultReturnChar = "\n"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	TimeoutOps time.Duration
	ReadDelay  time.Duration

	AuthBypass bool

	UsernamePattern   *regexp.Regexp
	PasswordPattern   *regexp.Regexp
	PassphrasePattern *regexp.Regexp

	PromptPattern *regexp.Regexp
	ReturnChar    []byte

	Q    *util.Queue
	Errs chan error

	ChannelLog io.Writer
	// contains filtered or unexported fields
}

Channel is an object that sits "on top" of a scrapligo Transport object, its purpose in life is to read data from the transport into its Q, and provide methods to read "until" an input or an expected prompt is seen.

func NewChannel

func NewChannel(
	l *logging.Instance,
	t *transport.Transport,
	options ...util.Option,
) (*Channel, error)

NewChannel returns a scrapligo Channel object.

func (*Channel) AuthenticateSSH

func (c *Channel) AuthenticateSSH(p, pp []byte) ([]byte, error)

AuthenticateSSH handles "in channel" SSH authentication.

func (*Channel) AuthenticateTelnet

func (c *Channel) AuthenticateTelnet(u, p []byte) ([]byte, error)

AuthenticateTelnet handles "in channel" telnet authentication.

func (*Channel) Close

func (c *Channel) Close() error

Close signals to stop the channel read loop and closes the underlying Transport object.

func (*Channel) GetPrompt

func (c *Channel) GetPrompt() ([]byte, error)

GetPrompt returns a byte slice containing the current "prompt" of the connected ssh/telnet server.

func (*Channel) GetTimeout

func (c *Channel) GetTimeout(t time.Duration) time.Duration

GetTimeout returns the target timeout for an operation based on the TimeoutOps attribute of the Channel and the value t.

func (*Channel) Open

func (c *Channel) Open() error

Open opens the underlying Transport and begins the `read` goroutine, this also kicks off any in channel authentication (if necessary).

func (*Channel) Read

func (c *Channel) Read() ([]byte, error)

Read reads and returns the first available bytes from the channel Q object. If there are any errors on the Errs channel (these would come from the underlying transport), the error is returned with nil for the byte slice.

func (*Channel) ReadAll

func (c *Channel) ReadAll() ([]byte, error)

ReadAll reads and returns *all* available bytes form the channel Q object. If there are any errors on the Errs channel (these would come from the underlying transport), the error is returned with nil for the byte slice. Be careful using this as it is possible to dequeue "too much" from the channel causing us to not be able to "find" the prompt or inputs during normal operations. In general, this should probably only be used when connecting to consoles/files.

func (*Channel) ReadUntilAnyPrompt

func (c *Channel) ReadUntilAnyPrompt(prompts []*regexp.Regexp) ([]byte, error)

ReadUntilAnyPrompt reads bytes out of the channel Q object until any of the prompts in the "prompts" argument are seen in the output. Once any pattern is seen, all read bytes are returned.

func (*Channel) ReadUntilExplicit

func (c *Channel) ReadUntilExplicit(b []byte) ([]byte, error)

ReadUntilExplicit reads bytes out of the channel Q object until the bytes b are seen in the output. Once the bytes are seen all read bytes are returned.

func (*Channel) ReadUntilInput

func (c *Channel) ReadUntilInput(b []byte) ([]byte, error)

ReadUntilInput reads bytes out of the channel Q object until the "input" bytes b are "seen" in the channel output. Once b is seen, all read bytes are returned.

func (*Channel) ReadUntilPrompt

func (c *Channel) ReadUntilPrompt() ([]byte, error)

ReadUntilPrompt reads bytes out of the channel Q object until the channel PromptPattern regex pattern is seen in the output. Once that pattern is seen, all read bytes are returned.

func (*Channel) SendInput

func (c *Channel) SendInput(input string, opts ...util.Option) ([]byte, error)

SendInput sends the input string to the target device. Any bytes output is returned.

func (*Channel) SendInputB

func (c *Channel) SendInputB(input []byte, opts ...util.Option) ([]byte, error)

SendInputB sends the given input bytes to the device and returns the bytes read.

func (*Channel) SendInteractive

func (c *Channel) SendInteractive(
	events []*SendInteractiveEvent,
	opts ...util.Option,
) ([]byte, error)

SendInteractive sends a slice of SendInteractiveEvent to the device. This is typically used to handle any well understood "interactive" prompts on a device -- things like "clear logging" which prompts the user to confirm, or handling privilege escalation where there is a password prompt.

func (*Channel) Write

func (c *Channel) Write(b []byte, r bool) error

Write writes the given bytes b to the channel.

func (*Channel) WriteAndReturn

func (c *Channel) WriteAndReturn(b []byte, r bool) error

WriteAndReturn writes the given bytes b and then sends the channel ReturnChar.

func (*Channel) WriteReturn

func (c *Channel) WriteReturn() error

WriteReturn writes the channel ReturnChar to the channel.

type OperationOptions

type OperationOptions struct {
	StripPrompt      bool
	Eager            bool
	Timeout          time.Duration
	CompletePatterns []*regexp.Regexp
}

OperationOptions is a struct containing "operation" options -- things like if the channel should strip the device prompt out, send eagerly (without reading until the input), and the timeout for the given operation.

func NewOperation

func NewOperation(options ...util.Option) (*OperationOptions, error)

NewOperation returns a new OperationOptions object with the defaults set and any provided options applied.

type SendInteractiveEvent

type SendInteractiveEvent struct {
	ChannelInput    string
	ChannelResponse string
	HideInput       bool
}

SendInteractiveEvent is a struct representing a single "event" that can be sent to SendInteractive this event contains the input to send, the response to expect, and whether scrapligo should expect to see the input or if it is hidden (as is the case with passwords for privilege escalation).

Jump to

Keyboard shortcuts

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