Class: Rex::Proto::Ssh::ChannelFD

Inherits:
Object
  • Object
show all
Includes:
IO::Stream, IOMergeAbstraction
Defined in:
lib/rex/proto/ssh/connection.rb

Overview

Emulate a single bidirectional IO using the clients Connections Channels IOs

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IOMergeAbstraction

#has_read_data?, #read, #write

Constructor Details

#initialize(parent, chan_id = nil) ⇒ ChannelFD

Returns a new instance of ChannelFD.


270
271
272
# File 'lib/rex/proto/ssh/connection.rb', line 270

def initialize(parent, chan_id = nil)
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent


301
302
303
# File 'lib/rex/proto/ssh/connection.rb', line 301

def parent
  @parent
end

Instance Method Details

#channelHrrRbSsh::Connection::Channel

Expose a Channel from the Connection

Returns:


333
334
335
# File 'lib/rex/proto/ssh/connection.rb', line 333

def channel
  @parent.connection.channels[cid]
end

#cidObject


287
288
289
290
291
292
# File 'lib/rex/proto/ssh/connection.rb', line 287

def cid
  if @cid.nil?
    @cid = @parent.connection.open_channel_keys.first
  end
  @cid
end

#cid=(chan_id) ⇒ Object


294
295
296
297
298
299
300
# File 'lib/rex/proto/ssh/connection.rb', line 294

def cid=(chan_id)
  if @parent.connection.open_channel_keys.include?(chan_id)
    @cid = chan_id
  else
    raise "Invalid Channel ID passed to #{self.inspect}"
  end
end

#closeObject


278
279
280
281
# File 'lib/rex/proto/ssh/connection.rb', line 278

def close
  super
  @parent.close unless @parent.closed?
end

#closed?Boolean

Returns:

  • (Boolean)

283
284
285
# File 'lib/rex/proto/ssh/connection.rb', line 283

def closed?
  super and @parent.closed?
end

#fd_rdIO

Provide a selectable filedescriptor open for reading

Returns:

  • (IO)

    Descriptor for reading


309
310
311
312
313
314
# File 'lib/rex/proto/ssh/connection.rb', line 309

def fd_rd
  begin
    channel.io[0]
  rescue
  end
end

#fd_wr(fd = :stdout) ⇒ IO

Provide a selectable filedescriptor open for writing

Parameters:

  • fd (Symbol) (defaults to: :stdout)

    Output FD type, anything but :stderr uses 1 (STDOUT)

Returns:

  • (IO)

    Descriptor for writing


322
323
324
325
326
327
# File 'lib/rex/proto/ssh/connection.rb', line 322

def fd_wr(fd = :stdout)
  begin
    channel.io[(fd == :stderr ? 2 : 1)]
  rescue
  end
end

#inspectObject


274
275
276
# File 'lib/rex/proto/ssh/connection.rb', line 274

def inspect
  "#{super}/#{@parent.inspect}"
end