Module: Ronin::Network::Mixins::Telnet

Includes:
Mixin
Defined in:
lib/ronin/network/mixins/telnet.rb

Overview

Adds Telnet convenience methods and connection parameters to a class.

Defines the following parameters:

  • host (String) - Telnet host.
  • port (Integer) - Telnet port.
  • telnet_user (String) - Telnet user to login as.
  • telnet_password (String) - Telnet password to login with.
  • telnet_proxy (String) - Telnet proxy.
  • telnet_ssl (Boolean) - Enable Telnet over SSL. Defaults to true.

Instance Method Summary collapse

Methods included from Mixin

included

Instance Method Details

#telnet_connect(options = {}) {|connection| ... } ⇒ Net::Telnet (protected)

Creates a connection to a Telnet server. The host, port, telnet_user, telnet_password, telnet_proxy and telnet_ssl parameters will also be used to connect to the Telnet server.

Examples:

telnet_connect
# => Net::Telnet

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :port (Integer) — default: Ronin::Network::Telnet.default_port

    The port to connect to.

  • :binmode (Boolean)

    Indicates that newline substitution shall not be performed.

  • :output_log (String)

    The name of the file to write connection status messages and all received traffic to.

  • :dump_log (String)

    Similar to the :output_log option, but connection output is also written in hexdump format.

  • :prompt (Regexp) — default: Ronin::Network::Telnet.default_prompt

    A regular expression matching the host command-line prompt sequence, used to determine when a command has finished.

  • :telnet (Boolean) — default: true

    Indicates that the connection shall behave as a telnet connection.

  • :plain (Boolean)

    Indicates that the connection shall behave as a normal TCP connection.

  • :timeout (Integer) — default: Ronin::Network::Telnet.default_timeout

    The number of seconds to wait before timing out both the initial attempt to connect to host, and all attempts to read data from the host.

  • :wait_time (Integer)

    The amount of time to wait after seeing what looks like a prompt.

  • :proxy (Net::Telnet, IO) — default: Ronin::Network::Telnet.proxy

    A proxy object to used instead of opening a direct connection to the host.

  • :user (String)

    The user to login as.

  • :password (String)

    The password to login with.

Yields:

  • (connection)

    If a block is given, it will be passed the newly created Telnet connection.

Yield Parameters:

  • connection (Net::Telnet)

    The newly created Telnet connection.

Returns:

  • (Net::Telnet)

    The Telnet session



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ronin/network/mixins/telnet.rb', line 144

def telnet_connect(options={},&block)
  options[:port] ||= self.port
  options[:user] ||= self.telnet_user
  options[:password] ||= self.telnet_password

  options[:proxy] ||= self.telnet_proxy
  options[:ssl] ||= self.telnet_ssl

  if self.port
    print_info "Connecting to #{self.host}:#{self.port} ..."
  else
    print_info "Connecting to #{self.host} ..."
  end

  return ::Net.telnet_connect(self.host,options,&block)
end

#telnet_session(options = {}) {|session| ... } ⇒ Object (protected)

Starts a session with a Telnet server. The host, port, telnet_user, telnet_password, telnet_proxy and telnet_ssl parameters will also be used to connect to the Telnet server.

Examples:

telnet_session do |movie|
  movie.each_line { |line| puts line }
end

Yields:

  • (session)

    If a block is given, it will be passed the newly created Telnet session. After the block has returned, the Telnet session will be closed.

Yield Parameters:

  • session (Net::Telnet)

    The newly created Telnet session.

See Also:



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/ronin/network/mixins/telnet.rb', line 184

def telnet_session(options={},&block)
  return telnet_connect(options) do |sess|
    yield sess if block_given?
    sess.close

    if self.port
      print_info "Disconnecting to #{self.host}:#{self.port}"
    else
      print_info "Disconnecting to #{self.host}"
    end
  end
end