Skip to content

Commit 33e3a0b

Browse files
authored
Merge pull request rapid7#19984 from zeroSteiner/feat/lib/adcs-mm-updates/2
Feat/lib/adcs mm updates/2
2 parents 53394fb + 468f168 commit 33e3a0b

File tree

8 files changed

+44
-12
lines changed

8 files changed

+44
-12
lines changed

lib/metasploit/framework/data_service/proxy/session_data_proxy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def sessions(opts={})
1313
def report_session(opts)
1414
begin
1515
self.data_service_operation do |data_service|
16-
add_opts_workspace(opts)
16+
add_opts_workspace(opts, opts.fetch(:workspace, opts[:session]&.workspace))
1717
data_service.report_session(opts)
1818
end
1919
rescue => e

lib/msf/base/sessions/ldap.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,17 @@ def bootstrap(datastore = {}, handler = nil)
4242
session = self
4343
session.init_ui(user_input, user_output)
4444

45-
@info = "LDAP #{datastore['USERNAME']} @ #{@peer_info}"
45+
username = datastore['USERNAME']
46+
if username.blank?
47+
begin
48+
whoami = client.ldapwhoami
49+
rescue Net::LDAP::Error => e
50+
ilog('ldap session opened with no username and the target does not support the LDAP whoami extension')
51+
else
52+
username = whoami.delete_prefix('u:').split('\\').last
53+
end
54+
end
55+
@info = "LDAP #{username} @ #{@peer_info}"
4656
end
4757

4858
def execute_file(full_path, args)

lib/msf/core/auxiliary/report.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,14 @@ def report_vuln(opts={})
307307

308308
# report_vuln is only called in an identified case, consider setting value reported here
309309
attempt_info = {
310+
:workspace => opts[:workspace],
310311
:vuln_id => vuln.id,
311312
:attempted_at => timestamp || Time.now.utc,
312313
:exploited => false,
313314
:fail_detail => 'vulnerability identified',
314315
:fail_reason => 'Untried', # Mdm::VulnAttempt::Status::UNTRIED, avoiding direct dependency on Mdm, used elsewhere in this module
315316
:module => mname,
316-
:username => username || "unknown",
317+
:username => username || "unknown"
317318
}
318319

319320
# TODO: figure out what opts are required and why the above logic doesn't match that of the db_manager method

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)

modules/auxiliary/gather/ldap_esc_vulnerable_cert_finder.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,17 @@ def query_ldap_server_certificates(esc_raw_filter, esc_id, notes: [])
218218
def map_sids_to_names(sids_array)
219219
mapped = []
220220
sids_array.each do |sid|
221-
# this common SID doesn't always have an entry
222-
if sid == Rex::Proto::Secauthz::WellKnownSids::SECURITY_AUTHENTICATED_USER_SID
221+
# these common SIDs don't always have an entry
222+
case sid
223+
when Rex::Proto::Secauthz::WellKnownSids::SECURITY_AUTHENTICATED_USER_SID
223224
mapped << SID.new(sid, 'Authenticated Users')
224225
next
226+
when Rex::Proto::Secauthz::WellKnownSids::SECURITY_ENTERPRISE_CONTROLLERS_SID
227+
mapped << SID.new(sid, 'Enterprise Domain Controllers')
228+
next
229+
when Rex::Proto::Secauthz::WellKnownSids::SECURITY_LOCAL_SYSTEM_SID
230+
mapped << SID.new(sid, 'Local System')
231+
next
225232
end
226233

227234
sid_entry = get_object_by_sid(sid)
@@ -609,16 +616,17 @@ def print_vulnerable_cert_info
609616
info = nil if info.blank?
610617

611618
hash[:ca_servers].each_value do |ca_server|
612-
service = report_service({
619+
service = report_service(
613620
host: ca_server[:ip_address],
614621
port: 445,
615622
proto: 'tcp',
616623
name: 'AD CS',
617624
info: "AD CS CA name: #{ca_server[:name]}"
618-
})
625+
)
619626

620627
if ca_server[:ip_address].present?
621628
vuln = report_vuln(
629+
workspace: myworkspace,
622630
host: ca_server[:ip_address],
623631
port: 445,
624632
proto: 'tcp',

spec/lib/msf/base/sessions/ldap_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
allow(client).to receive(:peerinfo).and_return(peer_info)
2424
allow(client).to receive(:peerhost).and_return(address)
2525
allow(client).to receive(:peerport).and_return(port)
26+
allow(client).to receive(:ldapwhoami).and_return("u:WORKGROUP\\Administrator")
2627
end
2728

2829
it_behaves_like 'client session'

0 commit comments

Comments
 (0)