class Rex::Post::Meterpreter::Extensions::Stdapi::Net::Socket

This class provides an interface to interacting with sockets on the remote machine. It allows callers to open TCP, UDP, and other arbitrary socket-based connections as channels that can then be interacted with through the established meterpreter connection.

Public Class Methods

new(client) click to toggle source

Initialize the socket subsystem and start monitoring sockets as they come in.

# File lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb, line 38
def initialize(client)
  self.client = client

  # register the inbound handler for the tcp server channel (allowing us to
  # receive new client connections to a tcp server channel)
  client.register_inbound_handler( Rex::Post::Meterpreter::Extensions::Stdapi::Net::SocketSubsystem::TcpServerChannel )

end

Public Instance Methods

create( params ) click to toggle source

Creates an arbitrary client socket channel using the information supplied in the socket parameters instance. The params argument is expected to be of type Rex::Socket::Parameters.

# File lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb, line 65
def create( params )
  res = nil

  if( params.tcp? )
    if( params.server? )
      res = create_tcp_server_channel( params )
    else
      res = create_tcp_client_channel( params )
    end
  elsif( params.udp? )
    res = create_udp_channel( params )
  end

  return res
end
create_tcp_client_channel(params) click to toggle source

Creates a TCP client channel.

# File lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb, line 99
def create_tcp_client_channel(params)
  begin
    channel = SocketSubsystem::TcpClientChannel.open(client, params)
    if( channel != nil )
      return channel.lsock
    end
    return nil
  rescue ::Rex::Post::Meterpreter::RequestError => e
    case e.code
    when 10000 .. 10100
      raise ::Rex::ConnectionError.new
    end
    raise e
  end
end
create_tcp_server_channel(params) click to toggle source

Create a TCP server channel.

# File lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb, line 84
def create_tcp_server_channel(params)
  begin
    return SocketSubsystem::TcpServerChannel.open(client, params)
  rescue ::Rex::Post::Meterpreter::RequestError => e
    case e.code
    when 10000 .. 10100
      raise ::Rex::ConnectionError.new
    end
    raise e
  end
end
create_udp_channel(params) click to toggle source

Creates a UDP channel.

# File lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb, line 118
def create_udp_channel(params)
  begin
    return SocketSubsystem::UdpChannel.open(client, params)
  rescue ::Rex::Post::Meterpreter::RequestError => e
    case e.code
      when 10000 .. 10100
      raise ::Rex::ConnectionError.new
    end
    raise e
  end
end
shutdown() click to toggle source

Deregister the inbound handler for the tcp server channel

# File lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb, line 50
def shutdown
  client.deregister_inbound_handler(  Rex::Post::Meterpreter::Extensions::Stdapi::Net::SocketSubsystem::TcpServerChannel )
end