Skip to content

Commit 02e3a55

Browse files
committed
Catch additional exceptions for failures
1 parent 389e8af commit 02e3a55

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Exploit::Remote::MsIcpr
3030
class MsIcprError < StandardError; end
3131
class MsIcprConnectionError < MsIcprError; end
3232
class MsIcprAuthenticationError < MsIcprError; end
33+
class MsIcprAuthorizationError < MsIcprError; end
3334
class MsIcprNotFoundError < MsIcprError; end
3435
class MsIcprUnexpectedReplyError < MsIcprError; end
3536
class MsIcprUnknownError < MsIcprError; end
@@ -91,7 +92,7 @@ def request_certificate(opts = {})
9192
rescue RubySMB::Error::UnexpectedStatusCode => e
9293
if e.status_code == ::WindowsError::NTStatus::STATUS_OBJECT_NAME_NOT_FOUND
9394
# STATUS_OBJECT_NAME_NOT_FOUND will be the status if Active Directory Certificate Service (AD CS) is not installed on the target
94-
raise MsIcprNotFoundError, 'Connection failed (AD CS was not found)'
95+
raise MsIcprNotFoundError, 'Connection failed (AD CS was not found).'
9596
end
9697

9798
elog(e.message, error: e)
@@ -192,6 +193,17 @@ def do_request_cert(icpr, opts)
192193
print_error(" Source: #{hresult.facility}") if hresult.facility
193194
print_error(" HRESULT: #{hresult}")
194195
end
196+
197+
case hresult
198+
when ::WindowsError::HResult::CERTSRV_E_ENROLL_DENIED
199+
raise MsIcprAuthorizationError.new(hresult.description)
200+
when ::WindowsError::HResult::CERTSRV_E_TEMPLATE_DENIED
201+
raise MsIcprAuthorizationError.new(hresult.description)
202+
when ::WindowsError::HResult::CERTSRV_E_UNSUPPORTED_CERT_TYPE
203+
raise MsIcprNotFoundError.new(hresult.description)
204+
else
205+
raise MsIcprUnknownError.new(hresult.description)
206+
end
195207
end
196208

197209
return unless response[:certificate]

modules/auxiliary/admin/dcerpc/cve_2022_26923_certifried.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ def run
139139
end
140140
end
141141
end
142-
rescue MsSamrConnectionError, MsIcprConnectionError => e
142+
rescue MsSamrConnectionError, MsIcprConnectionError, SmbIpcConnectionError => e
143143
fail_with(Failure::Unreachable, e.message)
144-
rescue MsSamrAuthenticationError, MsIcprAuthenticationError => e
144+
rescue MsSamrAuthenticationError, MsIcprAuthenticationError, MsIcprAuthorizationError, SmbIpcAuthenticationError => e
145145
fail_with(Failure::NoAccess, e.message)
146146
rescue MsSamrNotFoundError, MsIcprNotFoundError => e
147147
fail_with(Failure::NotFound, e.message)

modules/auxiliary/admin/dcerpc/icpr_cert.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def initialize(info = {})
5151

5252
def run
5353
send("action_#{action.name.downcase}")
54-
rescue MsIcprConnectionError => e
54+
rescue MsIcprConnectionError, SmbIpcConnectionError => e
5555
fail_with(Failure::Unreachable, e.message)
56-
rescue MsIcprAuthenticationError => e
56+
rescue MsIcprAuthenticationError, MsIcprAuthorizationError, SmbIpcAuthenticationError => e
5757
fail_with(Failure::NoAccess, e.message)
5858
rescue MsIcprNotFoundError => e
5959
fail_with(Failure::NotFound, e.message)

0 commit comments

Comments
 (0)