494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
|
# File 'lib/rex/proto/ms_dtyp.rb', line 494
def self.from_sddl_text(sddl_text, domain_sid:)
parts = sddl_text.upcase.split(';', -1)
raise SDDLParseError.new('too few ACE fields') if parts.length < 6
raise SDDLParseError.new('too many ACE fields') if parts.length > 7
ace_type, ace_flags, rights, object_guid, inherit_object_guid, account_sid = parts[0...6]
resource_attribute = parts[6]
ace = self.new
case ace_type
when 'A'
ace..ace_type = MsDtypAceType::ACCESS_ALLOWED_ACE_TYPE
when 'D'
ace..ace_type = MsDtypAceType::ACCESS_DENIED_ACE_TYPE
when 'OA'
ace..ace_type = MsDtypAceType::ACCESS_ALLOWED_OBJECT_ACE_TYPE
when 'OD'
ace..ace_type = MsDtypAceType::ACCESS_DENIED_OBJECT_ACE_TYPE
when 'AU'
ace..ace_type = MsDtypAceType::SYSTEM_AUDIT_ACE_TYPE
when 'OU'
ace..ace_type = MsDtypAceType::SYSTEM_AUDIT_OBJECT_ACE_TYPE
when 'AL', 'OL', 'ML', 'XA', 'SD', 'RA', 'SP', 'XU', 'ZA', 'TL', 'FL'
raise SDDLParseError.new('unsupported ACE type: ' + ace_type)
else
raise SDDLParseError.new('unknown ACE type: ' + ace_type)
end
ace_flags.split(/(CI|OI|NP|IO|ID|SA|FA|TP|CR)/).each do |flag|
case flag
when 'CI'
ace..ace_flags.container_inherit_ace = true
when 'OI'
ace..ace_flags.object_inherit_ace = true
when 'NP'
ace..ace_flags.no_propagate_inherit_ace = true
when 'IO'
ace..ace_flags.inherit_only_ace = true
when 'ID'
ace..ace_flags.inherited_ace = true
when 'SA'
ace..ace_flags.successful_access_ace_flag = true
when 'FA'
ace..ace_flags.failed_access_ace_flag = true
when 'TP'
raise SDDLParseError.new('unsupported ACE flag: TP')
when 'CR'
ace..ace_flags.critical_ace_flag = true
when ''
else
raise SDDLParseError.new('unknown ACE flag: ' + flag)
end
end
ace.body.access_mask = MsDtypAccessMask.from_sddl_text(rights)
unless object_guid.blank?
begin
guid = MsDtypGuid.new(object_guid)
rescue StandardError
raise SDDLParseError.new('invalid object GUID: ' + object_guid)
end
unless ace.body.respond_to?('object_type=')
raise SDDLParseError.new('setting object type for incompatible ACE type')
end
ace.body.flags.ace_object_type_present = true
ace.body.object_type = guid
end
unless inherit_object_guid.blank?
begin
guid = MsDtypGuid.new(inherit_object_guid)
rescue StandardError
raise SDDLParseError.new('invalid inherited object GUID: ' + inherit_object_guid)
end
unless ace.body.respond_to?('inherited_object_type=')
raise SDDLParseError.new('setting inherited object type for incompatible ACE type')
end
ace.body.flags.ace_inherited_object_type_present = true
ace.body.inherited_object_type = guid
end
unless account_sid.blank?
ace.body.sid = MsDtypSid.from_sddl_text(account_sid, domain_sid: domain_sid)
end
unless resource_attribute.blank?
raise SDDLParseError.new('unsupported resource attribute: ' + resource_attribute)
end
ace
end
|