Class: Msf::Sessions::SshCommandShellBind::TcpServerChannel

Inherits:
Object
  • Object
show all
Includes:
Rex::IO::StreamServer
Defined in:
lib/msf/base/sessions/ssh_command_shell_bind.rb

Overview

Represents an SSH reverse port forward. Will receive connection messages back from the SSH server, whereupon a TcpClientChannel will be opened

Instance Method Summary collapse

Constructor Details

#initialize(params, client, host, port) ⇒ TcpServerChannel

Returns a new instance of TcpServerChannel.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 147

def initialize(params, client, host, port)
  @params = params
  @client = client
  @host = host
  @port = port
  @channels = []
  @closed = false
  @mutex = Mutex.new
  @condition = ConditionVariable.new

  if params.ssl
    extend(Rex::Socket::SslTcpServer)
    initsock(params)
  end
end

Instance Method Details

#_acceptObject (protected)



205
206
207
208
209
210
211
212
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 205

def _accept
  result = nil
  channel = @channels.pop
  if channel
    result = channel.lsock
  end
  result
end

#accept(opts = {}) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 163

def accept(opts = {})
  timeout = opts['Timeout']
  if (timeout.nil? || timeout <= 0)
    timeout = nil
  end

  @mutex.synchronize {
    if @channels.length > 0
      return _accept
    end
    @condition.wait(@mutex, timeout)
    return _accept
  }
end

#closeObject



182
183
184
185
186
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 182

def close
  if !closed?
    @closed = @client.stop_server_channel(@host, @port)
  end
end

#closed?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 178

def closed?
  @closed
end

#create(cid, ssh_channel, peer_host, peer_port) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/msf/base/sessions/ssh_command_shell_bind.rb', line 188

def create(cid, ssh_channel, peer_host, peer_port)
  @mutex.synchronize {
    peer_info = {
      'PeerHost' => peer_host,
      'PeerPort' => peer_port
    }
    params = @params.merge(peer_info)
    channel = TcpClientChannel.new(@client, cid, ssh_channel, params)
    @channels.insert(0, channel)

    # Let any waiting thread know we're ready
    @condition.signal
  }
end