Module: Ronin::Support::Network::Telnet::Mixin

Defined in:
lib/ronin/support/network/telnet/mixin.rb

Overview

Provides helper methods for using the Telnet protocol.

Instance Method Summary collapse

Instance Method Details

#telnet_connect(host, proxy: Telnet.proxy, port: Telnet::DEFAULT_PORT, binmode: false, wait_time: 0, prompt: Telnet::DEFAULT_PROMPT, timeout: Telnet.default_timeout, telnet: nil, plain: nil, user: nil, password: nil, output_log: nil, dump_log: nil) {|telnet| ... } ⇒ Net::Telnet

Creates a new Telnet connection.

Examples:

telnet_connect('towel.blinkenlights.nl')
# => #<Net::Telnet: ...>
telnet_connect('towel.blinkenlights.nl') do |movie|
  movie.each_line { |line| puts line }
end

Parameters:

  • host (String)

    The host to connect to.

  • port (Integer) (defaults to: Telnet::DEFAULT_PORT)

    The port to connect to.

  • binmode (Boolean) (defaults to: false)

    Indicates that newline substitution shall not be performed.

  • output_log (String, nil) (defaults to: nil)

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

  • dump_log (String, nil) (defaults to: nil)

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

  • prompt (Regexp) (defaults to: Telnet::DEFAULT_PROMPT)

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

  • telnet (Boolean) (defaults to: nil)

    Indicates that the connection shall behave as a telnet connection.

  • plain (Boolean) (defaults to: nil)

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

  • timeout (Integer) (defaults to: 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) (defaults to: 0)

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

  • proxy (Net::Telnet, IO, nil) (defaults to: Telnet.proxy)

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

  • user (String, nil) (defaults to: nil)

    The user to login as.

  • password (String, nil) (defaults to: nil)

    The password to login with.

Yields:

  • (telnet)

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

Yield Parameters:

  • telnet (Net::Telnet)

    The newly created Telnet session.

Returns:

  • (Net::Telnet)

    The Telnet session



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ronin/support/network/telnet/mixin.rb', line 105

def telnet_connect(host, # connection options
                         proxy:     Telnet.proxy,
                         port:      Telnet::DEFAULT_PORT,
                         binmode:   false,
                         wait_time: 0,
                         prompt:    Telnet::DEFAULT_PROMPT,
                         timeout:   Telnet.default_timeout,
                         telnet:    nil,
                         plain:     nil,
                         # authentication options
                         user:     nil,
                         password: nil,
                         # log options
                         output_log: nil,
                         dump_log:   nil)
  host = DNS::IDN.to_ascii(host)

  telnet_options = {
    'Host'       => host,
    'Port'       => port,
    'Binmode'    => binmode,
    'Waittime'   => wait_time,
    'Prompt'     => prompt,
    'Timeout'    => timeout
  }

  telnet_options['Telnetmode'] = true       if (telnet && !plain)
  telnet_options['Output_log'] = output_log if output_log
  telnet_options['Dump_log']   = dump_log   if dump_log
  telnet_options['Proxy']      = proxy      if proxy

  telnet = Net::Telnet.new(telnet_options)
  telnet.(user,password) if user

  if block_given?
    yield telnet
    telnet.close
  else
    return telnet
  end
end