Refactor send_request_cgi_follow_redirect

bug/bundler_fix
Meatballs 2014-02-03 21:49:49 +00:00
parent 83925da2f1
commit a8ff6eb429
No known key found for this signature in database
GPG Key ID: 5380EAF01F2F8B38
2 changed files with 42 additions and 37 deletions

View File

@ -268,27 +268,36 @@ module Exploit::Remote::HttpClient
end end
end end
# Connects to the server, creates a request, sends the request,
# reads the response
# #
# Connects to the server, creates a request, sends the request, reads the response # Passes +opts+ through directly to Rex::Proto::Http::Client#request_cgi.
#
# Passes +opts+ through directly to Rex::Proto::Http::Client#request_cgi unless
# follow_redirect is true and the server responds with 30x.
# If the client is redirected +opts+ will be updated to reflect
# the redirect location and +opts['redirect_uri']+ will contain the full URI.
#
# #
def send_request_cgi(opts={}, timeout = 20) def send_request_cgi(opts={}, timeout = 20)
opts['redirect_depth'] ||= 1
t = opts[:timeout] ? opts[:timeout] : timeout
begin begin
c = connect(opts) c = connect(opts)
r = c.request_cgi(opts) r = c.request_cgi(opts)
response = c.send_recv(r, t) c.send_recv(r, opts[:timeout] ? opts[:timeout] : timeout)
rescue ::Errno::EPIPE, ::Timeout::Error
nil
end
end
if opts['follow_redirect'] && (opts['redirect_depth'] > 0) #
opts['redirect_depth'] -= 1 # Connects to the server, creates a request, sends the request, reads the response
# if a redirect (HTTP 30x response) is received it will attempt to follow the
# direct and retrieve that URI.
#
# The +opts+ will be updated to the updated location and +opts['redirect_uri']+
# will contain the full URI.
#
def send_request_cgi_follow_redirect(opts={}, timeout = 20, redirect_depth = 1)
response = send_request_cgi(opts, timeout)
if response && redirect_depth > 0
redirect_depth -= 1
if response
code = response.code code = response.code
if code == 301 || code == 302 || code == 303 || code == 307 || code == 308 if code == 301 || code == 302 || code == 303 || code == 307 || code == 308
@ -303,15 +312,11 @@ module Exploit::Remote::HttpClient
opts['ssl'] = true opts['ssl'] = true
end end
return send_request_cgi(opts, t) return send_request_cgi_follow_redirect(opts, timeout, redirect_depth)
end
end end
end end
response response
rescue ::Errno::EPIPE, ::Timeout::Error
nil
end
end end
# #

View File

@ -59,9 +59,9 @@ class Metasploit3 < Msf::Exploit::Remote
def check def check
uri = target_uri.path uri = target_uri.path
opts = { 'uri' => uri, 'follow_redirect' => true } opts = { 'uri' => uri }
response = send_request_cgi(opts) response = send_request_cgi_follow_redirect(opts)
if opts['redirect_uri'] if opts['redirect_uri']
vprint_status("Redirected to #{opts['redirect_uri']}.") vprint_status("Redirected to #{opts['redirect_uri']}.")