Skip to content

Commit a076a04

Browse files
committed
Responded to comments
1 parent b459d1a commit a076a04

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lib/msf/core/exploit/remote/ldap/active_directory.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,6 @@ def adds_get_ca_servers(ldap)
270270
}
271271
end
272272

273-
if ca_servers.empty?
274-
print_warning('No Certificate Authority servers found in LDAP.')
275-
else
276-
ca_servers.each do |ca|
277-
print_good("Found CA: #{ca[:name]} (#{ca[:dNSHostName]})")
278-
end
279-
end
280-
281273
ca_servers
282274
end
283275

modules/auxiliary/gather/ldap_esc_vulnerable_cert_finder.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def initialize(info = {})
9898
OptEnum.new('REPORT', [true, 'What templates to report (applies filtering to results)', 'vulnerable-and-published', %w[all published enrollable vulnerable vulnerable-and-published vulnerable-and-enrollable]]),
9999
OptBool.new('RUN_REGISTRY_CHECKS', [true, 'Authenticate to WinRM to query the registry values to enhance reporting for ESC9, ESC10 and ESC16. Must be a privileged user in order to query successfully', false]),
100100
OptString.new('CA', [false, 'The name of the Certificate Authority you wish to preform the registry checks on'], conditions: %w[RUN_REGISTRY_CHECKS == true]),
101-
OptInt.new('TIMEOUT', [false, 'The WinRM timeout when running registry checks', 20], conditions: %w[RUN_REGISTRY_CHECKS == true]),
101+
OptInt.new('WINRM_TIMEOUT', [false, 'The WinRM timeout when running registry checks', 20], conditions: %w[RUN_REGISTRY_CHECKS == true]),
102102
])
103103
end
104104

@@ -371,7 +371,7 @@ def query_ca_policy_values(shell)
371371
end
372372

373373
def query_dc_reg_values(ca_ip_address, domain, user)
374-
conn = create_winrm_connection(datastore['RHOST'], domain, user, datastore['TIMEOUT'])
374+
conn = create_winrm_connection(datastore['RHOST'], domain, user, datastore['WINRM_TIMEOUT'])
375375
handled_locally = false
376376
conn.shell(:powershell) do |shell|
377377
@registry_values[:certificate_mapping_methods] = run_registry_command(shell, 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\SecurityProviders\\Schannel', 'CertificateMappingMethods').to_i
@@ -384,21 +384,34 @@ def query_dc_reg_values(ca_ip_address, domain, user)
384384
return if handled_locally
385385

386386
query_ca_reg_values(ca_ip_address, domain, user)
387+
ensure
388+
shell.close if shell
387389
end
388390

389391
def query_ca_reg_values(ca_ip_address, domain, user)
390-
conn = create_winrm_connection(ca_ip_address, domain, user, datastore['TIMEOUT'])
392+
conn = create_winrm_connection(ca_ip_address, domain, user, datastore['WINRM_TIMEOUT'])
391393
conn.shell(:powershell) do |shell|
392394
@registry_values.merge!(query_ca_policy_values(shell))
393395
end
396+
ensure
397+
shell.close if shell
394398
end
395399

396400
def enum_registry_values
397401
@registry_values ||= {}
398402
domain = adds_get_domain_info(@ldap)[:dns_name]
399403
user = adds_get_current_user(@ldap)[:sAMAccountName].first.to_s
400404
ca_servers = adds_get_ca_servers(@ldap)
401-
ca_entry = ca_servers.find { |ca| ca[:name].casecmp(datastore['CA']).zero? }
405+
if ca_servers.empty?
406+
print_warning('No Certificate Authority servers found in LDAP.')
407+
return
408+
else
409+
ca_servers.each do |ca|
410+
print_good("Found CA: #{ca[:name]} (#{ca[:dNSHostName]})")
411+
end
412+
end
413+
414+
ca_entry = ca_servers.find { |ca| ca[:name].casecmp?(datastore['CA']) }
402415
unless ca_entry
403416
print_error("CA #{datastore['CA']} not found in LDAP. Checking registry values is unable to continue")
404417
return

0 commit comments

Comments
 (0)