Class: Rex::Proto::Ssh::Connection
- Inherits:
-
HrrRbSsh::Connection
- Object
- HrrRbSsh::Connection
- Rex::Proto::Ssh::Connection
- Includes:
- AccessControlList
- Defined in:
- lib/rex/proto/ssh/connection.rb
Overview
Encapsulation of Connection constructor for Rex use Provides ACLs for port forwarding and client (io) access hooks
Instance Attribute Summary collapse
-
#authentication ⇒ Object
Returns the value of attribute authentication.
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#global_request_handler ⇒ Object
Returns the value of attribute global_request_handler.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#transport ⇒ Object
Returns the value of attribute transport.
Class Method Summary collapse
Instance Method Summary collapse
-
#close ⇒ Object
Close the connection and underlying socket.
-
#initialize(io = nil, options = self.default_options, context = {}) ⇒ Rex::Proto::Ssh::Connection
constructor
Create new Connection from an IO and options set, pull trans and auth from options if present, create from options set otherwise.
-
#open_channel_keys(ctype = 'session') ⇒ Array
Provide keys of explicitly not closed channels.
-
#reader(fd = 0, cn = open_channel_keys.first) ⇒ IO
Provide IO from which to read remote-end inputs.
-
#writer(fd = 1, cn = open_channel_keys.first) ⇒ IO
Provide IO into which writes to the remote end can be sent.
Methods included from AccessControlList
Constructor Details
#initialize(io = nil, options = self.default_options, context = {}) ⇒ Rex::Proto::Ssh::Connection
Create new Connection from an IO and options set, pull trans and auth from options if present, create from options set otherwise.
Creates a default empty handler set for channel requests.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rex/proto/ssh/connection.rb', line 82 def initialize(io = nil, = self., context = {}) @context = context @logger = Logger.new self.class.name @server = .delete(:ssh_server) @mode = .delete(:ssh_mode) || HrrRbSsh::Mode::SERVER # Take a pre-built transport from the options or build one on the fly @transport = .delete(:ssh_transport) || HrrRbSsh::Transport.new( io, @mode, ) # Take a pre-built authentication from the options or build one on the fly @authentication = .delete(:ssh_authentication) || HrrRbSsh::Authentication.new(@transport, @mode, ) @global_request_handler = GlobalRequestHandler.new(self) # Retain remaining options for later use @options = @channels = Hash.new @username = nil @closed = nil end |
Instance Attribute Details
#authentication ⇒ Object
Returns the value of attribute authentication.
149 150 151 |
# File 'lib/rex/proto/ssh/connection.rb', line 149 def authentication @authentication end |
#channels ⇒ Object
Returns the value of attribute channels.
149 150 151 |
# File 'lib/rex/proto/ssh/connection.rb', line 149 def channels @channels end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
150 151 152 |
# File 'lib/rex/proto/ssh/connection.rb', line 150 def context @context end |
#global_request_handler ⇒ Object
Returns the value of attribute global_request_handler.
149 150 151 |
# File 'lib/rex/proto/ssh/connection.rb', line 149 def global_request_handler @global_request_handler end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
150 151 152 |
# File 'lib/rex/proto/ssh/connection.rb', line 150 def server @server end |
#transport ⇒ Object
Returns the value of attribute transport.
149 150 151 |
# File 'lib/rex/proto/ssh/connection.rb', line 149 def transport @transport end |
Class Method Details
.default_options ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rex/proto/ssh/connection.rb', line 62 def self. noneauth = HrrRbSsh::Authentication::Authenticator.new { |context| true } return { 'authentication_none_authenticator' => noneauth, 'authentication_password_authenticator' => noneauth, 'authentication_publickey_authenticator' => noneauth, 'authentication_keyboard_interactive_authenticator' => noneauth, 'local_version' => 'SSH-2.0-RexProtoSsh' } end |
Instance Method Details
#close ⇒ Object
Close the connection and underlying socket
144 145 146 147 |
# File 'lib/rex/proto/ssh/connection.rb', line 144 def close super @transport.io.close if @transport and !@transport.io.closed? end |
#open_channel_keys(ctype = 'session') ⇒ Array
Provide keys of explicitly not closed channels
111 112 113 114 115 116 117 |
# File 'lib/rex/proto/ssh/connection.rb', line 111 def open_channel_keys(ctype = 'session') channels.keys.sort.select do |cn| channels[cn].closed? === false and ( ctype.nil? or channels[cn].channel_type == ctype ) end end |
#reader(fd = 0, cn = open_channel_keys.first) ⇒ IO
Provide IO from which to read remote-end inputs
126 127 128 |
# File 'lib/rex/proto/ssh/connection.rb', line 126 def reader(fd = 0, cn = open_channel_keys.first) channels[cn].io[fd] end |
#writer(fd = 1, cn = open_channel_keys.first) ⇒ IO
Provide IO into which writes to the remote end can be sent
137 138 139 |
# File 'lib/rex/proto/ssh/connection.rb', line 137 def writer(fd = 1, cn = open_channel_keys.first) channels[cn].io[fd] end |