Skip to content

Instantly share code, notes, and snippets.

@gomasy
Created June 11, 2015 15:07
Show Gist options
  • Save gomasy/0f63f83f5d6d8aea3117 to your computer and use it in GitHub Desktop.
Save gomasy/0f63f83f5d6d8aea3117 to your computer and use it in GitHub Desktop.
require "uri"
require "securerandom"
require "net/http"
require "digest/md5"
url = URI.parse("http://ctfq.sweetduet.info:10080/~q9/flag.html")
uname = "q9"
realm = "secret"
qop = "auth"
nc = "00000001"
cnonce = SecureRandom.hex
hashed_a1 = "c627e19450db746b739f41b64097d449"
hashed_a2 = Digest::MD5.hexdigest(%(GET:#{url.path}))
Net::HTTP.start(url.host, url.port) do |http|
content = http.get(url.path)
nonce = content["WWW-Authenticate"].match(/nonce="(.+)",/)[1]
response = Digest::MD5.hexdigest(%(#{hashed_a1}:#{nonce}:#{nc}:#{cnonce}:#{qop}:#{hashed_a2}))
puts http.get(url.path, {"Authorization" => %(Digest username=#{uname}, realm="#{realm}", nonce="#{nonce}", uri="#{url.path}", algorithm=MD5, response="#{response}", qop=#{qop}, nc=#{nc}, cnonce="#{cnonce}")}).body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment