Skip to content

Commit 180795f

Browse files
committed
Fix rapid7#7743, nil @cnonce in rex/proto/http/client.rb
Fix rapid7#7743
1 parent 7585999 commit 180795f

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ def initialize(info = {})
8080
)
8181
register_autofilter_ports([ 80, 8080, 443, 8000, 8888, 8880, 8008, 3000, 8443 ])
8282
register_autofilter_services(%W{ http https })
83-
84-
# Used by digest auth
85-
@cnonce = make_cnonce
86-
@nonce_count = -1
8783
end
8884

8985

@@ -769,10 +765,6 @@ def http_fingerprint(opts={})
769765
fprint[:signature]
770766
end
771767

772-
def make_cnonce
773-
Digest::MD5.hexdigest "%x" % (Time.now.to_i + rand(65535))
774-
end
775-
776768
protected
777769

778770
attr_accessor :client

lib/rex/proto/http/client.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,18 @@ def basic_auth_header(username,password)
310310
auth_str = "Basic " + Rex::Text.encode_base64(auth_str)
311311
end
312312

313+
314+
def make_cnonce
315+
Digest::MD5.hexdigest "%x" % (Time.now.to_i + rand(65535))
316+
end
317+
313318
# Send a series of requests to complete Digest Authentication
314319
#
315320
# @param opts [Hash] the options used to build an HTTP request
316321
# @return [Response] the last valid HTTP response we received
317322
def digest_auth(opts={})
318-
@nonce_count = 0
323+
cnonce = make_cnonce
324+
nonce_count = 0
319325

320326
to = opts['timeout'] || 20
321327

@@ -330,7 +336,7 @@ def digest_auth(opts={})
330336
end
331337

332338
begin
333-
@nonce_count += 1
339+
nonce_count += 1
334340

335341
resp = opts['response']
336342

@@ -387,7 +393,7 @@ def digest_auth(opts={})
387393
[
388394
algorithm.hexdigest("#{digest_user}:#{parameters['realm']}:#{digest_password}"),
389395
parameters['nonce'],
390-
@cnonce
396+
cnonce
391397
].join ':'
392398
else
393399
"#{digest_user}:#{parameters['realm']}:#{digest_password}"
@@ -397,7 +403,7 @@ def digest_auth(opts={})
397403
ha2 = algorithm.hexdigest("#{method}:#{path}")
398404

399405
request_digest = [ha1, parameters['nonce']]
400-
request_digest.push(('%08x' % @nonce_count), @cnonce, qop) if qop
406+
request_digest.push(('%08x' % nonce_count), cnonce, qop) if qop
401407
request_digest << ha2
402408
request_digest = request_digest.join ':'
403409

@@ -407,8 +413,8 @@ def digest_auth(opts={})
407413
"realm=\"#{parameters['realm']}\"",
408414
"nonce=\"#{parameters['nonce']}\"",
409415
"uri=\"#{path}\"",
410-
"cnonce=\"#{@cnonce}\"",
411-
"nc=#{'%08x' % @nonce_count}",
416+
"cnonce=\"#{cnonce}\"",
417+
"nc=#{'%08x' % nonce_count}",
412418
"algorithm=#{algstr}",
413419
"response=\"#{algorithm.hexdigest(request_digest)[0, 32]}\"",
414420
# The spec says the qop value shouldn't be enclosed in quotes, but

0 commit comments

Comments
 (0)