Skip to content

Commit e473c08

Browse files
authored
Merge pull request #20542 from zeroSteiner/fix/smb-kerberos-login-exp
Fix a Kerberos Error Edge Case When Logging In
2 parents 3f1698f + c27138a commit e473c08

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/metasploit/framework/login_scanner/kerberos.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,30 @@ def self.login_status_for_kerberos_error(krb_err)
7878
case error_code
7979
when Rex::Proto::Kerberos::Model::Error::ErrorCodes::KDC_ERR_KEY_EXPIRED, Rex::Proto::Kerberos::Model::Error::ErrorCodes::KRB_AP_ERR_SKEW
8080
# Correct password, but either password needs resetting or clock is skewed
81-
Metasploit::Model::Login::Status::SUCCESSFUL
81+
begin
82+
pa_data_entry = krb_err.res.e_data_as_pa_data.find do |pa_data|
83+
pa_data.type == Rex::Proto::Kerberos::Model::PreAuthType::PA_PW_SALT
84+
end
85+
86+
if pa_data_entry
87+
pw_salt = pa_data_entry.decoded_value
88+
if pw_salt.nt_status
89+
case pw_salt.nt_status.value
90+
when ::WindowsError::NTStatus::STATUS_PASSWORD_EXPIRED
91+
# Windows Server 2019 Build 17763 (possibly others) replies with STATUS_PASSWORD_EXPIRED even when the password is incorrect
92+
Metasploit::Model::Login::Status::INCORRECT
93+
else
94+
Metasploit::Model::Login::Status::SUCCESSFUL
95+
end
96+
else
97+
Metasploit::Model::Login::Status::SUCCESSFUL
98+
end
99+
else
100+
Metasploit::Model::Login::Status::SUCCESSFUL
101+
end
102+
rescue Rex::Proto::Kerberos::Model::Error::KerberosDecodingError
103+
Metasploit::Model::Login::Status::SUCCESSFUL
104+
end
82105
when Rex::Proto::Kerberos::Model::Error::ErrorCodes::KDC_ERR_C_PRINCIPAL_UNKNOWN
83106
# The username doesn't exist
84107
Metasploit::Model::Login::Status::INVALID_PUBLIC_PART

modules/auxiliary/scanner/smb/smb_login.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def run_host(ip)
115115
fail_with(Msf::Exploit::Failure::BadConfig, 'The SMBDomain option is required when using Kerberos authentication.') if datastore['SMBDomain'].blank?
116116
fail_with(Msf::Exploit::Failure::BadConfig, 'The DomainControllerRhost is required when using Kerberos authentication.') if datastore['DomainControllerRhost'].blank?
117117

118-
if !datastore['PASSWORD']
118+
if datastore['SMBPass'].blank?
119119
# In case no password has been provided, we assume the user wants to use Kerberos tickets stored in cache
120120
# Write mode is still enable in case new TGS tickets are retrieved.
121121
ticket_storage = kerberos_ticket_storage({ read: true, write: true })
@@ -178,7 +178,7 @@ def run_host(ip)
178178
realm: domain,
179179
username: datastore['SMBUser'],
180180
password: datastore['SMBPass'],
181-
nil_passwords: datastore['SMB::Auth'] == Msf::Exploit::Remote::AuthOption::KERBEROS && !datastore['PASSWORD']
181+
nil_passwords: datastore['SMB::Auth'] == Msf::Exploit::Remote::AuthOption::KERBEROS && datastore['SMBPass'].blank?
182182
)
183183
cred_collection = prepend_db_hashes(cred_collection)
184184

0 commit comments

Comments
 (0)