Class: HrrRbSsh::Connection::GlobalRequestHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/ssh/hrr_rb_ssh.rb

Instance Method Summary collapse

Instance Method Details

#tcpip_forward(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rex/proto/ssh/hrr_rb_ssh.rb', line 14

def tcpip_forward(message)
  if @connection.permit?(message[:'address to bind'], message[:'port number to bind'], true)
    @logger.info { "starting tcpip-forward" }
    begin
      address_to_bind     = message[:'address to bind']
      port_number_to_bind = message[:'port number to bind']
      id = "#{address_to_bind}:#{port_number_to_bind}"
      server = Rex::Socket::TcpServer.create(
        'LocalHost' => address_to_bind,
        'LocalPort' => port_number_to_bind,
        'Context'   => @connection.options['Context'],
        'Proxies'   => @connection.options['Proxies']
      )
      @tcpip_forward_servers[id] = server
      @tcpip_forward_threads[id] = Thread.new(server){ |server|
        begin
          loop do
            Thread.new(server.accept){ |s|
              @connection.channel_open_start address_to_bind, port_number_to_bind, s
            }
          end
        rescue => e
          @logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
        end
      }
      @logger.info { "tcpip-forward started" }
    rescue => e
      @logger.warn { "starting tcpip-forward failed: #{e.message}" }
      raise e
    end
  else
    # raise Errno::EACCES
  end
end