@@ -167,12 +167,16 @@ def run
167
167
def action_read ( obj )
168
168
security_descriptor = obj [ ATTRIBUTE ]
169
169
if security_descriptor . nil?
170
- print_status ( ' The msDS-AllowedToActOnBehalfOfOtherIdentity field is empty.' )
170
+ print_status ( " The #{ ATTRIBUTE } field is empty." )
171
171
return
172
172
end
173
173
174
+ if ( sddl = sd_to_sddl ( security_descriptor ) )
175
+ vprint_status ( "#{ ATTRIBUTE } : #{ sddl } " )
176
+ end
177
+
174
178
if security_descriptor . dacl . nil?
175
- print_status ( ' The msDS-AllowedToActOnBehalfOfOtherIdentity DACL field is empty.' )
179
+ print_status ( " The #{ ATTRIBUTE } DACL field is empty." )
176
180
return
177
181
end
178
182
@@ -211,22 +215,22 @@ def action_remove(obj)
211
215
security_descriptor . dacl . acl_size . clear
212
216
213
217
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." )
215
219
end
216
- print_good ( ' Successfully updated the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
220
+ print_good ( " Successfully updated the #{ ATTRIBUTE } attribute." )
217
221
end
218
222
219
223
def action_flush ( obj )
220
224
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." )
222
226
return
223
227
end
224
228
225
229
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." )
227
231
end
228
232
229
- print_good ( ' Successfully deleted the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
233
+ print_good ( " Successfully deleted the #{ ATTRIBUTE } attribute." )
230
234
end
231
235
232
236
def action_write ( obj )
@@ -239,26 +243,37 @@ def action_write(obj)
239
243
end
240
244
241
245
def _action_write_create ( obj , delegate_from )
246
+ vprint_status ( "Creating new #{ ATTRIBUTE } ..." )
242
247
security_descriptor = Rex ::Proto ::MsDtyp ::MsDtypSecurityDescriptor . new
243
248
security_descriptor . owner_sid = Rex ::Proto ::MsDtyp ::MsDtypSid . new ( 'S-1-5-32-544' )
244
249
security_descriptor . dacl = Rex ::Proto ::MsDtyp ::MsDtypAcl . new
245
250
security_descriptor . dacl . acl_revision = Rex ::Proto ::MsDtyp ::MsDtypAcl ::ACL_REVISION_DS
246
251
security_descriptor . dacl . aces << build_ace ( delegate_from [ 'ObjectSid' ] )
247
252
253
+ if ( sddl = sd_to_sddl ( security_descriptor ) )
254
+ vprint_status ( "New #{ ATTRIBUTE } : #{ sddl } " )
255
+ end
256
+
248
257
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." )
250
259
end
251
260
252
- print_good ( ' Successfully created the msDS-AllowedToActOnBehalfOfOtherIdentity attribute.' )
261
+ print_good ( " Successfully created the #{ ATTRIBUTE } attribute." )
253
262
print_status ( 'Added account:' )
254
263
print_status ( " #{ delegate_from [ 'ObjectSid' ] } (#{ delegate_from [ 'sAMAccountName' ] } )" )
255
264
end
256
265
257
266
def _action_write_update ( obj , delegate_from )
267
+ vprint_status ( "Updating existing #{ ATTRIBUTE } ..." )
258
268
security_descriptor = obj [ ATTRIBUTE ]
269
+
270
+ if ( sddl = sd_to_sddl ( security_descriptor ) )
271
+ vprint_status ( "Old #{ ATTRIBUTE } : #{ sddl } " )
272
+ end
273
+
259
274
if security_descriptor . dacl
260
275
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 ." )
262
277
end
263
278
# clear these fields so they'll be calculated automatically after the update
264
279
security_descriptor . dacl . acl_count . clear
@@ -271,10 +286,20 @@ def _action_write_update(obj, delegate_from)
271
286
272
287
security_descriptor . dacl . aces << build_ace ( delegate_from [ 'ObjectSid' ] )
273
288
289
+ if ( sddl = sd_to_sddl ( security_descriptor ) )
290
+ vprint_status ( "New #{ ATTRIBUTE } : #{ sddl } " )
291
+ end
292
+
274
293
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." )
276
295
end
277
296
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 )
279
304
end
280
305
end
0 commit comments