Class: Ronin::CLI::Commands::Http Private
- Inherits:
-
ValueProcessorCommand
- Object
- Core::CLI::Command
- Ronin::CLI::Command
- ValueProcessorCommand
- Ronin::CLI::Commands::Http
- 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
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://
andhttps://
URL validation regex. URI::DEFAULT_PARSER.make_regexp(%w[http https])
Instance Attribute Summary collapse
-
#body ⇒ String?
readonly
private
The body to send with the request.
-
#form_data ⇒ Hash{String => String}
readonly
private
Form data.
-
#headers ⇒ Hash{String => String}
readonly
private
Additional HTTP request headers to send.
-
#http_method ⇒ Symbol
readonly
private
The HTTP request method.
-
#proxy ⇒ URI::HTTP?
readonly
private
The optional proxy to use.
-
#query_params ⇒ Hash{String => String}
readonly
private
Additional URL query params.
-
#user_agent ⇒ String?
readonly
private
Optional
User-agent
string to use.
Attributes inherited from ValueProcessorCommand
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ Http
constructor
private
Initializes the
ronin http
command. -
#print_response(response) ⇒ Object
private
Prints the HTTP response.
-
#process_value(url) ⇒ Object
private
Requests the given URL.
-
#run(*urls) ⇒ Object
private
Runs the
ronin http
command. -
#start_shell(base_url) ⇒ Object
private
Start the HTTPShell.
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
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.
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
#body ⇒ 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.
The body to send with the request.
278 279 280 |
# File 'lib/ronin/cli/commands/http.rb', line 278 def body @body end |
#form_data ⇒ Hash{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.
283 284 285 |
# File 'lib/ronin/cli/commands/http.rb', line 283 def form_data @form_data end |
#headers ⇒ Hash{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.
263 264 265 |
# File 'lib/ronin/cli/commands/http.rb', line 263 def headers @headers end |
#http_method ⇒ Symbol (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.
258 259 260 |
# File 'lib/ronin/cli/commands/http.rb', line 258 def http_method @http_method end |
#proxy ⇒ URI::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.
253 254 255 |
# File 'lib/ronin/cli/commands/http.rb', line 253 def proxy @proxy end |
#query_params ⇒ Hash{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.
273 274 275 |
# File 'lib/ronin/cli/commands/http.rb', line 273 def query_params @query_params end |
#user_agent ⇒ 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.
Optional User-agent
string to use.
268 269 270 |
# File 'lib/ronin/cli/commands/http.rb', line 268 def user_agent @user_agent end |
Instance Method Details
#print_response(response) ⇒ 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.
If --verbose
is specified then the response headers will also be
printed.
Prints the HTTP response.
379 380 381 |
# File 'lib/ronin/cli/commands/http.rb', line 379 def print_response(response) super(response, show_headers: [: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.
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.}" 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.) 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.
308 309 310 311 312 313 314 |
# File 'lib/ronin/cli/commands/http.rb', line 308 def run(*urls) if [:shell] start_shell([: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.
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 |