Class: Rex::Socket::Parameters
- Inherits:
-
Object
- Object
- Rex::Socket::Parameters
- Defined in:
- lib/rex/socket/parameters.rb
Overview
This class represents the set of parameters that are used to create a socket, whether it be a server or client socket.
Instance Attribute Summary collapse
- #bare ⇒ Object
- #comm ⇒ Object
- #context ⇒ Object
- #localhost ⇒ Object (also: #localaddr)
- #localport ⇒ Object
-
#peerhost ⇒ String
(also: #peeraddr)
The remote host information, equivalent to the PeerHost parameter hash key.
- #peerport ⇒ Object
- #proto ⇒ Object
-
#proxies ⇒ Array
List of proxies to use.
- #retries ⇒ Object
- #server ⇒ Object
- #ssl ⇒ Object
-
#ssl_cert ⇒ String
The SSL certificate, in pem format, stored as a string.
-
#ssl_cipher ⇒ String, Array
What specific SSL Cipher(s) to use, may be a string containing the cipher name or an array of strings containing cipher names e.g.
-
#ssl_client_cert ⇒ Object
The client SSL certificate.
-
#ssl_client_key ⇒ Object
The client SSL key.
-
#ssl_cn ⇒ String
Which Common Name to use for certificate.
-
#ssl_compression ⇒ Bool
Enables SSL/TLS-level compression.
-
#ssl_verify_mode ⇒ Object
SSL certificate verification mode for SSL context.
-
#ssl_version ⇒ String, Symbol
What version of SSL to use (Auto, SSL2, SSL3, SSL23, TLS1).
-
#sslctx ⇒ OpenSSL::SSL::SSLContext
Pre configured SSL Context to use.
- #timeout ⇒ Object
- #v6 ⇒ Object
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the Parameters class using the supplied hash.
Instance Method Summary collapse
-
#bare? ⇒ Boolean
Returns true if the socket is a bare socket that does not inherit from any extended Rex classes.
-
#client? ⇒ Boolean
Returns true if this represents parameters for a client.
-
#initialize(hash = {}) ⇒ Parameters
constructor
Initializes the attributes from the supplied hash.
-
#ip? ⇒ Boolean
Returns true if the protocol for the parameters is IP.
- #merge(other) ⇒ Object
- #merge!(other) ⇒ Object
-
#server? ⇒ Boolean
Returns true if this represents parameters for a server.
-
#ssl? ⇒ Boolean
Returns true if SSL has been requested.
-
#tcp? ⇒ Boolean
Returns true if the protocol for the parameters is TCP.
-
#udp? ⇒ Boolean
Returns true if the protocol for the parameters is UDP.
-
#v6? ⇒ Boolean
Returns true if IPv6 has been enabled.
Constructor Details
#initialize(hash = {}) ⇒ Parameters
Initializes the attributes from the supplied hash. The following hash keys can be specified.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/rex/socket/parameters.rb', line 80 def initialize(hash = {}) if (hash['PeerHost']) self.peerhost = hash['PeerHost'] elsif (hash['PeerAddr']) self.peerhost = hash['PeerAddr'] end if (hash['LocalHost']) self.localhost = hash['LocalHost'] elsif (hash['LocalAddr']) self.localhost = hash['LocalAddr'] end if (hash['PeerPort']) self.peerport = hash['PeerPort'].to_i end if (hash['LocalPort']) self.localport = hash['LocalPort'].to_i end if (hash['Bare']) self. = hash['Bare'] end if (hash['SSL'] and hash['SSL'].to_s =~ /^(t|y|1)/i) self.ssl = true end if hash['SSLContext'] self.sslctx = hash['SSLContext'] end self.ssl_version = hash.fetch('SSLVersion', nil) supported_ssl_verifiers = %W{CLIENT_ONCE FAIL_IF_NO_PEER_CERT NONE PEER} if (hash['SSLVerifyMode'] and supported_ssl_verifiers.include? hash['SSLVerifyMode']) self.ssl_verify_mode = hash['SSLVerifyMode'] end if hash['SSLCompression'] self.ssl_compression = hash['SSLCompression'] end if (hash['SSLCipher']) self.ssl_cipher = hash['SSLCipher'] end if (hash['VHOST']) self.ssl_cn = hash['VHOST'] end if (hash['SSLCommonName']) self.ssl_cn = hash['SSLCommonName'] 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['SSLClientCert'] and ::File.file?(hash['SSLClientCert'])) begin self.ssl_client_cert = ::File.read(hash['SSLClientCert']) rescue ::Exception => e elog("Failed to read client cert: #{e.class}: #{e}", LogSource) end end if (hash['SSLClientKey'] and ::File.file?(hash['SSLClientKey'])) begin self.ssl_client_key = ::File.read(hash['SSLClientKey']) rescue ::Exception => e elog("Failed to read client key: #{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 end # Whether or not the socket should be a server self.server = hash['Server'] # 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 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 end # The number of seconds before a connect attempt times out (client only) if hash['Timeout'] self.timeout = hash['Timeout'].to_i end # Whether to force IPv6 addressing self.v6 = hash['IPv6'] end |
Instance Attribute Details
#bare ⇒ Object
366 367 368 |
# File 'lib/rex/socket/parameters.rb', line 366 def @comm || false end |
#comm ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/rex/socket/parameters.rb', line 326 def comm return @comm unless @comm.nil? best_comm = nil # If no comm was explicitly specified, try to use the comm that is best fit # to handle the provided host based on the current routing table. if server and localhost best_comm = Rex::Socket::SwitchBoard.best_comm(localhost) elsif peerhost best_comm = Rex::Socket::SwitchBoard.best_comm(peerhost) end best_comm || Rex::Socket::Comm::Local end |
#context ⇒ Object
344 345 346 |
# File 'lib/rex/socket/parameters.rb', line 344 def context @context || {} end |
#localhost ⇒ Object Also known as: localaddr
296 297 298 |
# File 'lib/rex/socket/parameters.rb', line 296 def localhost @localhost || '0.0.0.0' end |
#localport ⇒ Object
303 304 305 |
# File 'lib/rex/socket/parameters.rb', line 303 def localport @localport || 0 end |
#peerhost ⇒ String Also known as: peeraddr
The remote host information, equivalent to the PeerHost parameter hash key.
284 285 286 |
# File 'lib/rex/socket/parameters.rb', line 284 def peerhost @peerhost end |
#peerport ⇒ Object
289 290 291 |
# File 'lib/rex/socket/parameters.rb', line 289 def peerport @peerport || 0 end |
#proto ⇒ Object
311 312 313 |
# File 'lib/rex/socket/parameters.rb', line 311 def proto @proto || 'tcp' end |
#proxies ⇒ Array
List of proxies to use
448 449 450 |
# File 'lib/rex/socket/parameters.rb', line 448 def proxies @proxies end |
#retries ⇒ Object
351 352 353 |
# File 'lib/rex/socket/parameters.rb', line 351 def retries @retries || 0 end |
#server ⇒ Object
319 320 321 |
# File 'lib/rex/socket/parameters.rb', line 319 def server @server || false end |
#ssl ⇒ Object
373 374 375 |
# File 'lib/rex/socket/parameters.rb', line 373 def ssl @ssl || false end |
#ssl_cert ⇒ String
The SSL certificate, in pem format, stored as a string. See SslTcpServer#makessl
418 419 420 |
# File 'lib/rex/socket/parameters.rb', line 418 def ssl_cert @ssl_cert end |
#ssl_cipher ⇒ String, Array
What specific SSL Cipher(s) to use, may be a string containing the cipher name or an array of strings containing cipher names e.g. ["DHE-RSA-AES256-SHA", "DHE-DSS-AES256-SHA"]
409 410 411 |
# File 'lib/rex/socket/parameters.rb', line 409 def ssl_cipher @ssl_cipher end |
#ssl_client_cert ⇒ Object
The client SSL certificate
427 428 429 |
# File 'lib/rex/socket/parameters.rb', line 427 def ssl_client_cert @ssl_client_cert end |
#ssl_client_key ⇒ Object
The client SSL key
432 433 434 |
# File 'lib/rex/socket/parameters.rb', line 432 def ssl_client_key @ssl_client_key end |
#ssl_cn ⇒ String
Which Common Name to use for certificate
413 414 415 |
# File 'lib/rex/socket/parameters.rb', line 413 def ssl_cn @ssl_cn end |
#ssl_compression ⇒ Bool
Enables SSL/TLS-level compression
422 423 424 |
# File 'lib/rex/socket/parameters.rb', line 422 def ssl_compression @ssl_compression end |
#ssl_verify_mode ⇒ Object
SSL certificate verification mode for SSL context
436 437 438 |
# File 'lib/rex/socket/parameters.rb', line 436 def ssl_verify_mode @ssl_verify_mode end |
#ssl_version ⇒ String, Symbol
What version of SSL to use (Auto, SSL2, SSL3, SSL23, TLS1)
383 384 385 |
# File 'lib/rex/socket/parameters.rb', line 383 def ssl_version @ssl_version end |
#sslctx ⇒ OpenSSL::SSL::SSLContext
Pre configured SSL Context to use
379 380 381 |
# File 'lib/rex/socket/parameters.rb', line 379 def sslctx @sslctx end |
#timeout ⇒ Object
358 359 360 |
# File 'lib/rex/socket/parameters.rb', line 358 def timeout @timeout || 5 end |
#v6 ⇒ Object
442 443 444 |
# File 'lib/rex/socket/parameters.rb', line 442 def v6 @v6 || false end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the Parameters class using the supplied hash.
37 38 39 |
# File 'lib/rex/socket/parameters.rb', line 37 def self.from_hash(hash) return self.new(hash) end |
Instance Method Details
#bare? ⇒ Boolean
Returns true if the socket is a bare socket that does not inherit from any extended Rex classes.
257 258 259 |
# File 'lib/rex/socket/parameters.rb', line 257 def return ( == true) end |
#client? ⇒ Boolean
Returns true if this represents parameters for a client.
228 229 230 |
# File 'lib/rex/socket/parameters.rb', line 228 def client? return (server == false) end |
#ip? ⇒ Boolean
Returns true if the protocol for the parameters is IP.
249 250 251 |
# File 'lib/rex/socket/parameters.rb', line 249 def ip? return (proto == 'ip') end |
#merge(other) ⇒ Object
198 199 200 |
# File 'lib/rex/socket/parameters.rb', line 198 def merge(other) self.dup.merge!(other) end |
#merge!(other) ⇒ Object
202 203 204 205 206 207 208 209 210 |
# File 'lib/rex/socket/parameters.rb', line 202 def merge!(other) other = self.class.new(other) if other.is_a? Hash other.instance_variables.each do |name| value = other.instance_variable_get(name) instance_variable_set(name, value) unless value.nil? end self end |
#server? ⇒ Boolean
Returns true if this represents parameters for a server.
221 222 223 |
# File 'lib/rex/socket/parameters.rb', line 221 def server? return (server == true) end |
#ssl? ⇒ Boolean
Returns true if SSL has been requested.
264 265 266 |
# File 'lib/rex/socket/parameters.rb', line 264 def ssl? return ssl end |
#tcp? ⇒ Boolean
Returns true if the protocol for the parameters is TCP.
235 236 237 |
# File 'lib/rex/socket/parameters.rb', line 235 def tcp? return (proto == 'tcp') end |
#udp? ⇒ Boolean
Returns true if the protocol for the parameters is UDP.
242 243 244 |
# File 'lib/rex/socket/parameters.rb', line 242 def udp? return (proto == 'udp') end |
#v6? ⇒ Boolean
Returns true if IPv6 has been enabled
271 272 273 |
# File 'lib/rex/socket/parameters.rb', line 271 def v6? return v6 end |