Module: Rex::Post::Meterpreter::SocketAbstraction

Includes:
Channel::SocketAbstraction
Included in:
Datagram, Stream
Defined in:
lib/rex/post/meterpreter/channels/socket_abstraction.rb

Overview

Abstraction


This class represents a channel that is streaming. This means that sequential data is flowing in either one or both directions.

Defined Under Namespace

Modules: DirectChannelWrite

Instance Method Summary collapse

Instance Method Details

#_write(*args) ⇒ Object

Wrap the _write() call in order to catch some common, but harmless Windows exceptions



100
101
102
103
104
105
106
107
108
109
# File 'lib/rex/post/meterpreter/channels/socket_abstraction.rb', line 100

def _write(*args)
  begin
    super(*args)
  rescue ::Rex::Post::Meterpreter::RequestError => e
    case e.code
    when 10000 .. 10100
      raise ::Rex::ConnectionError.new
    end
  end
end

#cleanupObject

Cleans up the stream abstraction.



91
92
93
94
95
# File 'lib/rex/post/meterpreter/channels/socket_abstraction.rb', line 91

def cleanup
  super

  cleanup_abstraction
end

#dio_close_handler(packet) ⇒ Object

Performs a close operation on the right side of the local stream.



82
83
84
85
86
# File 'lib/rex/post/meterpreter/channels/socket_abstraction.rb', line 82

def dio_close_handler(packet)
  rsock.close

  return super(packet)
end

#dio_write_handler(packet, data) ⇒ Object

Performs a write operation on the right side of the local stream.



69
70
71
72
73
74
75
76
77
# File 'lib/rex/post/meterpreter/channels/socket_abstraction.rb', line 69

def dio_write_handler(packet, data)
  rv = Rex::ThreadSafe.select(nil, [rsock], nil, 0.01)
  if(rv)
    rsock.syswrite(data)
    return true
  else
    return false
  end
end

#initialize(client, cid, type, flags, packet, **_) ⇒ Object

Passes the initialization information up to the base class



51
52
53
54
55
56
57
58
# File 'lib/rex/post/meterpreter/channels/socket_abstraction.rb', line 51

def initialize(client, cid, type, flags, packet, **_)
  # sf: initialize_abstraction() before super() as we can get a scenario where dio_write_handler() is called
  # with data to write to the rsock but rsock has not yet been initialized. This happens if the channel
  # is registered (client.add_channel(self) in Channel.initialize) to a session and a COMMAND_ID_CORE_CHANNEL_WRITE
  # request comes in before we have called self.initialize_abstraction()
  initialize_abstraction
  super(client, cid, type, flags, packet)
end