Skip to content

Commit

Permalink
Clean up attempt_login method
Browse files Browse the repository at this point in the history
  • Loading branch information
adeherdt-r7 committed Jun 25, 2024
1 parent 3dff3cc commit 940c32b
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lib/metasploit/framework/login_scanner/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,39 @@ def attempt_login(credential)

command = redis_proto(['AUTH', "#{credential.private}"])
sock.put(command)
result_options[:proof] = sock.get_once

# No password - ( -ERR Client sent AUTH, but no password is set\r\n )
# Invalid password - ( -ERR invalid password\r\n )
# Valid password - (+OK\r\n)

if result_options[:proof] && (result_options[:proof] =~ OLD_PASSWORD_NOT_SET || result_options[:proof] =~ PASSWORD_NOT_SET)
result_options[:status] = Metasploit::Model::Login::Status::NO_AUTH_REQUIRED
elsif result_options[:proof] && result_options[:proof] =~ /^-ERR invalid password/i
result_options[:status] = Metasploit::Model::Login::Status::INCORRECT
elsif result_options[:proof] && result_options[:proof][/^\+OK/]
result_options[:status] = Metasploit::Model::Login::Status::SUCCESSFUL
end

proof = validate_login(sock.get_once)
result_options[:proof] = proof unless proof.nil?
rescue Rex::ConnectionError, EOFError, Timeout::Error, Errno::EPIPE => e
result_options.merge!(
proof: e,
status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
)
end

disconnect if self.sock

::Metasploit::Framework::LoginScanner::Result.new(result_options)
end

private

# Validates the login data received from Redis and returns the correct Login status
# based upon the contents Redis sent back:
#
# No password - ( -ERR Client sent AUTH, but no password is set\r\n )
# Invalid password - ( -ERR invalid password\r\n )
# Valid password - (+OK\r\n)
def validate_login(data)
return if data.nil?

return Metasploit::Model::Login::Status::NO_AUTH_REQUIRED if data =~ OLD_PASSWORD_NOT_SET
return Metasploit::Model::Login::Status::NO_AUTH_REQUIRED if data =~ PASSWORD_NOT_SET
return Metasploit::Model::Login::Status::INCORRECT if data[:proof] =~ /^-ERR invalid password/
return Metasploit::Model::Login::Status::SUCCESSFUL if data[:proof][/^\+OK/]

nil
end

# (see Base#set_sane_defaults)
def set_sane_defaults
self.connection_timeout ||= 30
Expand Down

0 comments on commit 940c32b

Please sign in to comment.