< Summary

Class:SharpHoundCommonLib.LdapProducerQueryGenerator
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\LdapProducerQueryGenerator.cs
Covered lines:0
Uncovered lines:108
Coverable lines:108
Total lines:155
Line coverage:0% (0 of 108)
Covered branches:0
Total branches:58
Branch coverage:0% (0 of 58)

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GenerateDefaultPartitionParameters(...)0%3800%
GenerateConfigurationPartitionParameters(...)0%2000%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using SharpHoundCommonLib.Enums;
 4using SharpHoundCommonLib.LDAPQueries;
 5
 6namespace SharpHoundCommonLib;
 7
 8public class LdapProducerQueryGenerator {
 09    public static GeneratedLdapParameters GenerateDefaultPartitionParameters(CollectionMethod methods) {
 010        var filter = new LdapFilter();
 011        var properties = new List<string>();
 12
 013        properties.AddRange(CommonProperties.BaseQueryProps);
 014        properties.AddRange(CommonProperties.TypeResolutionProps);
 15
 016        if (methods.HasFlag(CollectionMethod.ObjectProps) || methods.HasFlag(CollectionMethod.ACL) || methods.HasFlag(Co
 017            filter = filter.AddComputers().AddDomains().AddUsers().AddContainers().AddGPOs().AddOUs().AddGroups();
 18
 019            if (methods.HasFlag(CollectionMethod.Container)) {
 020                properties.AddRange(CommonProperties.ContainerProps);
 021            }
 22
 023            if (methods.HasFlag(CollectionMethod.Group)) {
 024                properties.AddRange(CommonProperties.GroupResolutionProps);
 025            }
 26
 027            if (methods.HasFlag(CollectionMethod.ACL)) {
 028                properties.AddRange(CommonProperties.ACLProps);
 029            }
 30
 031            if (methods.HasFlag(CollectionMethod.ObjectProps)) {
 032                properties.AddRange(CommonProperties.ObjectPropsProps);
 033            }
 34
 035            if (methods.IsComputerCollectionSet()) {
 036                properties.AddRange(CommonProperties.ComputerMethodProps);
 037            }
 38
 039            if (methods.HasFlag(CollectionMethod.Trusts)) {
 040                properties.AddRange(CommonProperties.DomainTrustProps);
 041            }
 42
 043            if (methods.HasFlag(CollectionMethod.GPOLocalGroup))
 044                properties.AddRange(CommonProperties.GPOLocalGroupProps);
 45
 046            if (methods.HasFlag(CollectionMethod.SPNTargets))
 047                properties.AddRange(CommonProperties.SPNTargetProps);
 48
 049            if (methods.HasFlag(CollectionMethod.DCRegistry))
 050                properties.AddRange(CommonProperties.ComputerMethodProps);
 51
 052            if (methods.HasFlag(CollectionMethod.SPNTargets)) {
 053                properties.AddRange(CommonProperties.SPNTargetProps);
 054            }
 55
 056            return new GeneratedLdapParameters {
 057                Filter = filter,
 058                Attributes = properties.Distinct().ToArray()
 059            };
 60        }
 61
 062        if (methods.HasFlag(CollectionMethod.Group)) {
 063            filter = filter.AddGroups();
 064            properties.AddRange(CommonProperties.GroupResolutionProps);
 065        }
 66
 067        if (methods.IsComputerCollectionSet()) {
 068            filter = filter.AddComputers();
 069            properties.AddRange(CommonProperties.ComputerMethodProps);
 070        }
 71
 072        if (methods.HasFlag(CollectionMethod.Trusts)) {
 073            filter = filter.AddDomains();
 074            properties.AddRange(CommonProperties.ComputerMethodProps);
 075        }
 76
 077        if (methods.HasFlag(CollectionMethod.SPNTargets)) {
 078            filter = filter.AddUsers(CommonFilters.NeedsSPN);
 079            properties.AddRange(CommonProperties.SPNTargetProps);
 080        }
 81
 082        if (methods.HasFlag(CollectionMethod.GPOLocalGroup)) {
 083            filter = filter.AddOUs();
 084            properties.AddRange(CommonProperties.GPOLocalGroupProps);
 085        }
 86
 087        if (methods.HasFlag(CollectionMethod.DCRegistry)) {
 088            filter = filter.AddComputers(CommonFilters.DomainControllers);
 089            properties.AddRange(CommonProperties.ComputerMethodProps);
 090        }
 91
 092        return new GeneratedLdapParameters {
 093            Filter = filter,
 094            Attributes = properties.Distinct().ToArray()
 095        };
 096    }
 97
 098    public static GeneratedLdapParameters GenerateConfigurationPartitionParameters(CollectionMethod methods) {
 099        var filter = new LdapFilter();
 0100        var properties = new List<string>();
 101
 0102        properties.AddRange(CommonProperties.BaseQueryProps);
 0103        properties.AddRange(CommonProperties.TypeResolutionProps);
 104
 0105        if (methods.HasFlag(CollectionMethod.ACL) || methods.HasFlag(CollectionMethod.ObjectProps) ||
 0106            methods.HasFlag(CollectionMethod.Container) || methods.HasFlag(CollectionMethod.CertServices)) {
 0107            filter = filter.AddContainers().AddConfiguration().AddCertificateTemplates().AddCertificateAuthorities()
 0108                .AddEnterpriseCertificationAuthorities().AddIssuancePolicies();
 109
 0110            if (methods.HasFlag(CollectionMethod.ObjectProps))
 0111            {
 0112                properties.AddRange(CommonProperties.ObjectPropsProps);
 0113            }
 114
 0115            if (methods.HasFlag(CollectionMethod.ACL)) {
 0116                properties.AddRange(CommonProperties.ACLProps);
 0117            }
 118
 0119            if (methods.HasFlag(CollectionMethod.Container)) {
 0120                properties.AddRange(CommonProperties.ContainerProps);
 0121            }
 122
 0123            if (methods.HasFlag(CollectionMethod.CertServices)) {
 0124                properties.AddRange(CommonProperties.CertAbuseProps);
 0125                properties.AddRange(CommonProperties.ObjectPropsProps);
 0126                properties.AddRange(CommonProperties.ContainerProps);
 0127                properties.AddRange(CommonProperties.ACLProps);
 0128            }
 129
 0130            if (methods.HasFlag(CollectionMethod.CARegistry)) {
 0131                properties.AddRange(CommonProperties.CertAbuseProps);
 0132            }
 133
 0134            return new GeneratedLdapParameters {
 0135                Filter = filter,
 0136                Attributes = properties.Distinct().ToArray()
 0137            };
 138        }
 139
 0140        if (methods.HasFlag(CollectionMethod.CARegistry)) {
 0141            filter = filter.AddEnterpriseCertificationAuthorities();
 0142            properties.AddRange(CommonProperties.CertAbuseProps);
 0143        }
 144
 0145        return new GeneratedLdapParameters {
 0146            Filter = filter,
 0147            Attributes = properties.Distinct().ToArray()
 0148        };
 0149    }
 150}
 151
 152public class GeneratedLdapParameters {
 153    public string[] Attributes { get; set; }
 154    public LdapFilter Filter { get; set; }
 155}