Class: Ronin::Support::Network::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/support/network/http.rb,
lib/ronin/support/network/http/mixin.rb,
lib/ronin/support/network/http/cookie.rb,
lib/ronin/support/network/http/request.rb,
lib/ronin/support/network/http/set_cookie.rb,
lib/ronin/support/network/http/user_agents.rb

Overview

Provides helper methods for communicating with HTTP Servers.

Core-Ext Methods

Defined Under Namespace

Modules: Mixin, Request, UserAgents Classes: Cookie, SetCookie

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, proxy: nil, ssl: port == 443, headers: {}, user_agent: self.class.user_agent, cookie: nil, user: nil, password: nil) {|_self| ... } ⇒ HTTP

Initializes an HTTP connection.

Parameters:

  • host (String)

    The host to connect to.

  • port (Integer)

    The port to connect tto.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: nil)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: self.class.user_agent)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: port == 443)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Yields:

  • (_self)

Yield Parameters:

Since:

  • 1.0.0



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/ronin/support/network/http.rb', line 249

def initialize(host,port, proxy:      nil,
                          ssl:        port == 443,
                          # header options
                          headers:    {},
                          user_agent: self.class.user_agent,
                          cookie:     nil,
                          # Basic-Auth options
                          user:       nil,
                          password:   nil)
  @host  = DNS::IDN.to_ascii(host)
  @port  = port.to_i

  @headers        = headers
  self.user_agent = user_agent if user_agent
  self.cookie     = cookie     if cookie

  @user     = user
  @password = password

  if proxy
    @proxy = URI(proxy)
    @http  = Net::HTTP.new(
      @host, @port,
      @proxy.host, @proxy.port, @proxy.user, @proxy.password
    )
  else
    @http = Net::HTTP.new(@host,@port)
  end

  case ssl
  when true then initialize_ssl
  when Hash then initialize_ssl(**ssl)
  end

  yield self if block_given?
end

Instance Attribute Details

The default cookie params to add to every request.

Returns:



167
168
169
# File 'lib/ronin/support/network/http.rb', line 167

def cookie
  @cookie
end

#headersHash{String => String,Array} (readonly)

Additional headers to add to every request.

Returns:



152
153
154
# File 'lib/ronin/support/network/http.rb', line 152

def headers
  @headers
end

#hostString (readonly)

The host to connect to.

Returns:



142
143
144
# File 'lib/ronin/support/network/http.rb', line 142

def host
  @host
end

#passwordString? (readonly)

The HTTP Baic-Auth password to add to every request.

Returns:



162
163
164
# File 'lib/ronin/support/network/http.rb', line 162

def password
  @password
end

#portInteger (readonly)

The port to connect to.

Returns:



147
148
149
# File 'lib/ronin/support/network/http.rb', line 147

def port
  @port
end

#proxyURI::HTTP, ... (readonly)

The proxy to send requests through.

Returns:



137
138
139
# File 'lib/ronin/support/network/http.rb', line 137

def proxy
  @proxy
end

#userString? (readonly)

The HTTP Baic-Auth user to add to every request.

Returns:



157
158
159
# File 'lib/ronin/support/network/http.rb', line 157

def user
  @user
end

#user_agentString?

The User-Agent header value.

Returns:

Since:

  • 1.0.0



564
565
566
# File 'lib/ronin/support/network/http.rb', line 564

def user_agent
  @user_agent
end

Class Method Details

.allowed_methods(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Array<Symbol>

Performs a OPTIONS HTTP request for the given URI and parses the Allow response header.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (Array<Symbol>)

    The allowed HTTP request methods for the given URL.

See Also:

Since:

  • 1.0.0



2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
# File 'lib/ronin/support/network/http.rb', line 2331

def self.allowed_methods(url, proxy:      self.proxy,
                              ssl:        nil,
                              headers:    {},
                              user_agent: nil,
                              cookie:     nil,
                              user:       nil,
                              password:   nil,
                              **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.allowed_methods(path,**kwargs)
end

.connect(host, port, ssl: port == 443, **kwargs) {|http| ... } ⇒ HTTP?

Creates a HTTP connection to the host nad port.

Parameters:

  • host (String)

    The host to connect to.

  • port (Integer)

    The port to connect to.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: port == 443)

    Specifies whether to enable SSL and/or the SSL context configuration.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for #initialize.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :proxy (String, URI::HTTP, Addressable::URI, nil)

    The optional proxy to send requests through.

  • :headers (Hash{Symbol,String => String,Array}, nil)

    Additional headers to add to each request.

  • :user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) — default: HTTP.user_agent

    The default User-Agent string to add to each request.

  • :user (String, nil)

    The HTTP Basic-Auth user to add to each request.

  • :password (String, nil)

    The HTTP Basic-Auth password to add to each request.

Yields:

  • (http)

    If a block is given, it will be passed the newly created HTTP session object. Once the block returns, the HTTP session will be closed.

Yield Parameters:

  • http (HTTP)

    The HTTP session object.

Returns:

  • (HTTP, nil)

    The HTTP session object. If a block is given, then nil will be returned.

Since:

  • 1.0.0



472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/ronin/support/network/http.rb', line 472

def self.connect(host,port, ssl: port == 443, **kwargs)
  http = new(host,port, ssl: ssl, **kwargs)

  if block_given?
    begin
      yield http
    ensure
      http.close
    end
  else
    return http
  end
end

.connect_uri(url, ssl: nil, user: nil, password: nil, **kwargs) {|http| ... } ⇒ HTTP?

Creates a HTTP connection using the URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    The URI to connect to.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for #initialize.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :proxy (String, URI::HTTP, Addressable::URI, nil)

    The optional proxy to send requests through.

  • :headers (Hash{Symbol,String => String,Array}, nil)

    Additional headers to add to each request.

  • :user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) — default: HTTP.user_agent

    The default User-Agent string to add to each request.

  • :user (String, nil)

    The HTTP Basic-Auth user to add to each request.

  • :password (String, nil)

    The HTTP Basic-Auth password to add to each request.

Yields:

  • (http)

    If a block is given, it will be passed the newly created HTTP session object. Once the block returns, the HTTP session will be closed.

Yield Parameters:

  • http (HTTP)

    The HTTP session object.

Returns:

  • (HTTP, nil)

    The HTTP session object. If a block is given, then nil will be returned.

Raises:

  • (ArgumentError)

    The URL was not a URI::HTTP, Addressable::URI, or a String object.

Since:

  • 1.0.0



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/ronin/support/network/http.rb', line 511

def self.connect_uri(url, ssl:      nil,
                          user:     nil,
                          password: nil,
                          **kwargs, &block)
  case url
  when URI::HTTP
    host       = url.host
    port       = url.port
    user     ||= url.user
    password ||= url.password
    ssl      ||= (url.scheme == 'https')
  when String
    uri = Addressable::URI.parse(url)

    host       = uri.host
    port       = uri.inferred_port
    user     ||= uri.user
    password ||= uri.password
    ssl      ||= (uri.scheme == 'https')
  when Addressable::URI
    host       = url.host
    port       = url.inferred_port
    user     ||= url.user
    password ||= url.password
    ssl      ||= (url.scheme == 'https')
  else
    raise(ArgumentError,"url must be a URI::HTTP, Addressable::URI, or a String: #{url.inspect}")
  end

  return connect(host,port, ssl:      ssl,
                            user:     user,
                            password: password,
                            **kwargs, &block)
end

.copy(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a COPY request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
# File 'lib/ronin/support/network/http.rb', line 1772

def self.copy(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.copy(path,**kwargs,&block)
end

.delete(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a DELETE request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
# File 'lib/ronin/support/network/http.rb', line 1825

def self.delete(url, proxy:      self.proxy,
                     ssl:        nil,
                     headers:    {},
                     user_agent: nil,
                     cookie:     nil,
                     user:       nil,
                     password:   nil,
                     **kwargs,
                     &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.delete(path,**kwargs,&block)
end

.get(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a GET request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
# File 'lib/ronin/support/network/http.rb', line 1878

def self.get(url, proxy:      self.proxy,
                  ssl:        nil,
                  headers:    {},
                  user_agent: nil,
                  cookie:     nil,
                  user:       nil,
                  password:   nil,
                  **kwargs,
                  &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.get(path,**kwargs,&block)
end

.get_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String

Performs a GET request for the given URI and returns the response body.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String)

    The response body.

See Also:

Since:

  • 1.0.0



2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
# File 'lib/ronin/support/network/http.rb', line 2019

def self.get_body(url, proxy:      self.proxy,
                       ssl:        nil,
                       headers:    {},
                       user_agent: nil,
                       cookie:     nil,
                       user:       nil,
                       password:   nil,
                       **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.get_body(path,**kwargs)
end

.get_cookies(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Array<SetCookie>?

Sends an HTTP request and returns the parsed Set-Cookie header(s).

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

See Also:

Since:

  • 1.0.0



1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
# File 'lib/ronin/support/network/http.rb', line 1972

def self.get_cookies(url, proxy:      self.proxy,
                          ssl:        nil,
                          headers:    {},
                          user_agent: nil,
                          cookie:     nil,
                          user:       nil,
                          password:   nil,
                          **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.get_cookies(path, **kwargs)
end

.get_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}

Performs a GET request for the given URI and returns the response headers.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

See Also:

Since:

  • 1.0.0



1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
# File 'lib/ronin/support/network/http.rb', line 1926

def self.get_headers(url, proxy:      self.proxy,
                          ssl:        nil,
                          headers:    {},
                          user_agent: nil,
                          cookie:     nil,
                          user:       nil,
                          password:   nil,
                          **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.get_headers(path,**kwargs)
end

.head(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a HEAD request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
# File 'lib/ronin/support/network/http.rb', line 2071

def self.head(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.head(path,**kwargs,&block)
end

.lock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a LOCK request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
# File 'lib/ronin/support/network/http.rb', line 2124

def self.lock(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.lock(path,**kwargs,&block)
end

.mkcol(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a MKCOL request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
# File 'lib/ronin/support/network/http.rb', line 2177

def self.mkcol(url, proxy:      self.proxy,
                    ssl:        nil,
                    headers:    {},
                    user_agent: nil,
                    cookie:     nil,
                    user:       nil,
                    password:   nil,
                    **kwargs,
                    &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.mkcol(path,**kwargs,&block)
end

.move(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a MOVE request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
# File 'lib/ronin/support/network/http.rb', line 2230

def self.move(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.move(path,**kwargs,&block)
end

.ok?(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Boolean

Sends a HTTP request and determines if the response status was 200.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (Boolean)

    Indicates that the response status was 200.

See Also:

Since:

  • 1.0.0



1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
# File 'lib/ronin/support/network/http.rb', line 1526

def self.ok?(method=:head,url, proxy:      self.proxy,
                               ssl:        nil,
                               headers:    {},
                               user_agent: nil,
                               cookie:     nil,
                               user:       nil,
                               password:   nil,
                               **kwargs)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.ok?(method,path,**kwargs)
end

.options(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a OPTIONS request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
# File 'lib/ronin/support/network/http.rb', line 2283

def self.options(url, proxy:      self.proxy,
                      ssl:        nil,
                      headers:    {},
                      user_agent: nil,
                      cookie:     nil,
                      user:       nil,
                      password:   nil,
                      **kwargs,
                      &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.options(path,**kwargs,&block)
end

.patch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PATCH request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
# File 'lib/ronin/support/network/http.rb', line 2383

def self.patch(url, proxy:      self.proxy,
                    ssl:        nil,
                    headers:    {},
                    user_agent: nil,
                    cookie:     nil,
                    user:       nil,
                    password:   nil,
                    **kwargs,
                    &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.patch(path,**kwargs,&block)
end

.post(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a POST request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
# File 'lib/ronin/support/network/http.rb', line 2436

def self.post(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.post(path,**kwargs,&block)
end

.post_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String

Performs a POST request for the given URI and returns the response body.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String)

    The response body.

See Also:

Since:

  • 1.0.0



2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
# File 'lib/ronin/support/network/http.rb', line 2531

def self.post_body(url, proxy:      self.proxy,
                        ssl:        nil,
                        headers:    {},
                        user_agent: nil,
                        cookie:     nil,
                        user:       nil,
                        password:   nil,
                        **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.post_body(path,**kwargs)
end

.post_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}

Performs a POST request on the given URI and returns the response headers.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

See Also:

Since:

  • 1.0.0



2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
# File 'lib/ronin/support/network/http.rb', line 2484

def self.post_headers(url, proxy:      self.proxy,
                           ssl:        nil,
                           headers:    {},
                           user_agent: nil,
                           cookie:     nil,
                           user:       nil,
                           password:   nil,
                           **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.post_headers(path,**kwargs)
end

.powered_by_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String?

Sends an HTTP request and returns the X-Powered-By header.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String, nil)

    The X-Powered-By header.

See Also:

Since:

  • 1.0.0



1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
# File 'lib/ronin/support/network/http.rb', line 1669

def self.powered_by_header(url, proxy:      self.proxy,
                                ssl:        nil,
                                headers:    {},
                                user_agent: nil,
                                cookie:     nil,
                                user:       nil,
                                password:   nil,
                                **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.powered_by_header(path: path, **kwargs)
end

.propfind(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PROPFIND request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
# File 'lib/ronin/support/network/http.rb', line 2583

def self.propfind(url, proxy:      self.proxy,
                       ssl:        nil,
                       headers:    {},
                       user_agent: nil,
                       cookie:     nil,
                       user:       nil,
                       password:   nil,
                       **kwargs,
                       &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.propfind(path,**kwargs,&block)
end

.proppatch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PROPPATCH request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
# File 'lib/ronin/support/network/http.rb', line 2636

def self.proppatch(url, proxy:      self.proxy,
                        ssl:        nil,
                        headers:    {},
                        user_agent: nil,
                        cookie:     nil,
                        user:       nil,
                        password:   nil,
                        **kwargs,
                        &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.proppatch(path,**kwargs,&block)
end

.proxyURI::HTTP, ...

Note:

If the RONIN_HTTP_PROXY environment variable is specified, it will be used as the default value. If the HTTP_PROXY environment variable is specified, it will be used as the default value.

The Ronin HTTP proxy to use.

Returns:

  • (URI::HTTP, Addressable::URI, nil)

    The Ronin HTTP proxy.



59
60
61
62
63
64
65
# File 'lib/ronin/support/network/http.rb', line 59

def self.proxy
  @proxy ||= if ENV['RONIN_HTTP_PROXY']
               Addressable::URI.parse(ENV['RONIN_HTTP_PROXY'])
             elsif ENV['HTTP_PROXY']
               Addressable::URI.parse(ENV['HTTP_PROXY'])
             end
end

.proxy=(new_proxy) ⇒ URI::HTTP, ...

Sets the Ronin HTTP proxy to use.

Parameters:

  • new_proxy (URI::HTTP, Addressable::URI, String, nil)

    The new proxy information to use.

Returns:

  • (URI::HTTP, Addressable::URI, nil)

    The new proxy.

Raises:

  • (ArgumentError)

    The given proxy information was not a URI::HTTP, Addressable::URI, String, or nil.



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ronin/support/network/http.rb', line 82

def self.proxy=(new_proxy)
  @proxy = case new_proxy
           when URI::HTTP, Addressable::URI
             new_proxy
           when String
             Addressable::URI.parse(new_proxy)
           when nil
             nil
           else
             raise(ArgumentError,"invalid proxy value (#{new_proxy.inspect}), must be either a URI::HTTP, Addressable::URI, String, or nil")
           end
end

.put(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PUT request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
# File 'lib/ronin/support/network/http.rb', line 2689

def self.put(url, proxy:      self.proxy,
                  ssl:        nil,
                  headers:    {},
                  user_agent: nil,
                  cookie:     nil,
                  user:       nil,
                  password:   nil,
                  **kwargs,
                  &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.put(path,**kwargs,&block)
end

.request(method, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs and arbitrary HTTP request.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Raises:

  • (ArgumentError)

    The :method option did not match a known Net::HTTP request class.

See Also:



1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
# File 'lib/ronin/support/network/http.rb', line 1423

def self.request(method,url, proxy:      self.proxy,
                             ssl:        nil,
                             headers:    {},
                             user_agent: nil,
                             cookie:     nil,
                             user:       nil,
                             password:   nil,
                             **kwargs,
                             &block)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(uri, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.request(method,path,**kwargs,&block)
end

.response_body(method = :get, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String

Sends an arbitrary HTTP request and returns the response body.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :get)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String)

    The response body.

See Also:

Since:

  • 1.0.0



1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
# File 'lib/ronin/support/network/http.rb', line 1720

def self.response_body(method=:get,url, proxy:      self.proxy,
                                        ssl:        nil,
                                        headers:    {},
                                        user_agent: nil,
                                        cookie:     nil,
                                        user:       nil,
                                        password:   nil,
                                        **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.response_body(method,path,**kwargs)
end

.response_headers(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}

Sends an arbitrary HTTP request and returns the response headers.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

See Also:

Since:

  • 1.0.0



1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
# File 'lib/ronin/support/network/http.rb', line 1577

def self.response_headers(method=:head,url, proxy:      self.proxy,
                                            ssl:        nil,
                                            headers:    {},
                                            user_agent: nil,
                                            cookie:     nil,
                                            user:       nil,
                                            password:   nil,
                                            **kwargs)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.response_headers(method,path,**kwargs)
end

.response_status(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Integer

Sends an arbitrary HTTP request and returns the response status.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (Integer)

    The status code of the response.

See Also:

Since:

  • 1.0.0



1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
# File 'lib/ronin/support/network/http.rb', line 1475

def self.response_status(method=:head,url, proxy:      self.proxy,
                                           ssl:        nil,
                                           headers:    {},
                                           user_agent: nil,
                                           cookie:     nil,
                                           user:       nil,
                                           password:   nil,
                                           **kwargs)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.response_status(method,path,**kwargs)
end

.server_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String?

Sends an HTTP request and returns the Server header.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String, nil)

    The Server header.

See Also:

Since:

  • 1.0.0



1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
# File 'lib/ronin/support/network/http.rb', line 1623

def self.server_header(url, proxy:      self.proxy,
                            ssl:        nil,
                            headers:    {},
                            user_agent: nil,
                            cookie:     nil,
                            user:       nil,
                            password:   nil,
                            **kwargs)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.server_header(path: path, **kwargs)
end

.trace(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a TRACE request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
# File 'lib/ronin/support/network/http.rb', line 2742

def self.trace(url, proxy:      self.proxy,
                    ssl:        nil,
                    headers:    {},
                    user_agent: nil,
                    cookie:     nil,
                    user:       nil,
                    password:   nil,
                    **kwargs,
                    &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.trace(path,**kwargs,&block)
end

.unlock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a UNLOCK request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
# File 'lib/ronin/support/network/http.rb', line 2795

def self.unlock(url, proxy:      self.proxy,
                     ssl:        nil,
                     headers:    {},
                     user_agent: nil,
                     cookie:     nil,
                     user:       nil,
                     password:   nil,
                     **kwargs,
                     &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.unlock(path,**kwargs,&block)
end

.user_agentString?

The default Ronin HTTP User-Agent string.

Returns:

  • (String, nil)

    The default Ronin HTTP User-Agent.



103
104
105
# File 'lib/ronin/support/network/http.rb', line 103

def self.user_agent
  @user_agent
end

.user_agent=(new_user_agent) ⇒ String?

Sets the default Ronin HTTP User-Agent string.

The new User-Agent default value.

  • If a Symbol or a String is given, then the user_agent value will be set.
  • If nil is given, then the user_agent value will be cleared.

Parameters:

  • new_user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil)

Returns:

  • (String, nil)

    The new User-Agent string.



127
128
129
130
131
132
# File 'lib/ronin/support/network/http.rb', line 127

def self.user_agent=(new_user_agent)
  @user_agent = case new_user_agent
                when Symbol then UserAgents[new_user_agent]
                else             new_user_agent
                end
end

Instance Method Details

#allowed_methods(path = '*', **kwargs) ⇒ Array<Symbol>

Sends a OPTIONS HTTP request and parses the Allow response header.

Parameters:

  • path (String) (defaults to: '*')

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (Array<Symbol>)

    The allowed HTTP request methods for the given path.

Since:

  • 1.0.0



1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
# File 'lib/ronin/support/network/http.rb', line 1172

def allowed_methods(path='*',**kwargs)
  response = options(path,**kwargs)
  allow    = response['Allow']
  methods  = allow.split(', ')

  methods.map! do |method|
    method.downcase!
    method.to_sym
  end

  return methods
end

#closeObject

Closes the HTTP connection.

Since:

  • 1.0.0



1389
1390
1391
# File 'lib/ronin/support/network/http.rb', line 1389

def close
  @http.finish if @http.started?
end

#copy(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a COPY HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



934
935
936
# File 'lib/ronin/support/network/http.rb', line 934

def copy(path,**kwargs,&block)
  request(:copy,path,**kwargs,&block)
end

#delete(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a DELETE HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



957
958
959
# File 'lib/ronin/support/network/http.rb', line 957

def delete(path,**kwargs,&block)
  request(:delete,path,**kwargs,&block)
end

#get(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a GET HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



980
981
982
# File 'lib/ronin/support/network/http.rb', line 980

def get(path,**kwargs,&block)
  request(:get,path,**kwargs,&block)
end

#get_body(path, **kwargs) ⇒ String

Sends a GET HTTP request and returns the response body.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String)

    The response body.

Since:

  • 1.0.0



1039
1040
1041
# File 'lib/ronin/support/network/http.rb', line 1039

def get_body(path,**kwargs)
  response_body(:get,path,**kwargs)
end

#get_cookies(path, **kwargs) ⇒ Array<SetCookie>

Sends an HTTP request and returns the parsed Set-Cookie header(s).

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

Since:

  • 1.0.0



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
# File 'lib/ronin/support/network/http.rb', line 1014

def get_cookies(path, **kwargs)
  response = request(:get,path,**kwargs)

  if (set_cookies = response.get_fields('Set-Cookie'))
    set_cookies.map do |cookie|
      SetCookie.parse(cookie)
    end
  else
    []
  end
end

#get_headers(path, **kwargs) ⇒ Hash{String => String}

Sends a GET HTTP request and returns the response headers.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

Since:

  • 1.0.0



997
998
999
# File 'lib/ronin/support/network/http.rb', line 997

def get_headers(path,**kwargs)
  response_headers(:get,path,**kwargs)
end

#head(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a HEAD HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1062
1063
1064
# File 'lib/ronin/support/network/http.rb', line 1062

def head(path,**kwargs,&block)
  request(:head,path,**kwargs,&block)
end

#lock(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a LOCK HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1085
1086
1087
# File 'lib/ronin/support/network/http.rb', line 1085

def lock(path,**kwargs,&block)
  request(:lock,path,**kwargs,&block)
end

#mkcol(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a MKCOL HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1108
1109
1110
# File 'lib/ronin/support/network/http.rb', line 1108

def mkcol(path,**kwargs,&block)
  request(:mkcol,path,**kwargs,&block)
end

#move(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a MOVE HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1131
1132
1133
# File 'lib/ronin/support/network/http.rb', line 1131

def move(path,**kwargs,&block)
  request(:move,path,**kwargs,&block)
end

#ok?(method = :head, path, **kwargs) ⇒ Boolean

Sends a HTTP request and determines if the response status was 200.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (Boolean)

    Indicates that the response status was 200.

Since:

  • 1.0.0



815
816
817
# File 'lib/ronin/support/network/http.rb', line 815

def ok?(method=:head,path,**kwargs)
  response_status(method,path,**kwargs) == 200
end

#options(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a OPTIONS HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1154
1155
1156
# File 'lib/ronin/support/network/http.rb', line 1154

def options(path,**kwargs,&block)
  request(:options,path,**kwargs,&block)
end

#patch(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a PATCH HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1204
1205
1206
# File 'lib/ronin/support/network/http.rb', line 1204

def patch(path,**kwargs,&block)
  request(:patch,path,**kwargs,&block)
end

#post(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a POST HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1227
1228
1229
# File 'lib/ronin/support/network/http.rb', line 1227

def post(path,**kwargs,&block)
  request(:post,path,**kwargs,&block)
end

#post_body(path, **kwargs) ⇒ String

Sends a POST HTTP request and returns the response body.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String)

    The response body.

Since:

  • 1.0.0



1261
1262
1263
# File 'lib/ronin/support/network/http.rb', line 1261

def post_body(path,**kwargs)
  response_body(:post,path,**kwargs)
end

#post_headers(path, **kwargs) ⇒ Hash{String => String}

Sends a POST HTTP request and returns the response headers.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

Since:

  • 1.0.0



1244
1245
1246
# File 'lib/ronin/support/network/http.rb', line 1244

def post_headers(path,**kwargs)
  response_headers(:post,path,**kwargs)
end

#powered_by_header(method: :head, path: '/', **kwargs) ⇒ String?

Sends an HTTP request and returns the X-Powered-By header.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String) (defaults to: '/')

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String, nil)

    The X-Powered-By header.

Since:

  • 1.0.0



888
889
890
891
# File 'lib/ronin/support/network/http.rb', line 888

def powered_by_header(method: :head, path: '/',**kwargs)
  response = request(method,path,**kwargs)
  response['X-Powered-By']
end

#prop_find {|response| ... } ⇒ Net::HTTPResponse

Sends a PROPFIND HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1288
1289
1290
# File 'lib/ronin/support/network/http.rb', line 1288

def propfind(path,**kwargs,&block)
  request(:propfind,path,**kwargs,&block)
end

#prop_patch {|response| ... } ⇒ Net::HTTPResponse

Sends a PROPPATCH HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1313
1314
1315
# File 'lib/ronin/support/network/http.rb', line 1313

def proppatch(path,**kwargs,&block)
  request(:proppatch,path,**kwargs,&block)
end

#propfind(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a PROPFIND HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1284
1285
1286
# File 'lib/ronin/support/network/http.rb', line 1284

def propfind(path,**kwargs,&block)
  request(:propfind,path,**kwargs,&block)
end

#proppatch(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a PROPPATCH HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1309
1310
1311
# File 'lib/ronin/support/network/http.rb', line 1309

def proppatch(path,**kwargs,&block)
  request(:proppatch,path,**kwargs,&block)
end

#put(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a PUT HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1334
1335
1336
# File 'lib/ronin/support/network/http.rb', line 1334

def put(path,**kwargs,&block)
  request(:put,path,**kwargs,&block)
end

#request(method, path, query: nil, query_params: nil, headers: nil, user_agent: @user_agent, cookie: @cookie, user: @user, password: @password, body: nil, form_data: nil, **additional_headers) {|response| ... } ⇒ Net::HTTPResponse

Sends an arbitrary HTTP request.

The HTTP method to use for the request.

Examples:

http.request(:get, '/')

Streaming response body:

http.request(:get, '/big_file.txt') do |response|
  respnse.read_body do |chunk|
    # ...
  end
end

Basic-Auth

http.request(:get, '/', user: 'admin', password: 'secret')

Query string:

http.request(:get, '/search', query: 'foo%20bar')

Query params:

http.request(:get, '/search', query_params: {q: 'foo bar'})

Request body:

http.request(:post, '/form', body: 'foo=1&bar=2')

Form data:

http.request(:post, '/form', form_data: {'foo' => 1, 'bar' => 2})

Streaming request body:

http.request(:put, '/file', body: File.new('/path/to/file'))

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock)
  • path (String)

    The path to to make the request for.

  • query (String, nil) (defaults to: nil)

    The query-string to append to the request path.

  • query_params (Hash, nil) (defaults to: nil)

    The query-params to append to the request path.

  • user (String, nil) (defaults to: @user)

    The user to authenticate as.

  • password (String, nil) (defaults to: @password)

    The password to authenticate with.

  • headers (Hash{Symbol,String => String}, nil) (defaults to: nil)

    Additional HTTP header names and values to add to the request.

  • cookie (String, Hash{String => String}, nil) (defaults to: @cookie)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie.

  • body (String, nil) (defaults to: nil)

    The body of the request.

  • form_data (Hash, String, nil) (defaults to: nil)

    The form data that may be sent in the body of the request.

  • additional_headers (Hash{Symbol => String})

    Additional headers to add to the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Raises:

  • (ArgumentError)

    The :method option did not match a known Net::HTTP request class.

Since:

  • 1.0.0



700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
# File 'lib/ronin/support/network/http.rb', line 700

def request(method,path, # query string keyword arguments
                         query:        nil,
                         query_params: nil,
                         # header keyword arguments
                         headers:    nil,
                         user_agent: @user_agent,
                         cookie:     @cookie,
                         # Basic-Auth keyword arguments
                         user:     @user,
                         password: @password,
                         # request body keyword arguments
                         body:      nil,
                         form_data: nil,
                         **additional_headers,
                         &block)
  request = Request.build(method,path, headers:      @headers,
                                       user_agent:   user_agent,
                                       cookie:       cookie,
                                       user:         user,
                                       password:     password,
                                       query:        query,
                                       query_params: query_params,
                                       body:         body,
                                       form_data:    form_data)

  if headers
    # populate any arbitrary headers
    headers.each do |name,value|
      request[name] = value
    end
  end

  unless additional_headers.empty?
    # set additional keyword argument headers (ex: `referer: '...'`
    additional_headers.each do |name,value|
      request[name] = value
    end
  end

  return @http.request(request,&block)
end

#response_body(method = :get, path, **kwargs) ⇒ String

Sends an arbitrary HTTP request and returns the response body.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :get)
  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String)

    The response body.

Since:

  • 1.0.0



911
912
913
# File 'lib/ronin/support/network/http.rb', line 911

def response_body(method=:get,path,**kwargs)
  request(method,path,**kwargs).body
end

#response_headers(method = :head, path, **kwargs) ⇒ Hash{String => String}

Sends an arbitrary HTTP request and returns the response headers.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

Since:

  • 1.0.0



837
838
839
840
841
842
843
844
845
# File 'lib/ronin/support/network/http.rb', line 837

def response_headers(method=:head,path,**kwargs)
  headers = {}

  request(method,path,**kwargs).each_capitalized do |name,value|
    headers[name] = value
  end

  return headers
end

#response_status(method = :head, path, **kwargs) ⇒ Integer

Sends an arbitrary HTTP request and returns the response status.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (Integer)

    The response status code.

Since:

  • 1.0.0



792
793
794
795
# File 'lib/ronin/support/network/http.rb', line 792

def response_status(method=:head,path,**kwargs)
  response = request(method,path,**kwargs)
  response.code.to_i
end

#server_header(method: :head, path: '/', **kwargs) ⇒ String?

Sends an HTTP request and returns the Server header.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String) (defaults to: '/')

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Returns:

  • (String, nil)

    The Server header.

Since:

  • 1.0.0



865
866
867
868
# File 'lib/ronin/support/network/http.rb', line 865

def server_header(method: :head, path: '/',**kwargs)
  response = request(method,path,**kwargs)
  response['Server']
end

#ssl?Boolean

Determines if the HTTP connect is using SSL/TLS.

Returns:

  • (Boolean)

Since:

  • 1.0.0



553
554
555
# File 'lib/ronin/support/network/http.rb', line 553

def ssl?
  @http.use_ssl?
end

#trace(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a TRACE HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1357
1358
1359
# File 'lib/ronin/support/network/http.rb', line 1357

def trace(path,**kwargs,&block)
  request(:trace,path,**kwargs,&block)
end

#unlock(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a UNLOCK HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

  • :headers (Hash{Symbol,String => String}, nil)

    Additional HTTP header names and values to add to the request.

  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

Yields:

  • (response)

    If a block is given it will be passed the received HTTP response.

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1380
1381
1382
# File 'lib/ronin/support/network/http.rb', line 1380

def unlock(path,**kwargs,&block)
  request(:unlock,path,**kwargs,&block)
end