Files
metasploit-gs/lib/metasploit/framework/varnish/client.rb
T

58 lines
1.7 KiB
Ruby
Raw Normal View History

2016-11-21 22:06:20 -05:00
# -*- coding: binary -*-
require 'msf/core'
require 'msf/core/exploit/tcp'
module Metasploit
module Framework
module Varnish
module Client
2016-11-30 22:57:12 -05:00
@@AUTH_REQUIRED_REGEX = /107 \d+\s\s\s\s\s\s\n(\w+)\n\nAuthentication required\./ # 107 auth
@@AUTH_SUCCESS_REGEX = /200 \d+/ # 200 ok
def require_auth?
# function returns false if no auth is required, else the challenge string
2016-12-02 22:03:23 -05:00
res = sock.get_once # varnish can give the challenge on connect, so check if we have it already
if res && res =~ @@AUTH_REQUIRED_REGEX
return $1
end
# Cause a login fail to get the challenge. Length is correct, but this has upper chars, subtle diff for debugging
sock.put("auth #{Rex::Text.rand_text_alphanumeric(64)}\n")
res = sock.get_once # grab challenge
2016-11-30 22:57:12 -05:00
if res && res =~ @@AUTH_REQUIRED_REGEX
return $1
end
return false
end
2016-11-21 22:06:20 -05:00
def login(pass)
2016-11-30 19:45:24 -05:00
# based on https://www.varnish-cache.org/trac/wiki/CLI
2016-11-21 22:06:20 -05:00
begin
2016-11-30 22:57:12 -05:00
challenge = require_auth?
if !!challenge
response = Digest::SHA256.hexdigest("#{challenge}\n#{pass.strip}\n#{challenge}\n")
2016-11-30 19:45:24 -05:00
sock.put("auth #{response}\n")
2016-12-02 22:03:23 -05:00
res = sock.get_once
2016-11-30 22:57:12 -05:00
if res && res =~ @@AUTH_SUCCESS_REGEX
2016-11-30 19:45:24 -05:00
return true
2016-11-21 22:06:20 -05:00
else
2016-11-30 19:45:24 -05:00
return false
2016-11-21 22:06:20 -05:00
end
2016-11-30 19:45:24 -05:00
else
raise RuntimeError, "No Auth Required"
2016-11-21 22:06:20 -05:00
end
rescue Timeout::Error
raise RuntimeError, "Varnish Login timeout"
end
end
def close_session
sock.put('quit')
end
end
end
end
end