class Ronin::CLI::Commands::Http
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 random|chrome|firefox|safari|linux|macos|windows|iphone|ipad|android|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 alias to use -H, --header "NAME: VALUE" Adds a header to the request -C, --cookie COOKIE Sets the Cookie header -c, --cookie-param NAME=VALUE Sets an additional cookie param -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
Constants
- URL_REGEX
‘http://` and `https://` URL validation regex.
- USER_AGENT_ALIASES
Mapping of user-agent aliases.
Attributes
The body to send with the request.
@return [String, nil]
Form data.
@return [Hash{String => String}]
Additional HTTP request headers to send.
@return [Hash{String => String}]
The HTTP request method.
@return [Symbol]
The optional proxy to use.
@return [URI::HTTP, nil]
Additional URL query params.
@return [Hash{String => String}]
Optional ‘User-agent` string to use.
@return [String, Symbol, nil]
Public Class Methods
Initializes the ‘ronin http` command.
@param [Hash{Symbol => Object}] kwargs
Additional keyword arguments.
# File lib/ronin/cli/commands/http.rb, line 361 def initialize(**kwargs) super(**kwargs) @proxy = nil @http_method = :get @headers = {} @cookie = nil @user_agent = nil @query_params = {} @form_data = {} end
Public Instance Methods
Prints the HTTP response.
@param [Net::HTTPResponse] response
The HTTP response object.
@note
If `--verbose` is specified then the response headers will also be printed.
@see HTTPMethods#print_response
Ronin::CLI::Printing::HTTP#print_response
# File lib/ronin/cli/commands/http.rb, line 451 def print_response(response) super(response, show_headers: options[:verbose]) end
Requests the given URL.
@param [String] url
The URL to request.
# File lib/ronin/cli/commands/http.rb, line 405 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, cookie: @cookie, 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
Runs the ‘ronin http` command.
@param [Array<String>] urls
The URL(s) to request.
# File lib/ronin/cli/commands/http.rb, line 379 def run(*urls) if options[:shell] start_shell(options[:shell]) else super(*urls) end end
Start the {HTTPShell}.
@param [String] base_url
The base URL to connect to.
# File lib/ronin/cli/commands/http.rb, line 393 def start_shell(base_url) HTTPShell.start(base_url, proxy: @proxy, headers: @headers, user_agent: @user_agent) end