Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/metasploit/framework/varnish/client.rb
Views: 11784
# -*- coding: binary -*-1module Metasploit2module Framework3module Varnish4module Client56@@AUTH_REQUIRED_REGEX = /107 \d+\s\s\s\s\s\s\n(\w+)\n\nAuthentication required\./ # 107 auth7@@AUTH_SUCCESS_REGEX = /200 \d+/ # 200 ok89def require_auth?10# function returns false if no auth is required, else the challenge string11res = sock.get_once # varnish can give the challenge on connect, so check if we have it already12if res && res =~ @@AUTH_REQUIRED_REGEX13return $114end15# Cause a login fail to get the challenge. Length is correct, but this has upper chars, subtle diff for debugging16sock.put("auth #{Rex::Text.rand_text_alphanumeric(64)}\n")17res = sock.get_once # grab challenge18if res && res =~ @@AUTH_REQUIRED_REGEX19return $120end21return false22end2324def login(pass)25# based on https://www.varnish-cache.org/trac/wiki/CLI26begin27challenge = require_auth?28if !!challenge29response = Digest::SHA256.hexdigest("#{challenge}\n#{pass.strip}\n#{challenge}\n")30sock.put("auth #{response}\n")31res = sock.get_once32if res && res =~ @@AUTH_SUCCESS_REGEX33return true34else35return false36end37else38raise RuntimeError, "No Auth Required"39end40rescue Timeout::Error41raise RuntimeError, "Varnish Login timeout"42end43end4445def close_session46sock.put('quit')47end4849end50end51end52end53545556