2005-07-09 21:18:49 +00:00
|
|
|
require 'rex/socket'
|
2005-06-02 07:52:17 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class represents the set of parameters that are used to create
|
|
|
|
# a socket, whether it be a server or client socket.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Rex::Socket::Parameters
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Factory
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-06-03 04:51:51 +00:00
|
|
|
def self.from_hash(hash)
|
|
|
|
return self.new(hash)
|
2005-06-02 07:52:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Constructor
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
# Initializes the attributes from the supplied hash
|
|
|
|
def initialize(hash)
|
|
|
|
if (hash['PeerHost'])
|
|
|
|
self.peerhost = hash['PeerHost']
|
|
|
|
elsif (hash['PeerAddr'])
|
|
|
|
self.peerhost = hash['PeerHost']
|
|
|
|
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'])
|
2005-06-03 22:51:09 +00:00
|
|
|
self.bare = hash['Bare']
|
2005-06-02 07:52:17 +00:00
|
|
|
else
|
|
|
|
self.bare = false
|
|
|
|
end
|
|
|
|
|
2005-06-03 22:51:09 +00:00
|
|
|
if (hash['SSL'])
|
|
|
|
self.ssl = hash['SSL']
|
|
|
|
else
|
|
|
|
self.ssl = false
|
|
|
|
end
|
|
|
|
|
2005-06-02 07:52:17 +00:00
|
|
|
# The protocol this socket will be using
|
2005-06-03 04:51:51 +00:00
|
|
|
if (hash['Proto'])
|
|
|
|
self.proto = hash['Proto'].downcase
|
|
|
|
else
|
|
|
|
self.proto = 'tcp'
|
|
|
|
end
|
2005-06-02 07:52:17 +00:00
|
|
|
|
|
|
|
# Whether or not the socket should be a server
|
|
|
|
self.server = hash['Server'] || false
|
|
|
|
|
|
|
|
# The communication subsystem to use to create the socket
|
2005-09-30 05:48:45 +00:00
|
|
|
self.comm = hash['Comm']
|
|
|
|
|
|
|
|
# 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.comm == nil and hash['PeerHost'])
|
|
|
|
self.comm = Rex::Socket::SwitchBoard.best_comm(hash['PeerHost'])
|
|
|
|
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)
|
2005-06-02 07:52:17 +00:00
|
|
|
|
|
|
|
# The number of connection retries to make (client only)
|
|
|
|
self.retries = hash['Retries'] || 0
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Conditionals
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
def server?
|
|
|
|
return (server == true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def client?
|
|
|
|
return (server == false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def tcp?
|
2005-06-03 04:51:51 +00:00
|
|
|
return (proto == 'tcp')
|
2005-06-02 07:52:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def udp?
|
2005-06-03 04:51:51 +00:00
|
|
|
return (proto == 'udp')
|
2005-06-02 07:52:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def bare?
|
|
|
|
return (bare == true)
|
|
|
|
end
|
|
|
|
|
2005-06-03 22:51:09 +00:00
|
|
|
def ssl?
|
|
|
|
return ssl
|
|
|
|
end
|
|
|
|
|
2005-06-02 07:52:17 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Attributes
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
attr_accessor :peerhost, :peerport
|
|
|
|
attr_accessor :localhost, :localport
|
|
|
|
attr_accessor :proto, :server, :comm
|
2005-06-03 22:51:09 +00:00
|
|
|
attr_accessor :retries, :bare, :ssl
|
2005-06-02 07:52:17 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Synonyms
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
alias peeraddr peerhost
|
|
|
|
alias localaddr localhost
|
|
|
|
|
|
|
|
end
|