lib/metasploit/framework/login_scanner/http.rb
# Attempt a single login with a single credential against the target.
#
# @param credential [Credential] The credential object to attempt to
#   login with.
# @return [Result] A Result object indicating success or failure
Attempt a single login with a single credential against the target.
Attempt a single login with a single credential against the target .
def attempt_login(credential)
          ssl = false if ssl.nil?
          result_opts = {
            credential: credential,
            status: Metasploit::Model::Login::Status::INCORRECT,
            proof: nil,
            host: host,
            port: port,
            protocol: 'tcp'
          }
          if ssl
            result_opts[:service_name] = 'https'
          else
            result_opts[:service_name] = 'http'
          end
          http_client = Rex::Proto::Http::Client.new(
            host, port, {}, ssl, ssl_version,
            nil, credential.public, credential.private
          )
          if credential.realm
            http_client.set_config('domain' => credential.realm)
          end
          begin
            http_client.connect
            request = http_client.request_cgi(
              'uri' => uri,
              'method' => method
            )
            response = http_client._send_recv(request)
            if response && response.code == 401 && response.headers['WWW-Authenticate']
              response = http_client.send_auth(
                response, request.opts, connection_timeout, true
              )
              if response && response.code == 200
                result_opts.merge!(status: Metasploit::Model::Login::Status::SUCCESSFUL, proof: response.headers)
              end
            else
              result_opts.merge!(status: Metasploit::Model::Login::Status::NO_AUTH_REQUIRED)
            end
          rescue ::EOFError, Errno::ETIMEDOUT, Rex::ConnectionError, ::Timeout::Error
            result_opts.merge!(status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT)
          ensure
            http_client.close
          end
          Result.new(result_opts)
        end
def attempt_login ( credential ) ssl = false if ssl . nil? result_opts = { credential : credential , status : Metasploit :: Model :: Login :: Status :: INCORRECT , proof : nil , host : host , port : port , protocol : 'tcp' } if ssl result_opts [ :service_name ] = 'https' else result_opts [ :service_name ] = 'http' end http_client = Rex :: Proto :: Http :: Client . new ( host , port , { } , ssl , ssl_version , nil , credential . public , credential . private ) if credential . realm http_client . set_config ( 'domain' => credential . realm ) end begin http_client . connect request = http_client . request_cgi ( 'uri' => uri , 'method' => method ) response = http_client . _send_recv ( request ) if response && response . code == 401 && response . headers [ 'WWW-Authenticate' ] response = http_client . send_auth ( response , request . opts , connection_timeout , true ) if response && response . code == 200 result_opts . merge! ( status : Metasploit :: Model :: Login :: Status :: SUCCESSFUL , proof : response . headers ) end else result_opts . merge! ( status : Metasploit :: Model :: Login :: Status :: NO_AUTH_REQUIRED ) end rescue :: EOFError , Errno :: ETIMEDOUT , Rex :: ConnectionError , :: Timeout :: Error result_opts . merge! ( status : Metasploit :: Model :: Login :: Status :: UNABLE_TO_CONNECT ) ensure http_client . close end Result . new ( result_opts ) end
Attempt a single login with a single credential against the target.
Attempt a single login with a single credential against the target .
# First try to connect without logging in to make sure this # resource requires authentication. We use #_send_recv for # that instead of #send_recv. # Now send the creds
A Result object indicating success or failure
A Result object indicating success or failure
Result
credential
The credential object to attempt to login with.
The credential object to attempt to login with .