From 1f5e96a5001bddc7a95b300348b01887577c16c9 Mon Sep 17 00:00:00 2001 From: Rohan Vazarkar Date: Wed, 31 Jul 2024 09:46:34 -0400 Subject: [PATCH] fix: exception when adding keys (#149) fix: couple missing properties chore: bump version --- src/CommonLib/LdapQueries/CommonProperties.cs | 2 +- src/CommonLib/LdapUtils.cs | 19 ++++++++----------- .../Processors/LdapPropertyProcessor.cs | 1 + src/CommonLib/SharpHoundCommonLib.csproj | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/CommonLib/LdapQueries/CommonProperties.cs b/src/CommonLib/LdapQueries/CommonProperties.cs index 54a59549..7362f1e5 100644 --- a/src/CommonLib/LdapQueries/CommonProperties.cs +++ b/src/CommonLib/LdapQueries/CommonProperties.cs @@ -55,7 +55,7 @@ public static class CommonProperties LDAPProperties.GroupPolicyOptions, LDAPProperties.AllowedToDelegateTo, LDAPProperties.AllowedToActOnBehalfOfOtherIdentity, LDAPProperties.WhenCreated, LDAPProperties.HostServiceAccount, LDAPProperties.UnixUserPassword, LDAPProperties.MsSFU30Password, - LDAPProperties.UnicodePassword + LDAPProperties.UnicodePassword, LDAPProperties.ProfilePath, LDAPProperties.ScriptPath }; public static readonly string[] ContainerProps = diff --git a/src/CommonLib/LdapUtils.cs b/src/CommonLib/LdapUtils.cs index 2be64cd5..57bdf4b9 100644 --- a/src/CommonLib/LdapUtils.cs +++ b/src/CommonLib/LdapUtils.cs @@ -1402,22 +1402,19 @@ public async IAsyncEnumerable GetWellKnownPrincipalOutput() { } private async IAsyncEnumerable GetEnterpriseDCGroups() { - var grouped = new Dictionary>(); - var forestSidToName = new Dictionary(); + var grouped = new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); + var forestSidToName = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); foreach (var domainSid in DomainControllers.GroupBy(x => new SecurityIdentifier(x.Key).AccountDomainSid.Value)) { if (await GetDomainNameFromSid(domainSid.Key) is (true, var domainName) && await GetForest(domainName) is (true, var forestName) && await GetDomainSidFromDomainName(forestName) is (true, var forestDomainSid)) { - forestSidToName.Add(forestDomainSid, forestName); - if (grouped.ContainsKey(forestDomainSid)) { - foreach (var k in domainSid) { - grouped[forestDomainSid].Add(k.Key); - } - } else { + forestSidToName.TryAdd(forestDomainSid, forestName); + if (!grouped.ContainsKey(forestDomainSid)) { grouped[forestDomainSid] = new List(); - foreach (var k in domainSid) { - grouped[forestDomainSid].Add(k.Key); - } + } + + foreach (var k in domainSid) { + grouped[forestDomainSid].Add(k.Key); } } } diff --git a/src/CommonLib/Processors/LdapPropertyProcessor.cs b/src/CommonLib/Processors/LdapPropertyProcessor.cs index b4b495e3..0075bf14 100644 --- a/src/CommonLib/Processors/LdapPropertyProcessor.cs +++ b/src/CommonLib/Processors/LdapPropertyProcessor.cs @@ -212,6 +212,7 @@ public async Task ReadUserProperties(IDirectoryObject entry, str props.Add("unicodepassword", entry.GetProperty(LDAPProperties.UnicodePassword)); props.Add("sfupassword", entry.GetProperty(LDAPProperties.MsSFU30Password)); props.Add("logonscript", entry.GetProperty(LDAPProperties.ScriptPath)); + props.Add("profilepath", entry.GetProperty(LDAPProperties.ProfilePath)); entry.TryGetLongProperty(LDAPProperties.AdminCount, out var ac); props.Add("admincount", ac != 0); diff --git a/src/CommonLib/SharpHoundCommonLib.csproj b/src/CommonLib/SharpHoundCommonLib.csproj index 0888bb1b..b69d200e 100644 --- a/src/CommonLib/SharpHoundCommonLib.csproj +++ b/src/CommonLib/SharpHoundCommonLib.csproj @@ -9,7 +9,7 @@ Common library for C# BloodHound enumeration tasks GPL-3.0-only https://github.com/BloodHoundAD/SharpHoundCommon - 4.0.3 + 4.0.4 SharpHoundCommonLib SharpHoundCommonLib