Class: Ronin::Vulns::WebVuln::HTTPRequest Private
- Inherits:
-
Object
- Object
- Ronin::Vulns::WebVuln::HTTPRequest
- Defined in:
- lib/ronin/vulns/web_vuln/http_request.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.
Represents a HTTP request.
Constant Summary collapse
- CRLF =
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 newline deliminator.
"\r\n"
Instance Attribute Summary collapse
-
#cookie ⇒ Ronin::Support::Network::HTTP::Cookie?
readonly
private
Additional
Cookie
header for the request. -
#form_data ⇒ Hash{String => Object}?
readonly
private
The form data that may be sent in the body of the request.
-
#headers ⇒ Hash{Symbol,String => String}?
readonly
private
Additional HTTP header names and values to add to the request.
-
#password ⇒ String?
readonly
private
The password to authenticate with.
-
#query_params ⇒ Hash{String,Symbol => String}?
readonly
private
The query param for the request.
-
#referer ⇒ String?
readonly
private
The optional HTTP
Referer
header for the request. -
#request_method ⇒ :copy, ...
readonly
private
The HTTP request method.
-
#url ⇒ URI::HTTP
readonly
private
The URL of the request.
-
#user ⇒ String?
readonly
private
The user to authenticate as.
-
#user_agent ⇒ String, ...
readonly
private
The optional HTTP
User-Agent
header to send with each request.
Instance Method Summary collapse
-
#initialize(url, request_method: :get, user: nil, password: nil, user_agent: nil, referer: nil, query_params: nil, headers: nil, cookie: nil, form_data: nil) ⇒ HTTPRequest
constructor
private
Initializes the HTTP request object.
-
#to_curl ⇒ String
private
Converts the HTTP request to a
curl
command. -
#to_http ⇒ String
private
Converts the HTTP request to a raw HTTP request.
-
#user_agent_string ⇒ String?
private
The
User-Agent
string for the request.
Constructor Details
#initialize(url, request_method: :get, user: nil, password: nil, user_agent: nil, referer: nil, query_params: nil, headers: nil, cookie: nil, form_data: nil) ⇒ HTTPRequest
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 HTTP request object.
The HTTP request mehtod for each request.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 129 def initialize(url, request_method: :get, user: nil, password: nil, user_agent: nil, referer: nil, query_params: nil, headers: nil, cookie: nil, form_data: nil) @url = url if query_params && !query_params.empty? @url = url.dup @url.query_params = query_params end @request_method = request_method @user = user @password = password @user_agent = user_agent @referer = referer @query_params = query_params @cookie = if Support::Network::HTTP::Cookie.new() end @headers = headers @form_data = form_data end |
Instance Attribute Details
#cookie ⇒ Ronin::Support::Network::HTTP::Cookie? (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 Cookie
header for the request.
85 86 87 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 85 def @cookie end |
#form_data ⇒ Hash{String => Object}? (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 form data that may be sent in the body of the request.
95 96 97 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 95 def form_data @form_data end |
#headers ⇒ Hash{Symbol,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 header names and values to add to the request.
90 91 92 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 90 def headers @headers end |
#password ⇒ 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 password to authenticate with.
57 58 59 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 57 def password @password end |
#query_params ⇒ Hash{String,Symbol => 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 query param for the request.
80 81 82 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 80 def query_params @query_params end |
#referer ⇒ 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 optional HTTP Referer
header for the request.
75 76 77 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 75 def referer @referer end |
#request_method ⇒ :copy, ... (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.
47 48 49 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 47 def request_method @request_method end |
#url ⇒ 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 URL of the request.
40 41 42 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 40 def url @url end |
#user ⇒ 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 user to authenticate as.
52 53 54 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 52 def user @user 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.
The optional HTTP User-Agent
header to send with each request.
70 71 72 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 70 def user_agent @user_agent end |
Instance Method Details
#to_curl ⇒ String
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.
Converts the HTTP request to a curl
command.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 180 def to_curl escape = ->(str) { "'#{str.to_s.tr("'","\\'")}'" } command = ['curl'] if @request_method != :get command << '--request' << @request_method.upcase end if (@user || @password) command << '--user' << escape.call("#{@user}:#{@password}") end if @user_agent command << '--user-agent' << escape.call(user_agent_string) end if @referer command << '--referer' << escape.call(@referer) end if (@cookie && !@cookie.empty?) command << '--cookie' << escape.call(@cookie) end if @headers @headers.each do |name,value| command << '--header' << escape.call("#{name}: #{value}") end end if (@form_data && !@form_data.empty?) form_string = URI.encode_www_form(@form_data) command << '--form-string' << escape.call(form_string) end command << escape.call(@url) return command.join(' ') end |
#to_http ⇒ String
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.
Converts the HTTP request to a raw HTTP request.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 229 def to_http request = [] request << "#{@request_method.upcase} #{@url.request_uri} HTTP/1.1" if (@form_data && !@form_data.empty?) request << "Content-Type: x-www-form-urlencoded" end if (@user || @password) basic_auth = ["#{@user}:#{@password}"].pack('m0') request << "Authorization: Basic #{basic_auth}" end request << "User-Agent: #{user_agent_string}" if @user_agent request << "Referer: #{@referer}" if @referer request << "Cookie: #{@cookie}" if (@cookie && !@cookie.empty?) if @headers @headers.each do |name,value| request << "#{name}: #{value}" end end if (@form_data && !@form_data.empty?) request << '' request << URI.encode_www_form(@form_data) end return request.join(CRLF) << CRLF end |
#user_agent_string ⇒ String?
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 User-Agent
string for the request.
167 168 169 170 171 172 173 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 167 def user_agent_string case @user_agent when String, nil then @user_agent else Support::Network::HTTP::UserAgents[@user_agent] end end |