@@ -167,12 +167,16 @@ def run
167167 def action_read ( obj )
168168 security_descriptor = obj [ ATTRIBUTE ]
169169 if security_descriptor . nil?
170- print_status ( ' The msDS-AllowedToActOnBehalfOfOtherIdentity field is empty.' )
170+ print_status ( " The #{ ATTRIBUTE } field is empty." )
171171 return
172172 end
173173
174+ if ( sddl = sd_to_sddl ( security_descriptor ) )
175+ vprint_status ( "#{ ATTRIBUTE } : #{ sddl } " )
176+ end
177+
174178 if security_descriptor . dacl . nil?
175- print_status ( ' The msDS-AllowedToActOnBehalfOfOtherIdentity DACL field is empty.' )
179+ print_status ( " The #{ ATTRIBUTE } DACL field is empty." )
176180 return
177181 end
178182
@@ -211,22 +215,22 @@ def action_remove(obj)
211215 security_descriptor . dacl . acl_size . clear
212216
213217 unless @ldap . replace_attribute ( obj [ 'dn' ] , ATTRIBUTE , security_descriptor . to_binary_s )
214- fail_with_ldap_error ( ' Failed to update the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
218+ fail_with_ldap_error ( " Failed to update the #{ ATTRIBUTE } attribute." )
215219 end
216- print_good ( ' Successfully updated the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
220+ print_good ( " Successfully updated the #{ ATTRIBUTE } attribute." )
217221 end
218222
219223 def action_flush ( obj )
220224 unless obj [ ATTRIBUTE ]
221- print_status ( ' The msDS-AllowedToActOnBehalfOfOtherIdentity field is empty. No changes are necessary.' )
225+ print_status ( " The #{ ATTRIBUTE } field is empty. No changes are necessary." )
222226 return
223227 end
224228
225229 unless @ldap . delete_attribute ( obj [ 'dn' ] , ATTRIBUTE )
226- fail_with_ldap_error ( ' Failed to deleted the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
230+ fail_with_ldap_error ( " Failed to deleted the #{ ATTRIBUTE } attribute." )
227231 end
228232
229- print_good ( ' Successfully deleted the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
233+ print_good ( " Successfully deleted the #{ ATTRIBUTE } attribute." )
230234 end
231235
232236 def action_write ( obj )
@@ -239,26 +243,37 @@ def action_write(obj)
239243 end
240244
241245 def _action_write_create ( obj , delegate_from )
246+ vprint_status ( "Creating new #{ ATTRIBUTE } ..." )
242247 security_descriptor = Rex ::Proto ::MsDtyp ::MsDtypSecurityDescriptor . new
243248 security_descriptor . owner_sid = Rex ::Proto ::MsDtyp ::MsDtypSid . new ( 'S-1-5-32-544' )
244249 security_descriptor . dacl = Rex ::Proto ::MsDtyp ::MsDtypAcl . new
245250 security_descriptor . dacl . acl_revision = Rex ::Proto ::MsDtyp ::MsDtypAcl ::ACL_REVISION_DS
246251 security_descriptor . dacl . aces << build_ace ( delegate_from [ 'ObjectSid' ] )
247252
253+ if ( sddl = sd_to_sddl ( security_descriptor ) )
254+ vprint_status ( "New #{ ATTRIBUTE } : #{ sddl } " )
255+ end
256+
248257 unless @ldap . add_attribute ( obj [ 'dn' ] , ATTRIBUTE , security_descriptor . to_binary_s )
249- fail_with_ldap_error ( ' Failed to create the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
258+ fail_with_ldap_error ( " Failed to create the #{ ATTRIBUTE } attribute." )
250259 end
251260
252- print_good ( ' Successfully created the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
261+ print_good ( " Successfully created the #{ ATTRIBUTE } attribute." )
253262 print_status ( 'Added account:' )
254263 print_status ( " #{ delegate_from [ 'ObjectSid' ] } (#{ delegate_from [ 'sAMAccountName' ] } )" )
255264 end
256265
257266 def _action_write_update ( obj , delegate_from )
267+ vprint_status ( "Updating existing #{ ATTRIBUTE } ..." )
258268 security_descriptor = obj [ ATTRIBUTE ]
269+
270+ if ( sddl = sd_to_sddl ( security_descriptor ) )
271+ vprint_status ( "Old #{ ATTRIBUTE } : #{ sddl } " )
272+ end
273+
259274 if security_descriptor . dacl
260275 if security_descriptor . dacl . aces . any? { |ace | ace . body [ :sid ] . to_s == delegate_from [ 'ObjectSid' ] . to_s }
261- print_status ( "Delegation from #{ delegate_from [ 'sAMAccountName' ] } to #{ obj [ 'sAMAccountName' ] } is already enabled ." )
276+ print_status ( "Delegation from #{ delegate_from [ 'sAMAccountName' ] } to #{ obj [ 'sAMAccountName' ] } is already configured ." )
262277 end
263278 # clear these fields so they'll be calculated automatically after the update
264279 security_descriptor . dacl . acl_count . clear
@@ -271,10 +286,20 @@ def _action_write_update(obj, delegate_from)
271286
272287 security_descriptor . dacl . aces << build_ace ( delegate_from [ 'ObjectSid' ] )
273288
289+ if ( sddl = sd_to_sddl ( security_descriptor ) )
290+ vprint_status ( "New #{ ATTRIBUTE } : #{ sddl } " )
291+ end
292+
274293 unless @ldap . replace_attribute ( obj [ 'dn' ] , ATTRIBUTE , security_descriptor . to_binary_s )
275- fail_with_ldap_error ( ' Failed to update the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
294+ fail_with_ldap_error ( " Failed to update the #{ ATTRIBUTE } attribute." )
276295 end
277296
278- print_good ( 'Successfully updated the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
297+ print_good ( "Successfully updated the #{ ATTRIBUTE } attribute." )
298+ end
299+
300+ def sd_to_sddl ( sd )
301+ sd . to_sddl_text
302+ rescue StandardError => e
303+ elog ( 'failed to parse a binary security descriptor to SDDL' , error : e )
279304 end
280305end
0 commit comments