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.



254
255
256
# File 'lib/rex/proto/ssh/connection.rb', line 254

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

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



285
286
287
# File 'lib/rex/proto/ssh/connection.rb', line 285

def parent
  @parent
end

Instance Method Details

#channelHrrRbSsh::Connection::Channel

Expose a Channel from the Connection

Returns:



319
320
321
# File 'lib/rex/proto/ssh/connection.rb', line 319

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

#cidObject



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

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

#cid=(chan_id) ⇒ Object



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

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



262
263
264
265
# File 'lib/rex/proto/ssh/connection.rb', line 262

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

#closed?Boolean

Returns:

  • (Boolean)


267
268
269
# File 'lib/rex/proto/ssh/connection.rb', line 267

def closed?
  super and @parent.closed?
end

#fd_rdIO

Provide a selectable filedescriptor open for reading

Returns:

  • (IO)

    Descriptor for reading



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

def fd_rd
  begin
    channel.io[0]
  rescue => e
    elog(e)
  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



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

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

#inspectObject



258
259
260
# File 'lib/rex/proto/ssh/connection.rb', line 258

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