Class: Msf::Sessions::Modem::TcpClientChannel

Inherits:
ChannelBase
  • Object
show all
Includes:
Rex::Post::Channel::StreamAbstraction
Defined in:
lib/msf/base/sessions/modem.rb

Overview


Generic TCP client channel

Uses Rex::Post::Channel::StreamAbstraction to create an lsock/rsock pair. A dedicated reader thread drains recv from the underlying modem connection and writes into rsock, making data visible to lsock readers. The framework writes outbound data via write(), which forwards to the connection’s send() method.


Defined Under Namespace

Modules: SocketInterface

Instance Attribute Summary

Attributes inherited from ChannelBase

#cid, #params

Instance Method Summary collapse

Methods included from Rex::Post::Channel::StreamAbstraction

#read

Methods inherited from ChannelBase

#close, #closed?, #remote_closed, #remote_closed?

Constructor Details

#initialize(session, cid, conn, params) ⇒ TcpClientChannel

Create a new TcpClientChannel.

Parameters:

  • session (Modem)

    parent session

  • cid (Integer)

    channel ID, unique within the session

  • conn (#recv)

    modem connection object

  • params (Rex::Socket::Parameters)


202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/msf/base/sessions/modem.rb', line 202

def initialize(session, cid, conn, params)
  initialize_abstraction
  super

  start_reader_thread('ModemTcpClientChannelReader') do |data|
    rsock.syswrite(data)
    true
  rescue ::StandardError
    false
  end

  lsock.extend(SocketInterface)
  lsock.channel = self
  rsock.extend(SocketInterface)
  rsock.channel = self

  lsock.synchronize_access { lsock.initsock(params) }
  rsock.synchronize_access { rsock.initsock(params) }

  session.add_channel(self)
end

Instance Method Details

#monitor_rsock(name = 'ModemTcpClientRemote') ⇒ Object



190
191
192
# File 'lib/msf/base/sessions/modem.rb', line 190

def monitor_rsock(name = 'ModemTcpClientRemote')
  monitor_sock(rsock, sink: self, name: name, on_exit: method(:close))
end

#write(buf, length = nil) ⇒ Object

Send data toward the remote host through the modem connection.



227
228
229
# File 'lib/msf/base/sessions/modem.rb', line 227

def write(buf, length = nil)
  send_to_connection(buf, length)
end