@@ -208,13 +208,13 @@ def query_ldap_server(raw_filter, attributes, base_prefix: nil)
208
208
returned_entries
209
209
end
210
210
211
- def query_ldap_server_certificates ( esc_raw_filter , esc_name , notes : [ ] )
211
+ def query_ldap_server_certificates ( esc_raw_filter , esc_id , notes : [ ] )
212
212
attributes = [ 'cn' , 'name' , 'description' , 'ntSecurityDescriptor' , 'msPKI-Enrollment-Flag' , 'msPKI-RA-Signature' , 'PkiExtendedKeyUsage' ]
213
213
base_prefix = 'CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration'
214
214
esc_entries = query_ldap_server ( esc_raw_filter , attributes , base_prefix : base_prefix )
215
215
216
216
if esc_entries . empty?
217
- print_warning ( "Couldn't find any vulnerable #{ esc_name } templates!" )
217
+ print_warning ( "Couldn't find any vulnerable #{ esc_id } templates!" )
218
218
return
219
219
end
220
220
@@ -232,19 +232,15 @@ def query_ldap_server_certificates(esc_raw_filter, esc_name, notes: [])
232
232
233
233
certificate_symbol = entry [ :cn ] [ 0 ] . to_sym
234
234
if @certificate_details . key? ( certificate_symbol )
235
- @certificate_details [ certificate_symbol ] [ :techniques ] << esc_name
235
+ @certificate_details [ certificate_symbol ] [ :techniques ] << esc_id
236
236
@certificate_details [ certificate_symbol ] [ :notes ] += notes
237
237
else
238
- @certificate_details [ certificate_symbol ] = {
239
- name : entry [ :name ] [ 0 ] . to_s ,
240
- techniques : [ esc_name ] ,
241
- dn : entry [ :dn ] [ 0 ] . to_s ,
242
- enrollment_sids : convert_sids_to_human_readable_name ( allowed_sids ) ,
243
- ca_servers : { } ,
244
- manager_approval : ( [ entry [ %s(mspki-enrollment-flag) ] . first . to_i ] . pack ( 'l' ) . unpack1 ( 'L' ) & Rex ::Proto ::MsCrtd ::CT_FLAG_PEND_ALL_REQUESTS ) != 0 ,
245
- required_signatures : [ entry [ %s(mspki-ra-signature) ] . first . to_i ] . pack ( 'l' ) . unpack1 ( 'L' ) ,
238
+ @certificate_details [ certificate_symbol ] = build_certificate_details (
239
+ entry ,
240
+ allowed_sids ,
241
+ techniques : [ esc_id ] ,
246
242
notes : notes . dup
247
- }
243
+ )
248
244
end
249
245
end
250
246
end
@@ -480,7 +476,7 @@ def find_esc13_vuln_cert_templates
480
476
(mspki-certificate-policy=*)
481
477
)
482
478
FILTER
483
- attributes = [ 'cn' , 'description' , 'ntSecurityDescriptor' , 'msPKI-Certificate-Policy' ]
479
+ attributes = [ 'cn' , 'description' , 'ntSecurityDescriptor' , 'msPKI-Certificate-Policy' , 'msPKI-Enrollment-Flag' , 'msPKI-RA-Signature' ]
484
480
base_prefix = 'CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration'
485
481
esc_entries = query_ldap_server ( esc_raw_filter , attributes , base_prefix : base_prefix )
486
482
@@ -525,18 +521,24 @@ def find_esc13_vuln_cert_templates
525
521
@certificate_details [ certificate_symbol ] [ :techniques ] << 'ESC13'
526
522
@certificate_details [ certificate_symbol ] [ :notes ] << note
527
523
else
528
- @certificate_details [ certificate_symbol ] = {
529
- name : certificate_symbol . to_s ,
530
- techniques : [ 'ESC13' ] ,
531
- dn : entry [ :dn ] [ 0 ] . to_s ,
532
- enrollment_sids : convert_sids_to_human_readable_name ( allowed_sids ) ,
533
- ca_servers : { } ,
534
- notes : [ note ]
535
- }
524
+ @certificate_details [ certificate_symbol ] = build_certificate_details ( entry , allowed_sids , techniques : %w[ ESC13 ] , notes : [ note ] )
536
525
end
537
526
end
538
527
end
539
528
529
+ def build_certificate_details ( ldap_object , allowed_sids , techniques : [ ] , notes : [ ] )
530
+ {
531
+ name : ldap_object [ :cn ] [ 0 ] . to_s ,
532
+ techniques : techniques ,
533
+ dn : ldap_object [ :dn ] [ 0 ] . to_s ,
534
+ enrollment_sids : convert_sids_to_human_readable_name ( allowed_sids ) ,
535
+ ca_servers : { } ,
536
+ manager_approval : ( [ ldap_object [ %s(mspki-enrollment-flag) ] . first . to_i ] . pack ( 'l' ) . unpack1 ( 'L' ) & Rex ::Proto ::MsCrtd ::CT_FLAG_PEND_ALL_REQUESTS ) != 0 ,
537
+ required_signatures : [ ldap_object [ %s(mspki-ra-signature) ] . first . to_i ] . pack ( 'l' ) . unpack1 ( 'L' ) ,
538
+ notes : notes
539
+ }
540
+ end
541
+
540
542
def find_esc15_vuln_cert_templates
541
543
esc_raw_filter = '(&' \
542
544
'(objectclass=pkicertificatetemplate)' \
@@ -697,7 +699,7 @@ def print_vulnerable_cert_info
697
699
end
698
700
699
701
if hash [ :certificate_write_priv_sids ]
700
- print_status ( ' Users or Groups SIDs with Certificate Template write access :' )
702
+ print_status ( ' Certificate Template Write-Enabled SIDs :' )
701
703
hash [ :certificate_write_priv_sids ] . each do |sid |
702
704
print_status ( " * #{ highlight_sid ( sid ) } " )
703
705
end
@@ -744,6 +746,7 @@ def get_pki_object_by_oid(oid)
744
746
) &.first
745
747
@ldap_objects << pki_object if pki_object
746
748
end
749
+
747
750
pki_object
748
751
end
749
752
0 commit comments