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.
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 159 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 130 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.
86 87 88 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 86 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.
96 97 98 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 96 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.
91 92 93 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 91 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.
58 59 60 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 58 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.
81 82 83 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 81 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.
76 77 78 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 76 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.
48 49 50 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 48 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.
41 42 43 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 41 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.
53 54 55 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 53 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.
71 72 73 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 71 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.
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 220 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 181 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.
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 259 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 230 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.
168 169 170 171 172 173 174 |
# File 'lib/ronin/vulns/web_vuln/http_request.rb', line 168 def user_agent_string case @user_agent when String, nil then @user_agent else Support::Network::HTTP::UserAgents[@user_agent] end end |