Skip to content

Commit 196e198

Browse files
committed
Add some error handling for kerberos options
1 parent c1074c1 commit 196e198

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

lib/msf/core/exploit/remote/http_client.rb

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,29 @@ def connect(opts={})
159159

160160
http_logger_subscriber = Rex::Proto::Http::HttpLoggerSubscriber.new(logger: self)
161161

162-
kerberos_authenticator = Msf::Exploit::Remote::Kerberos::ServiceAuthenticator::HTTP.new(
163-
host: datastore['DomainControllerRhost'],
164-
hostname: datastore['HTTP::Rhostname'],
165-
proxies: datastore['Proxies'],
166-
realm: datastore['DOMAIN'],
167-
username: datastore['HttpUsername'],
168-
password: datastore['HttpPassword'],
169-
timeout: 20, # datastore['timeout']
170-
framework: framework,
171-
framework_module: self,
172-
cache_file: datastore['HTTP::Krb5Ccname'].blank? ? nil : datastore['HTTP::Krb5Ccname'],
173-
mutual_auth: true,
174-
use_gss_checksum: true,
175-
ticket_storage: kerberos_ticket_storage,
176-
offered_etypes: Msf::Exploit::Remote::AuthOption.as_default_offered_etypes(datastore['HTTP::KrbOfferedEncryptionTypes'])
177-
)
162+
kerberos_authenticator = nil
163+
if datastore['HTTP::Auth'] == Msf::Exploit::Remote::AuthOption::KERBEROS
164+
fail_with(Msf::Exploit::Failure::BadConfig, 'The HTTP::Rhostname option is required when using Kerberos authentication.') if datastore['HTTP::Rhostname'].blank?
165+
fail_with(Msf::Exploit::Failure::BadConfig, 'The DOMAIN option is required when using Kerberos authentication.') if datastore['DOMAIN'].blank?
166+
offered_etypes = Msf::Exploit::Remote::AuthOption.as_default_offered_etypes(datastore['HTTP::KrbOfferedEncryptionTypes'])
167+
fail_with(Msf::Exploit::Failure::BadConfig, 'At least one encryption type is required when using Kerberos authentication.') if offered_etypes.empty?
168+
169+
kerberos_authenticator = Msf::Exploit::Remote::Kerberos::ServiceAuthenticator::HTTP.new(
170+
host: datastore['DomainControllerRhost'],
171+
hostname: datastore['HTTP::Rhostname'],
172+
proxies: datastore['Proxies'],
173+
realm: datastore['DOMAIN'],
174+
username: datastore['HttpUsername'],
175+
password: datastore['HttpPassword'],
176+
framework: framework,
177+
framework_module: self,
178+
cache_file: datastore['HTTP::Krb5Ccname'].blank? ? nil : datastore['HTTP::Krb5Ccname'],
179+
mutual_auth: true,
180+
use_gss_checksum: true,
181+
ticket_storage: kerberos_ticket_storage,
182+
offered_etypes: offered_etypes
183+
)
184+
end
178185

179186
nclient = Rex::Proto::Http::Client.new(
180187
opts['rhost'] || rhost,

lib/rex/proto/http/client.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,21 @@ def send_auth(res, opts, t, persist)
314314
res = temp_response
315315
end
316316
return res
317+
elsif supported_auths.include?('Kerberos') && (preferred_auth.nil? || preferred_auth == 'Kerberos') && kerberos_authenticator
318+
opts['provider'] = 'Kerberos'
319+
temp_response = kerberos_auth(opts, mechanism: Rex::Proto::Gss::Mechanism::KERBEROS)
320+
if temp_response.is_a? Rex::Proto::Http::Response
321+
res = temp_response
322+
end
323+
return res
317324
elsif supported_auths.include?('Negotiate') && (preferred_auth.nil? || preferred_auth == 'Negotiate')
318325
opts['provider'] = 'Negotiate'
319326
temp_response = negotiate_auth(opts)
320327
if temp_response.is_a? Rex::Proto::Http::Response
321328
res = temp_response
322329
end
323330
return res
324-
elsif supported_auths.include?('Negotiate') && (preferred_auth.nil? || preferred_auth == 'Kerberos')
331+
elsif supported_auths.include?('Negotiate') && (preferred_auth.nil? || preferred_auth == 'Kerberos') && kerberos_authenticator
325332
opts['provider'] = 'Negotiate'
326333
temp_response = kerberos_auth(opts, mechanism: Rex::Proto::Gss::Mechanism::SPNEGO)
327334
if temp_response.is_a? Rex::Proto::Http::Response

0 commit comments

Comments
 (0)