Parent

Class/Module Index [+]

Quicksearch

Rex::Socket::Parameters

This class represents the set of parameters that are used to create a socket, whether it be a server or client socket.

Public Class Methods

from_hash(hash) click to toggle source

Creates an instance of the Parameters class using the supplied hash.

# File lib/rex/socket/parameters.rb, line 20
def self.from_hash(hash)
        return self.new(hash)
end
new(hash) click to toggle source

Initializes the attributes from the supplied hash. The following hash keys can be specified.

PeerHost / PeerAddr

The remote host to connect to.

PeerPort

The remote port to connect to.

LocalHost / LocalAddr

The local host to communicate from, if any.

LocalPort

The local port to communicate from, if any.

Bare

Create a bare socket.

Server

Whether or not this should be a server.

SSL

Whether or not SSL should be used.

SSLVersion

Specify SSL2, SSL3, or TLS1 (SSL3 is default)

SSLCert

A file containing an SSL certificate (for server sockets)

Proxies

List of proxies to use.

Proto

The underlying protocol to use.

IPv6

Force the use of IPv6.

Comm

The underlying Comm class to use to create the socket for this parameter
set.

Context

A context hash that can allow users of this parameter class instance to
determine who is responsible for requesting that a socket be created.

Retries

The number of times a connection should be retried.

Timeout

The number of seconds before a connection should time out
# File lib/rex/socket/parameters.rb, line 101
def initialize(hash)
        if (hash['PeerHost'])
                self.peerhost = hash['PeerHost']
        elsif (hash['PeerAddr'])
                self.peerhost = hash['PeerAddr']
        else
                self.peerhost = nil
        end

        if (hash['LocalHost'])
                self.localhost = hash['LocalHost']
        elsif (hash['LocalAddr'])
                self.localhost = hash['LocalAddr']
        else
                self.localhost = '0.0.0.0'
        end

        if (hash['PeerPort'])
                self.peerport = hash['PeerPort'].to_i
        else
                self.peerport = 0
        end

        if (hash['LocalPort'])
                self.localport = hash['LocalPort'].to_i
        else
                self.localport = 0
        end

        if (hash['Bare'])
                self.bare = hash['Bare']
        else
                self.bare = false
        end

        if (hash['SSL'] and hash['SSL'].to_s =~ /^(t|y|1)/)
                self.ssl = true
        else
                self.ssl = false
        end

        if (hash['SSLVersion'] and hash['SSLVersion'].to_s =~ /^(SSL2|SSL3|TLS1)$/)
                self.ssl_version = hash['SSLVersion']
        end

        if (hash['SSLCert'] and ::File.file?(hash['SSLCert']))
                begin
                        self.ssl_cert = ::File.read(hash['SSLCert'])
                rescue ::Exception => e
                        elog("Failed to read cert: #{e.class}: #{e}", LogSource)
                end
        end

        if hash['Proxies']
                self.proxies = hash['Proxies'].split('-').map{|a| a.strip}.map{|a| a.split(':').map{|b| b.strip}}
        end

        # The protocol this socket will be using
        if (hash['Proto'])
                self.proto = hash['Proto'].downcase
        else
                self.proto = 'tcp'
        end

        # Whether or not the socket should be a server
        self.server    = hash['Server'] || false

        # The communication subsystem to use to create the socket
        self.comm      = hash['Comm']

        # The context that was passed in, if any.
        self.context   = hash['Context'] || {}

        # If no comm was supplied, try to use the comm that is best fit to
        # handle the provided host based on the current routing table.
        if( self.server )
                if (self.comm == nil and self.localhost)
                        self.comm  = Rex::Socket::SwitchBoard.best_comm(self.localhost)
                end
        else
                if (self.comm == nil and self.peerhost)
                        self.comm  = Rex::Socket::SwitchBoard.best_comm(self.peerhost)
                end
        end

        # If we still haven't found a comm, we default to the local comm.
        self.comm      = Rex::Socket::Comm::Local if (self.comm == nil)

        # If we are a UDP server, turn off the server flag as it was only set when
        # creating the UDP socket in order to avail of the switch board above.
        if( self.server and self.proto == 'udp' )
                self.server = false
        end

        # The number of connection retries to make (client only)
        if hash['Retries']
                self.retries = hash['Retries'].to_i
        else
                self.retries = 0
        end

        # The number of seconds before a connect attempt times out (client only)
        if hash['Timeout']
                self.timeout = hash['Timeout'].to_i
        else
                self.timeout = 5
        end

        # Whether to force IPv6 addressing
        self.v6        = hash['IPv6'] || false
end

Public Instance Methods

bare?() click to toggle source

Returns true if the socket is a bare socket that does not inherit from any extended Rex classes.

# File lib/rex/socket/parameters.rb, line 258
def bare?
        return (bare == true)
end
client?() click to toggle source

Returns true if this represents parameters for a client.

# File lib/rex/socket/parameters.rb, line 229
def client?
        return (server == false)
end
ip?() click to toggle source

Returns true if the protocol for the parameters is IP.

# File lib/rex/socket/parameters.rb, line 250
def ip?
        return (proto == 'ip')
end
server?() click to toggle source

Returns true if this represents parameters for a server.

# File lib/rex/socket/parameters.rb, line 222
def server?
        return (server == true)
end
ssl?() click to toggle source

Returns true if SSL has been requested.

# File lib/rex/socket/parameters.rb, line 265
def ssl?
        return ssl
end
tcp?() click to toggle source

Returns true if the protocol for the parameters is TCP.

# File lib/rex/socket/parameters.rb, line 236
def tcp?
        return (proto == 'tcp')
end
udp?() click to toggle source

Returns true if the protocol for the parameters is UDP.

# File lib/rex/socket/parameters.rb, line 243
def udp?
        return (proto == 'udp')
end
v6?() click to toggle source

Returns true if IPv6 has been enabled

# File lib/rex/socket/parameters.rb, line 272
def v6?
        return v6
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.