lib/ronin/cli/commands/http.rb in ronin-2.0.5 vs lib/ronin/cli/commands/http.rb in ronin-2.1.0.rc1

- old
+ new

@@ -18,10 +18,11 @@ require 'ronin/cli/value_processor_command' require 'ronin/cli/printing/http' require 'ronin/cli/http_shell' require 'ronin/support/network/http' +require 'ronin/support/network/http/cookie' require 'command_kit/options/verbose' require 'addressable/uri' module Ronin @@ -55,13 +56,15 @@ # --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 + # -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 @@ -74,11 +77,11 @@ include CommandKit::Options::Verbose include Printing::HTTP # `http://` and `https://` URL validation regex. - URL_REGEX = URI::DEFAULT_PARSER.make_regexp(%w[http https]) + URL_REGEX = /\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/ usage '[options] {URL [...] | --shell URL}' option :method, value: { type: { @@ -176,17 +179,50 @@ }, desc: 'The User-Agent string to use' do |ua| @user_agent = ua end + # Mapping of user-agent aliases. + USER_AGENT_ALIASES = { + 'random' => :random, + 'chrome' => :chrome, + 'firefox' => :firefox, + 'safari' => :safari, + 'linux' => :linux, + 'macos' => :macos, + 'windows' => :windows, + 'iphone' => :iphone, + 'ipad' => :ipad, + 'android' => :android, + + 'chrome_linux' => :chrome_linux, + 'chrome_macos' => :chrome_macos, + 'chrome_windows' => :chrome_windows, + 'chrome_iphone' => :chrome_iphone, + 'chrome_ipad' => :chrome_ipad, + 'chrome_android' => :chrome_android, + + 'firefox_linux' => :firefox_linux, + 'firefox_macos' => :firefox_macos, + 'firefox_windows' => :firefox_windows, + 'firefox_iphone' => :firefox_iphone, + 'firefox_ipad' => :firefox_ipad, + + 'firefox_android' => :firefox_android, + + 'safari_macos' => :safari_macos, + 'safari_iphone' => :safari_iphone, + 'safari_ipad' => :safari_ipad, + + 'edge' => :edge + } + option :user_agent, short: '-u', value: { - type: Support::Network::HTTP::UserAgents::ALIASES.transform_keys { |key| - key.to_s.tr('_','-') - } + type: USER_AGENT_ALIASES }, - desc: 'The User-Agent to use' do |name| + desc: 'The User-Agent alias to use' do |name| @user_agent = name end option :header, short: '-H', value: { @@ -197,10 +233,39 @@ name, value = str.split(/:\s*/,2) @headers[name] = value end + option :cookie, short: '-C', + value: { + type: String, + usage: 'COOKIE' + }, + desc: 'Sets the Cookie header' do |cookie| + cookie = Support::Network::HTTP::Cookie.parse(cookie) + + if @cookie + @cookie.merge!(cookie) + else + @cookie = cookie + end + end + + option :cookie_param, short: '-c', + value: { + type: /[^\s=]+=\w+/, + usage: 'NAME=VALUE' + }, + desc: 'Sets an additional cookie param' do |param| + name, value = param.split('=',2) + + # lazy initialize the cookie + @cookie ||= Support::Network::HTTP::Cookie.new + + @cookie[name] = value + end + option :body, short: '-B', value: { type: String, usage: 'STRING' }, @@ -260,13 +325,18 @@ # Additional HTTP request headers to send. # # @return [Hash{String => String}] attr_reader :headers + # The optional `Cookie` header to send. + # + # @return [Ronin::Support::Network::HTTP::Cookie, nil] + attr_reader :cookie + # Optional `User-agent` string to use. # - # @return [String, nil] + # @return [String, Symbol, nil] attr_reader :user_agent # Additional URL query params. # # @return [Hash{String => String}] @@ -292,10 +362,11 @@ super(**kwargs) @proxy = nil @http_method = :get @headers = {} + @cookie = nil @user_agent = nil @query_params = {} @form_data = {} end @@ -345,9 +416,10 @@ 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