Class: SSLScan::Socket::Parameters
- Inherits:
-
Object
- Object
- SSLScan::Socket::Parameters
- Defined in:
- lib/ssl_scan/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 ⇒ Bool
Whether or not this is a bare (non-extended) socket instance that should be created.
-
#comm ⇒ Comm
The Comm instance that should be used to create the underlying socket.
-
#context ⇒ Hash
The context hash that was passed in to the structure.
-
#localhost ⇒ String
(also: #localaddr)
The local host.
-
#localport ⇒ Fixnum
The local port.
-
#peerhost ⇒ String
(also: #peeraddr)
The remote host information, equivalent to the PeerHost parameter hash key.
-
#peerport ⇒ Fixnum
The remote port.
-
#proto ⇒ String
The protocol to to use, such as TCP.
-
#proxies ⇒ String
List of proxies to use.
-
#retries ⇒ Fixnum
The number of attempts that should be made.
-
#server ⇒ Bool
Whether or not this is a server.
-
#ssl ⇒ Bool
Whether or not SSL should be used to wrap the connection.
-
#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_compression ⇒ Bool
Enables SSL/TLS-level compression.
-
#ssl_verify_mode ⇒ Object
The SSL context verification mechanism.
-
#ssl_version ⇒ String, Symbol
What version of SSL to use (SSL2, SSL3, SSL23, TLS1).
-
#timeout ⇒ Fixnum
The number of seconds before a connection attempt should time out.
-
#v6 ⇒ Bool
Whether we should use IPv6.
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.
-
#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.
78 79 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 197 198 199 200 201 202 |
# File 'lib/ssl_scan/socket/parameters.rb', line 78 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. = hash['Bare'] else self. = false end if (hash['SSL'] and hash['SSL'].to_s =~ /^(t|y|1)/i) self.ssl = true else self.ssl = false end supported_ssl_versions = ['SSL2', 'SSL23', 'TLS1', 'SSL3', :SSLv2, :SSLv3, :SSLv23, :TLSv1] if (hash['SSLVersion'] and supported_ssl_versions.include? hash['SSLVersion']) self.ssl_version = hash['SSLVersion'] end 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['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 = SSLScan::Socket::SwitchBoard.best_comm(self.localhost) end else if (self.comm == nil and self.peerhost) self.comm = SSLScan::Socket::SwitchBoard.best_comm(self.peerhost) end end # If we still haven't found a comm, we default to the local comm. self.comm = SSLScan::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 |
Instance Attribute Details
#bare ⇒ Bool
Whether or not this is a bare (non-extended) socket instance that should be created.
320 321 322 |
# File 'lib/ssl_scan/socket/parameters.rb', line 320 def @bare end |
#comm ⇒ Comm
The Comm instance that should be used to create the underlying socket.
303 304 305 |
# File 'lib/ssl_scan/socket/parameters.rb', line 303 def comm @comm end |
#context ⇒ Hash
The context hash that was passed in to the structure. (default: {})
307 308 309 |
# File 'lib/ssl_scan/socket/parameters.rb', line 307 def context @context end |
#localhost ⇒ String Also known as: localaddr
The local host. Equivalent to the LocalHost parameter hash key.
285 286 287 |
# File 'lib/ssl_scan/socket/parameters.rb', line 285 def localhost @localhost end |
#localport ⇒ Fixnum
The local port. Equivalent to the LocalPort parameter hash key.
289 290 291 |
# File 'lib/ssl_scan/socket/parameters.rb', line 289 def localport @localport end |
#peerhost ⇒ String Also known as: peeraddr
The remote host information, equivalent to the PeerHost parameter hash key.
277 278 279 |
# File 'lib/ssl_scan/socket/parameters.rb', line 277 def peerhost @peerhost end |
#peerport ⇒ Fixnum
The remote port. Equivalent to the PeerPort parameter hash key.
281 282 283 |
# File 'lib/ssl_scan/socket/parameters.rb', line 281 def peerport @peerport end |
#proto ⇒ String
The protocol to to use, such as TCP. Equivalent to the Proto parameter hash key.
294 295 296 |
# File 'lib/ssl_scan/socket/parameters.rb', line 294 def proto @proto end |
#proxies ⇒ String
List of proxies to use
358 359 360 |
# File 'lib/ssl_scan/socket/parameters.rb', line 358 def proxies @proxies end |
#retries ⇒ Fixnum
The number of attempts that should be made.
311 312 313 |
# File 'lib/ssl_scan/socket/parameters.rb', line 311 def retries @retries end |
#server ⇒ Bool
Whether or not this is a server. Equivalent to the Server parameter hash key.
299 300 301 |
# File 'lib/ssl_scan/socket/parameters.rb', line 299 def server @server end |
#ssl ⇒ Bool
Whether or not SSL should be used to wrap the connection.
324 325 326 |
# File 'lib/ssl_scan/socket/parameters.rb', line 324 def ssl @ssl end |
#ssl_cert ⇒ String
The SSL certificate, in pem format, stored as a string. See SslTcpServer#makessl
339 340 341 |
# File 'lib/ssl_scan/socket/parameters.rb', line 339 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”
334 335 336 |
# File 'lib/ssl_scan/socket/parameters.rb', line 334 def ssl_cipher @ssl_cipher end |
#ssl_compression ⇒ Bool
Enables SSL/TLS-level compression
343 344 345 |
# File 'lib/ssl_scan/socket/parameters.rb', line 343 def ssl_compression @ssl_compression end |
#ssl_verify_mode ⇒ Object
The SSL context verification mechanism
348 349 350 |
# File 'lib/ssl_scan/socket/parameters.rb', line 348 def ssl_verify_mode @ssl_verify_mode end |
#ssl_version ⇒ String, Symbol
What version of SSL to use (SSL2, SSL3, SSL23, TLS1)
328 329 330 |
# File 'lib/ssl_scan/socket/parameters.rb', line 328 def ssl_version @ssl_version end |
#timeout ⇒ Fixnum
The number of seconds before a connection attempt should time out.
315 316 317 |
# File 'lib/ssl_scan/socket/parameters.rb', line 315 def timeout @timeout end |
#v6 ⇒ Bool
Whether we should use IPv6
353 354 355 |
# File 'lib/ssl_scan/socket/parameters.rb', line 353 def v6 @v6 end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the Parameters class using the supplied hash.
36 37 38 |
# File 'lib/ssl_scan/socket/parameters.rb', line 36 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.
249 250 251 |
# File 'lib/ssl_scan/socket/parameters.rb', line 249 def return ( == true) end |
#client? ⇒ Boolean
Returns true if this represents parameters for a client.
220 221 222 |
# File 'lib/ssl_scan/socket/parameters.rb', line 220 def client? return (server == false) end |
#ip? ⇒ Boolean
Returns true if the protocol for the parameters is IP.
241 242 243 |
# File 'lib/ssl_scan/socket/parameters.rb', line 241 def ip? return (proto == 'ip') end |
#server? ⇒ Boolean
Returns true if this represents parameters for a server.
213 214 215 |
# File 'lib/ssl_scan/socket/parameters.rb', line 213 def server? return (server == true) end |
#ssl? ⇒ Boolean
Returns true if SSL has been requested.
256 257 258 |
# File 'lib/ssl_scan/socket/parameters.rb', line 256 def ssl? return ssl end |
#tcp? ⇒ Boolean
Returns true if the protocol for the parameters is TCP.
227 228 229 |
# File 'lib/ssl_scan/socket/parameters.rb', line 227 def tcp? return (proto == 'tcp') end |
#udp? ⇒ Boolean
Returns true if the protocol for the parameters is UDP.
234 235 236 |
# File 'lib/ssl_scan/socket/parameters.rb', line 234 def udp? return (proto == 'udp') end |
#v6? ⇒ Boolean
Returns true if IPv6 has been enabled
263 264 265 |
# File 'lib/ssl_scan/socket/parameters.rb', line 263 def v6? return v6 end |