Skip to content

Commit c201955

Browse files
committed
Land rapid7#5387, @wchen-r7's user-configurable HTTP timeout
Fixes rapid7#5219, Add connection timeout and response timeout for HttpClient
2 parents 03b70e3 + e0d9ee0 commit c201955

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/msf/core/exploit/http/client.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def initialize(info = {})
5252
OptBool.new('SSL', [ false, 'Negotiate SSL for outgoing connections', false]),
5353
OptEnum.new('SSLVersion', [ false, 'Specify the version of SSL that should be used', 'Auto', ['Auto', 'SSL2', 'SSL3', 'TLS1']]),
5454
OptBool.new('FingerprintCheck', [ false, 'Conduct a pre-exploit fingerprint verification', true]),
55-
OptString.new('DOMAIN', [ true, 'The domain to use for windows authentification', 'WORKSTATION'])
55+
OptString.new('DOMAIN', [ true, 'The domain to use for windows authentification', 'WORKSTATION']),
56+
OptInt.new('HttpClientTimeout', [false, 'HTTP connection and receive timeout', 20])
5657
], self.class
5758
)
5859

@@ -307,10 +308,11 @@ def cleanup
307308
# Passes +opts+ through directly to Rex::Proto::Http::Client#request_raw.
308309
#
309310
def send_request_raw(opts={}, timeout = 20)
311+
actual_timeout = datastore['HttpClientTimeout'] || opts[:timeout] || timeout
310312
begin
311313
c = connect(opts)
312314
r = c.request_raw(opts)
313-
c.send_recv(r, opts[:timeout] ? opts[:timeout] : timeout)
315+
c.send_recv(r, actual_timeout)
314316
rescue ::Errno::EPIPE, ::Timeout::Error
315317
nil
316318
end
@@ -323,10 +325,11 @@ def send_request_raw(opts={}, timeout = 20)
323325
# Passes +opts+ through directly to Rex::Proto::Http::Client#request_cgi.
324326
#
325327
def send_request_cgi(opts={}, timeout = 20)
328+
actual_timeout = datastore['HttpClientTimeout'] || opts[:timeout] || timeout
326329
begin
327330
c = connect(opts)
328331
r = c.request_cgi(opts)
329-
c.send_recv(r, opts[:timeout] ? opts[:timeout] : timeout)
332+
c.send_recv(r, actual_timeout)
330333
rescue ::Errno::EPIPE, ::Timeout::Error
331334
nil
332335
end
@@ -341,7 +344,8 @@ def send_request_cgi(opts={}, timeout = 20)
341344
# will contain the full URI.
342345
#
343346
def send_request_cgi!(opts={}, timeout = 20, redirect_depth = 1)
344-
res = send_request_cgi(opts, timeout)
347+
actual_timeout = datastore['HttpClientTimeout'] || opts[:timeout] || timeout
348+
res = send_request_cgi(opts, actual_timeout)
345349
return res unless res && res.redirect? && redirect_depth > 0
346350

347351
redirect_depth -= 1
@@ -360,7 +364,7 @@ def send_request_cgi!(opts={}, timeout = 20, redirect_depth = 1)
360364
opts['ssl'] = false
361365
end
362366

363-
send_request_cgi!(opts, timeout, redirect_depth)
367+
send_request_cgi!(opts, actual_timeout, redirect_depth)
364368
end
365369

366370
#

0 commit comments

Comments
 (0)