Module: Ronin::Support::Network::SSL::Mixin
- Includes:
- TCP::Mixin
- Included in:
- Mixin, Ronin::Support::Network::SMTP::Mixin, TLS::Mixin
- Defined in:
- lib/ronin/support/network/ssl/mixin.rb
Overview
Provides helper methods for communicating with SSL-enabled services.
Instance Method Summary collapse
-
#ssl_accept(port: nil, host: nil, **kwargs) {|client| ... } ⇒ nil
Creates a new SSL socket listening on a given host and port, accepts only one client and then stops listening.
-
#ssl_banner(host, port, bind_host: nil, bind_port: nil, **kwargs) {|banner| ... } ⇒ String
Reads the banner from the service running on the given host and port.
-
#ssl_cert(host, port, **kwargs) ⇒ Crypto::Cert
Connects to the host and port and returns the server's certificate.
-
#ssl_connect(host, port, bind_host: nil, bind_port: nil, **kwargs) {|ssl_socket| ... } ⇒ OpenSSL::SSL::SSLSocket?
Establishes a SSL connection.
-
#ssl_connect_and_send(data, host, port, bind_host: nil, bind_port: nil, **kwargs) {|ssl_socket| ... } ⇒ Object
Creates a new SSL connection and sends the given data.
-
#ssl_context(**kwargs) ⇒ OpenSSL::SSL::SSLContext
Creates a new SSL Context.
-
#ssl_open?(host, port, bind_host: nil, bind_port: nil, timeout: 5, **kwargs) ⇒ Boolean?
Tests whether a remote SSLed TCP port is open.
-
#ssl_send(data, host, port, bind_host: nil, bind_port: nil, **kwargs) ⇒ true
Connects to a specified host and port, sends the given data and then closes the connection.
-
#ssl_server_loop(port: nil, host: nil, backlog: 5, **kwargs) {|client| ... } ⇒ nil
Creates a new SSL socket listening on a given host and port, accepting clients in a loop.
-
#ssl_server_socket(socket, key: Network::SSL.key, cert: Network::SSL.cert, **kwargs) ⇒ OpenSSL::SSL::SSLSocket
Accepts an SSL session from an existing TCP socket.
-
#ssl_socket(socket, **kwargs) ⇒ OpenSSL::SSL::SSLSocket
Initiates an SSL session with an existing TCP socket.
Methods included from TCP::Mixin
#tcp_accept, #tcp_banner, #tcp_connect, #tcp_connect_and_send, #tcp_open?, #tcp_send, #tcp_server, #tcp_server_loop, #tcp_server_session
Instance Method Details
#ssl_accept(port: nil, host: nil, **kwargs) {|client| ... } ⇒ nil
Creates a new SSL socket listening on a given host and port, accepts only one client and then stops listening.
728 729 730 731 732 733 734 735 736 737 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 728 def ssl_accept(port: nil, host: nil,**kwargs) tcp_server_session(port: port, host: host, backlog: 1) do |server| client = server.accept ssl_client = ssl_server_socket(client,) ssl_client.accept yield ssl_client if block_given? ssl_client.close end end |
#ssl_banner(host, port, bind_host: nil, bind_port: nil, **kwargs) {|banner| ... } ⇒ String
Reads the banner from the service running on the given host and port.
462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 462 def (host,port, bind_host: nil, bind_port: nil, **kwargs) = nil ssl_connect(host,port, bind_host: bind_host, bind_port: bind_port, **kwargs) do |ssl_socket| = ssl_socket.readline.strip end yield if block_given? return end |
#ssl_cert(host, port, **kwargs) ⇒ Crypto::Cert
Connects to the host and port and returns the server's certificate.
394 395 396 397 398 399 400 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 394 def ssl_cert(host,port,**kwargs) socket = ssl_connect(host,port,**kwargs) cert = Crypto::Cert(socket.peer_cert) socket.close return cert end |
#ssl_connect(host, port, bind_host: nil, bind_port: nil, **kwargs) {|ssl_socket| ... } ⇒ OpenSSL::SSL::SSLSocket?
Establishes a SSL connection.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 266 def ssl_connect(host,port, bind_host: nil, bind_port: nil, **kwargs) socket = tcp_connect(host,port,bind_host: bind_host, bind_port: bind_port) ssl_socket = ssl_socket(socket,**kwargs) ssl_socket.hostname = host ssl_socket.connect if block_given? yield ssl_socket ssl_socket.close else return ssl_socket end end |
#ssl_connect_and_send(data, host, port, bind_host: nil, bind_port: nil, **kwargs) {|ssl_socket| ... } ⇒ Object
Creates a new SSL connection and sends the given data.
337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 337 def ssl_connect_and_send(data,host,port, bind_host: nil, bind_port: nil, **kwargs) socket = ssl_connect(host,port, bind_host: bind_host, bind_port: bind_port, **kwargs) socket.write(data) yield socket if block_given? return socket end |
#ssl_context(**kwargs) ⇒ OpenSSL::SSL::SSLContext
Creates a new SSL Context.
73 74 75 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 73 def ssl_context(**kwargs) Network::SSL.context(**kwargs) end |
#ssl_open?(host, port, bind_host: nil, bind_port: nil, timeout: 5, **kwargs) ⇒ Boolean?
Tests whether a remote SSLed TCP port is open.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 184 def ssl_open?(host,port, bind_host: nil, bind_port: nil, timeout: 5, **kwargs) Timeout.timeout(timeout) do ssl_connect(host,port, bind_host: bind_host, bind_port: bind_port, **kwargs) end return true rescue Timeout::Error return nil rescue SocketError, SystemCallError return false end |
#ssl_send(data, host, port, bind_host: nil, bind_port: nil, **kwargs) ⇒ true
Connects to a specified host and port, sends the given data and then closes the connection.
533 534 535 536 537 538 539 540 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 533 def ssl_send(data,host,port, bind_host: nil, bind_port: nil,**kwargs) ssl_connect(host,port, bind_host: bind_host, bind_port: bind_port,**kwargs) do |socket| socket.write(data) end return true end |
#ssl_server_loop(port: nil, host: nil, backlog: 5, **kwargs) {|client| ... } ⇒ nil
Creates a new SSL socket listening on a given host and port, accepting clients in a loop.
650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 650 def ssl_server_loop(port: nil, host: nil, backlog: 5, **kwargs) return tcp_server_session(port: port, host: host, backlog: backlog) do |server| loop do client = server.accept ssl_client = ssl_server_socket(client,**kwargs) ssl_client.accept yield ssl_client if block_given? ssl_client.close end end end |
#ssl_server_socket(socket, key: Network::SSL.key, cert: Network::SSL.cert, **kwargs) ⇒ OpenSSL::SSL::SSLSocket
Accepts an SSL session from an existing TCP socket.
582 583 584 585 586 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 582 def ssl_server_socket(socket, key: Network::SSL.key, cert: Network::SSL.cert, **kwargs) return ssl_socket(socket, cert: cert, key: key, **kwargs) end |
#ssl_socket(socket, **kwargs) ⇒ OpenSSL::SSL::SSLSocket
Initiates an SSL session with an existing TCP socket.
117 118 119 120 121 122 |
# File 'lib/ronin/support/network/ssl/mixin.rb', line 117 def ssl_socket(socket,**kwargs) ssl_socket = OpenSSL::SSL::SSLSocket.new(socket,ssl_context(**kwargs)) ssl_socket.sync_close = true return ssl_socket end |