@@ -195,8 +195,7 @@ def request_raw(opts={})
195
195
# - cookie: Cookie header value
196
196
# - ctype: Content-Type header value, default: +application/x-www-form-urlencoded+
197
197
# - data: HTTP data (only useful with some methods, see rfc2616)
198
- # - encode: URI encode the supplied URI, default: false
199
- # - encode_params: URI encode the GET or POST variables (names and values), default: true
198
+ # - encode: URI encode the supplied URI
200
199
# - headers: HTTP headers as a hash, e.g. <code>{ "X-MyHeader" => "value" }</code>
201
200
# - method: HTTP method to use in the request, not limited to standard methods defined by rfc2616, default: GET
202
201
# - proto: protocol, default: HTTP
@@ -209,28 +208,28 @@ def request_raw(opts={})
209
208
# - vhost: Host header value
210
209
#
211
210
def request_cgi ( opts = { } )
212
- c_enc = opts [ 'encode' ] || false
213
- c_enc_p = ( opts [ 'encode_params ' ] == true or opts [ 'encode_params' ] . nil? ? true : false )
214
- c_cgi = opts [ 'uri ' ] || '/ '
215
- c_body = opts [ 'data ' ] || ''
216
- c_meth = opts [ 'method ' ] || 'GET '
217
- c_prot = opts [ 'proto ' ] || 'HTTP '
218
- c_vers = opts [ 'version ' ] || config [ 'version' ] || '1.1 '
219
- c_qs = opts [ 'query ' ] || ''
220
- c_varg = opts [ 'vars_get' ] || { }
221
- c_varp = opts [ 'vars_post ' ] || { }
222
- c_head = opts [ 'headers' ] || config [ 'headers ' ] || { }
223
- c_rawh = opts [ 'raw_headers ' ] || config [ 'raw_headers' ] || ''
224
- c_type = opts [ 'ctype ' ] || 'application/x-www-form-urlencoded'
225
- c_ag = opts [ 'agent ' ] || config [ 'agent ' ]
226
- c_cook = opts [ 'cookie ' ] || config [ 'cookie ' ]
227
- c_host = opts [ 'vhost' ] || config [ 'vhost ']
228
- c_conn = opts [ 'connection ' ]
229
- c_path = opts [ 'path_info' ]
230
- c_auth = opts [ 'basic_auth' ] || config [ 'basic_auth' ] || ''
231
- uri = set_cgi ( c_cgi )
232
- qstr = c_qs
233
- pstr = c_body
211
+ c_enc = opts [ 'encode' ] || false
212
+ c_cgi = opts [ 'uri ' ] || '/'
213
+ c_body = opts [ 'data ' ] || ''
214
+ c_meth = opts [ 'method ' ] || 'GET '
215
+ c_prot = opts [ 'proto ' ] || 'HTTP '
216
+ c_vers = opts [ 'version ' ] || config [ 'version' ] || '1.1 '
217
+ c_qs = opts [ 'query ' ] || ''
218
+ c_varg = opts [ 'vars_get ' ] || { }
219
+ c_varp = opts [ 'vars_post' ] || { }
220
+ c_head = opts [ 'headers ' ] || config [ 'headers' ] || { }
221
+ c_rawh = opts [ 'raw_headers' ] || config [ 'raw_headers ' ] || ''
222
+ c_type = opts [ 'ctype ' ] || 'application/x-www-form-urlencoded '
223
+ c_ag = opts [ 'agent ' ] || config [ 'agent' ]
224
+ c_cook = opts [ 'cookie ' ] || config [ 'cookie ' ]
225
+ c_host = opts [ 'vhost ' ] || config [ 'vhost ' ]
226
+ c_conn = opts [ 'connection ' ]
227
+ c_path = opts [ 'path_info ' ]
228
+ c_auth = opts [ 'basic_auth' ] || config [ 'basic_auth' ] || ''
229
+
230
+ uri = set_cgi ( c_cgi )
231
+ qstr = c_qs
232
+ pstr = c_body
234
233
235
234
if ( config [ 'pad_get_params' ] )
236
235
1 . upto ( config [ 'pad_get_params_count' ] . to_i ) do |i |
@@ -243,27 +242,25 @@ def request_cgi(opts={})
243
242
244
243
c_varg . each_pair do |var , val |
245
244
qstr << '&' if qstr . length > 0
246
- qstr << ( c_enc_p ? set_encode_uri ( var ) : var )
245
+ qstr << set_encode_uri ( var )
247
246
qstr << '='
248
- qstr << ( c_enc_p ? set_encode_uri ( val ) : val )
247
+ qstr << set_encode_uri ( val )
249
248
end
250
249
251
250
if ( config [ 'pad_post_params' ] )
252
251
1 . upto ( config [ 'pad_post_params_count' ] . to_i ) do |i |
253
- rand_var = Rex ::Text . rand_text_alphanumeric ( rand ( 32 ) +1 )
254
- rand_val = Rex ::Text . rand_text_alphanumeric ( rand ( 32 ) +1 )
255
252
pstr << '&' if pstr . length > 0
256
- pstr << ( c_enc_p ? set_encode_uri ( rand_var ) : rand_var )
253
+ pstr << set_encode_uri ( Rex :: Text . rand_text_alphanumeric ( rand ( 32 ) + 1 ) )
257
254
pstr << '='
258
- pstr << ( c_enc_p ? set_encode_uri ( rand_val ) : rand_val )
255
+ pstr << set_encode_uri ( Rex :: Text . rand_text_alphanumeric ( rand ( 32 ) + 1 ) )
259
256
end
260
257
end
261
258
262
259
c_varp . each_pair do |var , val |
263
260
pstr << '&' if pstr . length > 0
264
- pstr << ( c_enc_p ? set_encode_uri ( var ) : var )
261
+ pstr << set_encode_uri ( var )
265
262
pstr << '='
266
- pstr << ( c_enc_p ? set_encode_uri ( val ) : val )
263
+ pstr << set_encode_uri ( val )
267
264
end
268
265
269
266
req = ''
@@ -297,7 +294,6 @@ def request_cgi(opts={})
297
294
req << set_chunked_header ( )
298
295
req << set_raw_headers ( c_rawh )
299
296
req << set_body ( pstr )
300
-
301
297
req
302
298
end
303
299
@@ -365,7 +361,7 @@ def send_request(req, t = -1)
365
361
#
366
362
# Read a response from the server
367
363
#
368
- def read_response ( t = -1 )
364
+ def read_response ( t = -1 , opts = { } )
369
365
370
366
resp = Response . new
371
367
resp . max_data = config [ 'read_max_data' ]
@@ -392,7 +388,7 @@ def read_response(t = -1)
392
388
393
389
##########################################################################
394
390
# XXX: NOTE: BUG: get_once currently (as of r10042) rescues "Exception"
395
- # As such, the following rescue block will ever be reached. -jjd
391
+ # As such, the following rescue block will never be reached. -jjd
396
392
##########################################################################
397
393
398
394
# Handle unexpected disconnects
@@ -434,14 +430,20 @@ def read_response(t = -1)
434
430
return resp if not resp
435
431
436
432
# As a last minute hack, we check to see if we're dealing with a 100 Continue here.
437
- if resp . proto == '1.1' and resp . code == 100
438
- # If so, our real response becaome the body, so we re-parse it.
439
- body = resp . body
440
- resp = Response . new
441
- resp . max_data = config [ 'read_max_data' ]
442
- rv = resp . parse ( body )
443
- # XXX: At some point, this may benefit from processing post-completion code
444
- # as seen above.
433
+ # Most of the time this is handled by the parser via check_100()
434
+ if resp . proto == '1.1' and resp . code == 100 and not opts [ :skip_100 ]
435
+ # Read the real response from the body if we found one
436
+ # If so, our real response became the body, so we re-parse it.
437
+ if resp . body . to_s =~ /^HTTP/
438
+ body = resp . body
439
+ resp = Response . new
440
+ resp . max_data = config [ 'read_max_data' ]
441
+ rv = resp . parse ( body )
442
+ # We found a 100 Continue but didn't read the real reply yet
443
+ # Otherwise reread the reply, but don't try this hack again
444
+ else
445
+ resp = read_response ( t , :skip_100 => true )
446
+ end
445
447
end
446
448
447
449
resp
0 commit comments