Class: Ronin::CLI::Commands::Http Private

Inherits:
ValueProcessorCommand show all
Includes:
CommandKit::Options::Verbose, Printing::HTTP
Defined in:
lib/ronin/cli/commands/http.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Send HTTP requests or spawn an interactive HTTP shell.

Usage

ronin http [options] [URL [...] | --shell URL]

Options

-v, --verbose                    Enables verbose output
-f, --file FILE                  Optional file to read values from
    --method HTTP_METHOD         Send the HTTP request method
    --get                        Send a GET request
    --head                       Send a HEAD request
    --patch                      Send a PATCH request
    --post                       Send a POST request
    --put                        Send a PUT request
    --copy                       Send a COPY request
    --delete                     Send a DELETE request
    --lock                       Send a LOCK request
    --options                    Send a OPTIONS request
    --mkcol                      Send a MKCOL request
    --move                       Send a MOVE request
    --propfind                   Send a PROPFIND request
    --proppatch                  Send a PROPPATCH request
    --trace                      Send a TRACE request
    --unlock                     Send an UNLOCK request
    --shell URL                  Open an interactive HTTP shell
-P, --proxy URL                  The proxy to use
-U, --user-agent-string STRING   The User-Agent string to use
-u chrome-linux|chrome-macos|chrome-windows|chrome-iphone|chrome-ipad|chrome-android|firefox-linux|firefox-macos|firefox-windows|firefox-iphone|firefox-ipad|firefox-android|safari-macos|safari-iphone|safari-ipad|edge,
    --user-agent                 The User-Agent to use
-H, --header "NAME: VALUE"       Adds a header to the request
-B, --body STRING                The request body
-F, --body-file FILE             Sends the file as the request body
-f, --form-data NAME=VALUE       Adds a value to the form data
-q, --query-param NAME=VALUE     Adds a query param to the URL
-h, --help                       Print help information

Arguments

[URL ...]                        The URL(s) to request

Since:

  • 2.0.0

Constant Summary collapse

URL_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

http:// and https:// URL validation regex.

Since:

  • 2.0.0

URI::DEFAULT_PARSER.make_regexp(%w[http https])

Instance Attribute Summary collapse

Attributes inherited from ValueProcessorCommand

#files

Instance Method Summary collapse

Methods included from Printing::HTTP

#print_body, #print_headers, #print_highlighted_body, #print_last_newline, #print_plain_body, #syntax_lexer_for_content_type

Methods included from Printing::SyntaxHighlighting

#syntax_formatter, #syntax_lexer, #syntax_lexer_for, #syntax_theme

Methods inherited from ValueProcessorCommand

#process_file

Constructor Details

#initialize(**kwargs) ⇒ Http

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the ronin http command.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Since:

  • 2.0.0



291
292
293
294
295
296
297
298
299
300
# File 'lib/ronin/cli/commands/http.rb', line 291

def initialize(**kwargs)
  super(**kwargs)

  @proxy        = nil
  @http_method  = :get
  @headers      = {}
  @user_agent   = nil
  @query_params = {}
  @form_data    = {}
end

Instance Attribute Details

#bodyString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The body to send with the request.

Returns:

  • (String, nil)

Since:

  • 2.0.0



278
279
280
# File 'lib/ronin/cli/commands/http.rb', line 278

def body
  @body
end

#form_dataHash{String => String} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Form data.

Returns:

  • (Hash{String => String})

Since:

  • 2.0.0



283
284
285
# File 'lib/ronin/cli/commands/http.rb', line 283

def form_data
  @form_data
end

#headersHash{String => String} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Additional HTTP request headers to send.

Returns:

  • (Hash{String => String})

Since:

  • 2.0.0



263
264
265
# File 'lib/ronin/cli/commands/http.rb', line 263

def headers
  @headers
end

#http_methodSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The HTTP request method.

Returns:

  • (Symbol)

Since:

  • 2.0.0



258
259
260
# File 'lib/ronin/cli/commands/http.rb', line 258

def http_method
  @http_method
end

#proxyURI::HTTP? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The optional proxy to use.

Returns:

  • (URI::HTTP, nil)

Since:

  • 2.0.0



253
254
255
# File 'lib/ronin/cli/commands/http.rb', line 253

def proxy
  @proxy
end

#query_paramsHash{String => String} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Additional URL query params.

Returns:

  • (Hash{String => String})

Since:

  • 2.0.0



273
274
275
# File 'lib/ronin/cli/commands/http.rb', line 273

def query_params
  @query_params
end

#user_agentString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Optional User-agent string to use.

Returns:

  • (String, nil)

Since:

  • 2.0.0



268
269
270
# File 'lib/ronin/cli/commands/http.rb', line 268

def user_agent
  @user_agent
end

Instance Method Details

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

If --verbose is specified then the response headers will also be printed.

Prints the HTTP response.

Parameters:

  • response (Net::HTTPResponse)

    The HTTP response object.

See Also:

  • HTTPMethods#print_response

Since:

  • 2.0.0



379
380
381
# File 'lib/ronin/cli/commands/http.rb', line 379

def print_response(response)
  super(response, show_headers: options[:verbose])
end

#process_value(url) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Requests the given URL.

Parameters:

  • url (String)

    The URL to request.

Since:

  • 2.0.0



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/ronin/cli/commands/http.rb', line 334

def process_value(url)
  unless url =~ URL_REGEX
    print_error "invalid URL: #{url.inspect}"
    return
  end

  uri = begin
          Addressable::URI.parse(url)
        rescue Addressable::URI::InvalidURIError => error
          print_error "invalid URL: #{error.message}"
          return
        end

  begin
    Support::Network::HTTP.request(
      @http_method, uri, proxy:        @proxy,
                         user_agent:   @user_agent,
                         query_params: @query_params,
                         headers:      @headers,
                         body:         @body,
                         form_data:    @form_data
    ) do |response|
      # NOTE: we must call HTTP.request with a block to avoid causing
      # #read_body to be called twice.
      print_response(response)
    end
  rescue StandardError => error
    if verbose? then print_exception(error)
    else             print_error(error.message)
    end
  end
end

#run(*urls) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the ronin http command.

Parameters:

  • urls (Array<String>)

    The URL(s) to request.

Since:

  • 2.0.0



308
309
310
311
312
313
314
# File 'lib/ronin/cli/commands/http.rb', line 308

def run(*urls)
  if options[:shell]
    start_shell(options[:shell])
  else
    super(*urls)
  end
end

#start_shell(base_url) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Start the HTTPShell.

Parameters:

  • base_url (String)

    The base URL to connect to.

Since:

  • 2.0.0



322
323
324
325
326
# File 'lib/ronin/cli/commands/http.rb', line 322

def start_shell(base_url)
  HTTPShell.start(base_url, proxy:      @proxy,
                            headers:    @headers,
                            user_agent: @user_agent)
end