Skip to content

Commit

Permalink
fix: feedback + swap to HashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 committed Jul 26, 2024
1 parent 3e11899 commit 8818f66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/CommonLib/Enums/LDAPProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ public static class LDAPProperties
public const string ServerName = "servername";
public const string OU = "ou";
public const string ProfilePath = "profilepath";
public const string DSASignature = "dsasignature";
}
}
14 changes: 4 additions & 10 deletions src/CommonLib/Processors/LdapPropertyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

namespace SharpHoundCommonLib.Processors {
public class LdapPropertyProcessor {
private static readonly string[] ReservedAttributes = CommonProperties.TypeResolutionProps
private static readonly HashSet<string> ReservedAttributes = new HashSet<string>(CommonProperties.TypeResolutionProps
.Concat(CommonProperties.BaseQueryProps).Concat(CommonProperties.GroupResolutionProps)
.Concat(CommonProperties.ComputerMethodProps).Concat(CommonProperties.ACLProps)
.Concat(CommonProperties.ObjectPropsProps).Concat(CommonProperties.ContainerProps)
.Concat(CommonProperties.SPNTargetProps).Concat(CommonProperties.DomainTrustProps)
.Concat(CommonProperties.GPOLocalGroupProps).Concat(CommonProperties.CertAbuseProps).ToArray();
.Concat(CommonProperties.GPOLocalGroupProps).Concat(CommonProperties.CertAbuseProps)
.Concat(new string[] { LDAPProperties.DSASignature }));

private readonly ILdapUtils _utils;

Expand Down Expand Up @@ -521,15 +522,8 @@ public async Task<IssuancePolicyProperties> ReadIssuancePolicyProperties(IDirect
public Dictionary<string, object> ParseAllProperties(IDirectoryObject entry) {
var props = new Dictionary<string, object>();

var type = typeof(LDAPProperties);
var reserved = new HashSet<string>(type.GetFields(BindingFlags.Static | BindingFlags.Public).Select(x => x.GetValue(null).ToString()));
_ = reserved.Add("dsasignature");
foreach (var reservedAttr in ReservedAttributes) {
reserved.Add(reservedAttr.ToLower());
}

foreach (var property in entry.PropertyNames()) {
if (reserved.Contains(property.ToLower()))
if (ReservedAttributes.Contains(property, StringComparer.OrdinalIgnoreCase))
continue;

var collCount = entry.PropertyCount(property);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/LdapPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ public void LDAPPropertyProcessor_ParseAllProperties()
{"name", "[email protected]"},
{"domainsid", "S-1-5-21-2697957641-2271029196-387917394"},
{"whencreated", 1683986131},
{"dsasignature", "jkr"}
{LDAPProperties.DSASignature, "jkr"}
}, "", "2F9F3630-F46A-49BF-B186-6629994EBCF9");

var processor = new LdapPropertyProcessor(new MockLdapUtils());
Expand All @@ -866,7 +866,7 @@ public void LDAPPropertyProcessor_ParseAllProperties()
Assert.DoesNotContain("description", keys);
Assert.DoesNotContain("whencreated", keys);
Assert.DoesNotContain("name", keys);
Assert.DoesNotContain("dsasignature", keys);
Assert.DoesNotContain(LDAPProperties.DSASignature, keys);

Assert.Contains("domainsid", keys);
Assert.Contains("domain", keys);
Expand Down

0 comments on commit 8818f66

Please sign in to comment.