Skip to content

Commit

Permalink
Merge pull request #83 from BloodHoundAD/adcs-cert-services-collectio…
Browse files Browse the repository at this point in the history
…n-method

chore: add CertServices to collection methods
  • Loading branch information
elikmiller authored Nov 22, 2023
2 parents f06408b + 37438c1 commit df41c18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/CommonLib/Enums/CollectionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public enum ResolvedCollectionMethod
UserRights = 1 << 15,
CARegistry = 1 << 16,
DCRegistry = 1 << 17,
CertServices = 1 << 18,
LocalGroups = DCOM | RDP | LocalAdmin | PSRemote,
ComputerOnly = LocalGroups | Session | UserRights | CARegistry | DCRegistry,
DCOnly = ACL | Container | Group | ObjectProps | Trusts | GPOLocalGroup,
Default = Group | Session | Trusts | ACL | ObjectProps | LocalGroups | SPNTargets | Container,
DCOnly = ACL | Container | Group | ObjectProps | Trusts | GPOLocalGroup | CertServices,
Default = Group | Session | Trusts | ACL | ObjectProps | LocalGroups | SPNTargets | Container | CertServices,
All = Default | LoggedOn | GPOLocalGroup | UserRights | CARegistry | DCRegistry
}
}
23 changes: 15 additions & 8 deletions src/CommonLib/LDAPQueries/LDAPFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,23 @@ public LDAPFilter AddFilter(string filter, bool enforce)
/// <returns></returns>
public string GetFilter()
{
var temp = string.Join("", _filterParts.ToArray());
if (_filterParts.Count == 1)
temp = _filterParts[0];
else if (_filterParts.Count > 1)
temp = $"(|{temp})";

var mandatory = string.Join("", _mandatory.ToArray());
temp = _mandatory.Count > 0 ? $"(&{temp}{mandatory})" : temp;
var filterPartList = _filterParts.ToArray().Distinct();
var mandatoryList = _mandatory.ToArray().Distinct();

return temp;
var filterPartsExceptMandatory = filterPartList.Except(mandatoryList).ToList();

var filterPartsDistinct = string.Join("", filterPartsExceptMandatory);
var mandatoryDistinct = string.Join("", mandatoryList);

if (filterPartsExceptMandatory.Count == 1)
filterPartsDistinct = filterPartsExceptMandatory[0];
else if (filterPartsExceptMandatory.Count > 1)
filterPartsDistinct = $"(|{filterPartsDistinct})";

filterPartsDistinct = _mandatory.Count > 0 ? $"(&{filterPartsDistinct}{mandatoryDistinct})" : filterPartsDistinct;

return filterPartsDistinct;
}

public IEnumerable<string> GetFilterList()
Expand Down

0 comments on commit df41c18

Please sign in to comment.