Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/lib/rex/proto/http/auth_digest.rb
Views: 18091
require 'digest'1require 'rex/text'23module Rex4module Proto5module Http6class AuthDigest78def make_cnonce9Digest::MD5.hexdigest '%x' % (::Time.now.to_i + rand(65535))10end1112def digest(digest_user, digest_password, method, path, parameters, iis = false)13cnonce = make_cnonce14nonce_count = 11516qop = parameters['qop']1718if parameters['algorithm'] =~ /(.*?)(-sess)?$/19algorithm = case ::Regexp.last_match(1)20when 'MD5' then Digest::MD521when 'MD-5' then Digest::MD522when 'SHA1' then Digest::SHA123when 'SHA-1' then Digest::SHA124when 'SHA2' then Digest::SHA225when 'SHA-2' then Digest::SHA226when 'SHA256' then Digest::SHA25627when 'SHA-256' then Digest::SHA25628when 'SHA384' then Digest::SHA38429when 'SHA-384' then Digest::SHA38430when 'SHA512' then Digest::SHA51231when 'SHA-512' then Digest::SHA51232when 'RMD160' then Digest::RMD16033else raise "unknown algorithm \"#{::Regexp.last_match(1)}\""34end35algstr = parameters['algorithm']36sess = ::Regexp.last_match(2)37else38algorithm = Digest::MD539algstr = 'MD5'40sess = false41end42a1 = if sess43[44algorithm.hexdigest("#{digest_user}:#{parameters['realm']}:#{digest_password}"),45parameters['nonce'],46cnonce47].join ':'48else49"#{digest_user}:#{parameters['realm']}:#{digest_password}"50end5152ha1 = algorithm.hexdigest(a1)53ha2 = algorithm.hexdigest("#{method}:#{path}")5455request_digest = [ha1, parameters['nonce']]56request_digest.push(('%08x' % nonce_count), cnonce, qop) if qop57request_digest << ha258request_digest = request_digest.join ':'59# Same order as IE760return [61"Digest username=\"#{digest_user}\"",62"realm=\"#{parameters['realm']}\"",63"nonce=\"#{parameters['nonce']}\"",64"uri=\"#{path}\"",65"cnonce=\"#{cnonce}\"",66"nc=#{'%08x' % nonce_count}",67"algorithm=#{algstr}",68"response=\"#{algorithm.hexdigest(request_digest)}\"",69# The spec says the qop value shouldn't be enclosed in quotes, but70# some versions of IIS require it and Apache accepts it. Chrome71# and Firefox both send it without quotes but IE does it this way.72# Use the non-compliant-but-everybody-does-it to be as compatible73# as possible by default. The user can override if they don't like74# it.75if iis76"qop=\"#{qop}\""77else78"qop=#{qop}"79end,80if parameters.key? 'opaque'81"opaque=\"#{parameters['opaque']}\""82end83].compact84end85end86end87end88end899091