Skip to content

Commit c190cc7

Browse files
committed
pushing for help
1 parent 372cf74 commit c190cc7

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

lib/metasploit/framework/varnish/client.rb

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,26 @@ module Framework
77
module Varnish
88
module Client
99

10+
auth_required_regex = /107 \d+\s\s\s\s\s\s\n(\w+)\n\nAuthentication required./ # 107 auth
11+
auth_success_regex = /200 \d+/ # 200 ok
1012

1113
def login(pass)
14+
# based on https://www.varnish-cache.org/trac/wiki/CLI
1215
begin
13-
if require_auth?
14-
sock.put("auth #{Rex::Text.rand_text_alphanumeric(3)}\n") # Cause a login fail to get the challenge
15-
res = sock.get_once(-1,3) # grab challenge
16-
if res && res =~ /107 \d+\s\s\s\s\s\s\n(\w+)\n\nAuthentication required./ # 107 auth
17-
challenge = $1
18-
response = challenge + "\n"
19-
response << pass + "\n"
20-
response << challenge + "\n"
21-
response = Digest::SHA256.hexdigest(response)
22-
sock.put("auth #{response}\n")
23-
res = sock.get_once(-1,3)
24-
if res && res =~ /200 \d+/ # 200 ok
25-
return true
26-
else
27-
return false
28-
end
16+
auth = require_auth?.to_s
17+
if not auth == 'false'
18+
#raise RuntimeError, $1 + "\n" + pass.strip + "\n" + $1 + "\n" + "auth " + Digest::SHA256.hexdigest("#{$1}\n#{pass.strip}\n#{$1}\n")
19+
response = Digest::SHA256.hexdigest("#{$1}\n#{pass.strip}\n#{$1}\n")
20+
sock.put("auth #{response}\n")
21+
res = sock.get_once(-1,3)
22+
raise RuntimeError, res
23+
if res && res =~ @auth_success_regex
24+
return true
2925
else
30-
raise RuntimeError, "Varnish Login timeout"
26+
return false
3127
end
28+
else
29+
raise RuntimeError, "No Auth Required"
3230
end
3331
rescue Timeout::Error
3432
raise RuntimeError, "Varnish Login timeout"
@@ -40,13 +38,14 @@ def close_session
4038
end
4139

4240
def require_auth?
41+
# function returns false if no auth is required, else
4342
sock.put("auth #{Rex::Text.rand_text_alphanumeric(3)}\n") # Cause a login fail to get the challenge
4443
res = sock.get_once(-1,3) # grab challenge
45-
if res && res =~ /107 \d+\s\s\s\s\s\s\n(\w+)\n\nAuthentication required./ # 107 auth
46-
return true
47-
else
48-
return false
49-
end
44+
if res && res =~ @auth_required_regex
45+
return $1
46+
else
47+
return false
48+
end
5049
end
5150

5251
end

0 commit comments

Comments
 (0)