< Summary

Class:SharpHoundCommonLib.ActiveDirectoryRuleDescriptor
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\SecurityDescriptor.cs
Covered lines:32
Uncovered lines:1
Coverable lines:33
Total lines:108
Line coverage:96.9% (32 of 33)
Covered branches:10
Total branches:10
Branch coverage:100% (10 of 10)

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%10100%
AccessControlType()100%10100%
IdentityReference()100%10100%
IsInherited()100%10100%
InheritedObjectType()100%10100%
IsAceInheritedFrom(...)100%100100%
ActiveDirectoryRights()100%10100%
ObjectType()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
 4813        public ActiveDirectoryRuleDescriptor(ActiveDirectoryAccessRule inner)
 4814        {
 4815            _inner = inner;
 4816        }
 17
 018        public virtual InheritanceFlags InheritanceFlags => _inner.InheritanceFlags;
 19
 20        public virtual AccessControlType AccessControlType()
 2121        {
 2122            return _inner.AccessControlType;
 2123        }
 24
 25        public virtual string IdentityReference()
 1626        {
 1627            return _inner.IdentityReference.Value;
 1628        }
 29
 30        public virtual bool IsInherited()
 1231        {
 1232            return _inner.IsInherited;
 1233        }
 34
 535        public virtual string InheritedObjectType() {
 536            return _inner.InheritedObjectType.ToString();
 537        }
 38
 39        public virtual bool IsAceInheritedFrom(string guid)
 2140        {
 41            //Check if the ace is inherited
 2142            var isInherited = _inner.IsInherited;
 43
 44            //The inheritedobjecttype needs to match the guid of the object type being enumerated or the guid for All
 2145            var inheritedType = _inner.InheritedObjectType.ToString();
 2146            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
 2150            if (!isInherited &&
 2151                (_inner.PropagationFlags & PropagationFlags.InheritOnly) != PropagationFlags.InheritOnly &&
 2152                !_inner.IsInherited)
 953                isInherited = true;
 54
 2155            return isInherited;
 2156        }
 57
 58        public virtual ActiveDirectoryRights ActiveDirectoryRights()
 1259        {
 1260            return _inner.ActiveDirectoryRights;
 1261        }
 62
 63        public virtual Guid ObjectType()
 1264        {
 1265            return _inner.ObjectType;
 1266        }
 67    }
 68
 69    public class ActiveDirectorySecurityDescriptor
 70    {
 71        private readonly ActiveDirectorySecurity _sd;
 72
 73        public ActiveDirectorySecurityDescriptor(ActiveDirectorySecurity sd)
 74        {
 75            _sd = sd;
 76        }
 77
 78        public virtual bool AreAccessRulesProtected()
 79        {
 80            return _sd.AreAccessRulesProtected;
 81        }
 82
 83        public virtual List<ActiveDirectoryRuleDescriptor> GetAccessRules(bool includeExplicit, bool includeInherited,
 84            Type targetType)
 85        {
 86            var result = new List<ActiveDirectoryRuleDescriptor>();
 87            foreach (ActiveDirectoryAccessRule ace in _sd.GetAccessRules(includeExplicit, includeInherited, targetType))
 88                result.Add(new ActiveDirectoryRuleDescriptor(ace));
 89
 90            return result;
 91        }
 92
 93        public virtual void SetSecurityDescriptorBinaryForm(byte[] binaryForm)
 94        {
 95            _sd.SetSecurityDescriptorBinaryForm(binaryForm);
 96        }
 97
 98        public virtual void SetSecurityDescriptorBinaryForm(byte[] binaryForm, AccessControlSections type)
 99        {
 100            _sd.SetSecurityDescriptorBinaryForm(binaryForm, type);
 101        }
 102
 103        public virtual string GetOwner(Type targetType)
 104        {
 105            return _sd.GetOwner(targetType).Value;
 106        }
 107    }
 108}