Skip to content

Commit 260f793

Browse files
committed
y no update challenge
1 parent 8369855 commit 260f793

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

lib/metasploit/framework/login_scanner/varnish.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ class VarnishCLI
2424
def attempt_login(credential)
2525
begin
2626
connect
27+
success = login(credential.private)
28+
close_session
29+
disconnect
30+
rescue RuntimeError => e
31+
return {:status => Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, :proof => e.message}
2732
rescue Rex::ConnectionError, EOFError, Timeout::Error
2833
status = Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
29-
else
30-
begin
31-
success = login(credential.private)
32-
rescue RuntimeError => e
33-
return {:status => Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, :proof => e.message}
34-
end
35-
36-
status = (success == true) ? Metasploit::Model::Login::Status::SUCCESSFUL : Metasploit::Model::Login::Status::INCORRECT
3734
end
35+
status = (success == true) ? Metasploit::Model::Login::Status::SUCCESSFUL : Metasploit::Model::Login::Status::INCORRECT
36+
3837
result = Result.new(credential: credential, status: status)
3938
result.host = host
4039
result.port = port

lib/metasploit/framework/varnish/client.rb

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,31 @@ 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
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
12+
13+
def require_auth?
14+
# function returns false if no auth is required, else the challenge string
15+
sock.put("auth #{Rex::Text.rand_text_alphanumeric(64)}\n") # Cause a login fail to get the challenge. Length is correct, but this has upper chars, subtle diff
16+
res = sock.get_once(-1,3) # grab challenge
17+
if res && res =~ @@AUTH_REQUIRED_REGEX
18+
return $1
19+
end
20+
return false
21+
end
1222

1323
def login(pass)
1424
# based on https://www.varnish-cache.org/trac/wiki/CLI
1525
begin
16-
auth = require_auth?
17-
if not !!auth
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")
26+
challenge = require_auth?
27+
if !!challenge
28+
response = Digest::SHA256.hexdigest("#{challenge}\n#{pass.strip}\n#{challenge}\n")
2029
sock.put("auth #{response}\n")
2130
res = sock.get_once(-1,3)
22-
raise RuntimeError, res
23-
if res && res =~ @AUTH_SUCCESS_REGEX
31+
if res && res =~ @@AUTH_SUCCESS_REGEX
2432
return true
2533
else
34+
raise RuntimeError, "|||#{challenge}|||#{pass.strip}|||#{response}"
2635
return false
2736
end
2837
else
@@ -36,16 +45,6 @@ def login(pass)
3645
def close_session
3746
sock.put('quit')
3847
end
39-
40-
def require_auth?
41-
# function returns false if no auth is required, else
42-
sock.put("auth #{Rex::Text.rand_text_alphanumeric(3)}\n") # Cause a login fail to get the challenge
43-
res = sock.get_once(-1,3) # grab challenge
44-
if res && res =~ @AUTH_REQUIRED_REGEX
45-
return $1
46-
end
47-
return false
48-
end
4948

5049
end
5150
end

0 commit comments

Comments
 (0)