< 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:108
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 InheritanceFlags InheritanceFlags => _inner.InheritanceFlags;
 19
 20        public virtual AccessControlType AccessControlType()
 21        {
 22            return _inner.AccessControlType;
 23        }
 24
 25        public virtual string IdentityReference()
 26        {
 27            return _inner.IdentityReference.Value;
 28        }
 29
 30        public virtual bool IsInherited()
 31        {
 32            return _inner.IsInherited;
 33        }
 34
 35        public virtual string InheritedObjectType() {
 36            return _inner.InheritedObjectType.ToString();
 37        }
 38
 39        public virtual bool IsAceInheritedFrom(string guid)
 40        {
 41            //Check if the ace is inherited
 42            var isInherited = _inner.IsInherited;
 43
 44            //The inheritedobjecttype needs to match the guid of the object type being enumerated or the guid for All
 45            var inheritedType = _inner.InheritedObjectType.ToString();
 46            isInherited = isInherited && (inheritedType == ACEGuids.AllGuid || inheritedType == guid);
 47
 48            //Special case for Exchange
 49            //If the ACE is not Inherited and is not an inherit-only ace, then it's set by exchange for reasons
 50            if (!isInherited &&
 51                (_inner.PropagationFlags & PropagationFlags.InheritOnly) != PropagationFlags.InheritOnly &&
 52                !_inner.IsInherited)
 53                isInherited = true;
 54
 55            return isInherited;
 56        }
 57
 58        public virtual ActiveDirectoryRights ActiveDirectoryRights()
 59        {
 60            return _inner.ActiveDirectoryRights;
 61        }
 62
 63        public virtual Guid ObjectType()
 64        {
 65            return _inner.ObjectType;
 66        }
 67    }
 68
 69    public class ActiveDirectorySecurityDescriptor
 70    {
 71        private readonly ActiveDirectorySecurity _sd;
 72
 3573        public ActiveDirectorySecurityDescriptor(ActiveDirectorySecurity sd)
 3574        {
 3575            _sd = sd;
 3576        }
 77
 78        public virtual bool AreAccessRulesProtected()
 079        {
 080            return _sd.AreAccessRulesProtected;
 081        }
 82
 83        public virtual List<ActiveDirectoryRuleDescriptor> GetAccessRules(bool includeExplicit, bool includeInherited,
 84            Type targetType)
 185        {
 186            var result = new List<ActiveDirectoryRuleDescriptor>();
 4587            foreach (ActiveDirectoryAccessRule ace in _sd.GetAccessRules(includeExplicit, includeInherited, targetType))
 2188                result.Add(new ActiveDirectoryRuleDescriptor(ace));
 89
 190            return result;
 191        }
 92
 93        public virtual void SetSecurityDescriptorBinaryForm(byte[] binaryForm)
 194        {
 195            _sd.SetSecurityDescriptorBinaryForm(binaryForm);
 196        }
 97
 98        public virtual void SetSecurityDescriptorBinaryForm(byte[] binaryForm, AccessControlSections type)
 099        {
 0100            _sd.SetSecurityDescriptorBinaryForm(binaryForm, type);
 0101        }
 102
 103        public virtual string GetOwner(Type targetType)
 1104        {
 1105            return _sd.GetOwner(targetType).Value;
 1106        }
 107    }
 108}