Documentation ¶
Index ¶
- Constants
- type Channel
- func (c *Channel) AuthenticateSSH(p, pp []byte) ([]byte, error)
- func (c *Channel) AuthenticateTelnet(u, p []byte) ([]byte, error)
- func (c *Channel) Close() error
- func (c *Channel) GetPrompt() ([]byte, error)
- func (c *Channel) GetTimeout(t time.Duration) time.Duration
- func (c *Channel) Open() error
- func (c *Channel) Read() ([]byte, error)
- func (c *Channel) ReadAll() ([]byte, error)
- func (c *Channel) ReadUntilAnyPrompt(prompts []*regexp.Regexp) ([]byte, error)
- func (c *Channel) ReadUntilExplicit(b []byte) ([]byte, error)
- func (c *Channel) ReadUntilInput(b []byte) ([]byte, error)
- func (c *Channel) ReadUntilPrompt() ([]byte, error)
- func (c *Channel) SendInput(input string, opts ...util.Option) ([]byte, error)
- func (c *Channel) SendInputB(input []byte, opts ...util.Option) ([]byte, error)
- func (c *Channel) SendInteractive(events []*SendInteractiveEvent, opts ...util.Option) ([]byte, error)
- func (c *Channel) Write(b []byte, r bool) error
- func (c *Channel) WriteAndReturn(b []byte, r bool) error
- func (c *Channel) WriteReturn() error
- type OperationOptions
- type SendInteractiveEvent
Constants ¶
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 ¶
AuthenticateSSH handles "in channel" SSH authentication.
func (*Channel) AuthenticateTelnet ¶
AuthenticateTelnet handles "in channel" telnet authentication.
func (*Channel) Close ¶
Close signals to stop the channel read loop and closes the underlying Transport object.
func (*Channel) GetPrompt ¶
GetPrompt returns a byte slice containing the current "prompt" of the connected ssh/telnet server.
func (*Channel) GetTimeout ¶
GetTimeout returns the target timeout for an operation based on the TimeoutOps attribute of the Channel and the value t.
func (*Channel) Open ¶
Open opens the underlying Transport and begins the `read` goroutine, this also kicks off any in channel authentication (if necessary).
func (*Channel) Read ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
SendInput sends the input string to the target device. Any bytes output is returned.
func (*Channel) SendInputB ¶
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) WriteAndReturn ¶
WriteAndReturn writes the given bytes b and then sends the channel ReturnChar.
func (*Channel) WriteReturn ¶
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 ¶
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).