< Summary

Class:SharpHoundCommonLib.ActiveDirectorySecurityDescriptor
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\SecurityDescriptor.cs
Covered lines:16
Uncovered lines:6
Coverable lines:22
Total lines:102
Line coverage:72.7% (16 of 22)
Covered branches:2
Total branches:2
Branch coverage:100% (2 of 2)

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%10100%
AreAccessRulesProtected()100%100%
GetAccessRules(...)100%20100%
SetSecurityDescriptorBinaryForm(...)100%10100%
SetSecurityDescriptorBinaryForm(...)100%100%
GetOwner(...)100%10100%

File(s)

D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\SecurityDescriptor.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.DirectoryServices;
 4using System.Security.AccessControl;
 5using SharpHoundCommonLib.Processors;
 6
 7namespace SharpHoundCommonLib
 8{
 9    public class ActiveDirectoryRuleDescriptor
 10    {
 11        private readonly ActiveDirectoryAccessRule _inner;
 12
 13        public ActiveDirectoryRuleDescriptor(ActiveDirectoryAccessRule inner)
 14        {
 15            _inner = inner;
 16        }
 17
 18        public virtual AccessControlType AccessControlType()
 19        {
 20            return _inner.AccessControlType;
 21        }
 22
 23        public virtual string IdentityReference()
 24        {
 25            return _inner.IdentityReference.Value;
 26        }
 27
 28        public virtual bool IsInherited()
 29        {
 30            return _inner.IsInherited;
 31        }
 32
 33        public virtual bool IsAceInheritedFrom(string guid)
 34        {
 35            //Check if the ace is inherited
 36            var isInherited = _inner.IsInherited;
 37
 38            //The inheritedobjecttype needs to match the guid of the object type being enumerated or the guid for All
 39            var inheritedType = _inner.InheritedObjectType.ToString();
 40            isInherited = isInherited && (inheritedType == ACEGuids.AllGuid || inheritedType == guid);
 41
 42            //Special case for Exchange
 43            //If the ACE is not Inherited and is not an inherit-only ace, then it's set by exchange for reasons
 44            if (!isInherited &&
 45                (_inner.PropagationFlags & PropagationFlags.InheritOnly) != PropagationFlags.InheritOnly &&
 46                !_inner.IsInherited)
 47                isInherited = true;
 48
 49            return isInherited;
 50        }
 51
 52        public virtual ActiveDirectoryRights ActiveDirectoryRights()
 53        {
 54            return _inner.ActiveDirectoryRights;
 55        }
 56
 57        public virtual Guid ObjectType()
 58        {
 59            return _inner.ObjectType;
 60        }
 61    }
 62
 63    public class ActiveDirectorySecurityDescriptor
 64    {
 65        private readonly ActiveDirectorySecurity _sd;
 66
 3167        public ActiveDirectorySecurityDescriptor(ActiveDirectorySecurity sd)
 3168        {
 3169            _sd = sd;
 3170        }
 71
 72        public virtual bool AreAccessRulesProtected()
 073        {
 074            return _sd.AreAccessRulesProtected;
 075        }
 76
 77        public virtual List<ActiveDirectoryRuleDescriptor> GetAccessRules(bool includeExplicit, bool includeInherited,
 78            Type targetType)
 379        {
 380            var result = new List<ActiveDirectoryRuleDescriptor>();
 13581            foreach (ActiveDirectoryAccessRule ace in _sd.GetAccessRules(includeExplicit, includeInherited, targetType))
 6382                result.Add(new ActiveDirectoryRuleDescriptor(ace));
 83
 384            return result;
 385        }
 86
 87        public virtual void SetSecurityDescriptorBinaryForm(byte[] binaryForm)
 388        {
 389            _sd.SetSecurityDescriptorBinaryForm(binaryForm);
 390        }
 91
 92        public virtual void SetSecurityDescriptorBinaryForm(byte[] binaryForm, AccessControlSections type)
 093        {
 094            _sd.SetSecurityDescriptorBinaryForm(binaryForm, type);
 095        }
 96
 97        public virtual string GetOwner(Type targetType)
 398        {
 399            return _sd.GetOwner(targetType).Value;
 3100        }
 101    }
 102}