diff --git a/src/CommonLib/Cache.cs b/src/CommonLib/Cache.cs index 5a185437..722ed031 100644 --- a/src/CommonLib/Cache.cs +++ b/src/CommonLib/Cache.cs @@ -4,29 +4,29 @@ namespace SharpHoundCommonLib { + [DataContract] public class Cache { - [DataMember]private ConcurrentDictionary _globalCatalogCache; + private Cache() + { + ValueToIdCache = new ConcurrentDictionary(); + IdToTypeCache = new ConcurrentDictionary(); + GlobalCatalogCache = new ConcurrentDictionary(); + MachineSidCache = new ConcurrentDictionary(); + SIDToDomainCache = new ConcurrentDictionary(); + } - [DataMember]private ConcurrentDictionary _idToTypeCache; + [DataMember] public ConcurrentDictionary GlobalCatalogCache { get; private set; } - [DataMember]private ConcurrentDictionary _machineSidCache; + [DataMember] public ConcurrentDictionary IdToTypeCache { get; private set; } - [DataMember]private ConcurrentDictionary _sidToDomainCache; + [DataMember] public ConcurrentDictionary MachineSidCache { get; private set; } - [DataMember]private ConcurrentDictionary _valueToIDCache; + [DataMember] public ConcurrentDictionary SIDToDomainCache { get; private set; } - private Cache() - { - _valueToIDCache = new ConcurrentDictionary(); - _idToTypeCache = new ConcurrentDictionary(); - _globalCatalogCache = new ConcurrentDictionary(); - _machineSidCache = new ConcurrentDictionary(); - _sidToDomainCache = new ConcurrentDictionary(); - } + [DataMember] public ConcurrentDictionary ValueToIdCache { get; private set; } - [IgnoreDataMember] - private static Cache CacheInstance { get; set; } + [IgnoreDataMember] private static Cache CacheInstance { get; set; } /// /// Add a SID to/from Domain mapping to the cache @@ -35,7 +35,7 @@ private Cache() /// internal static void AddSidToDomain(string key, string value) { - CacheInstance?._sidToDomainCache.TryAdd(key, value); + CacheInstance?.SIDToDomainCache.TryAdd(key, value); } /// @@ -46,7 +46,7 @@ internal static void AddSidToDomain(string key, string value) /// internal static bool GetDomainSidMapping(string key, out string value) { - if (CacheInstance != null) return CacheInstance._machineSidCache.TryGetValue(key, out value); + if (CacheInstance != null) return CacheInstance.MachineSidCache.TryGetValue(key, out value); value = null; return false; } @@ -58,46 +58,46 @@ internal static bool GetDomainSidMapping(string key, out string value) /// internal static void AddMachineSid(string key, string value) { - CacheInstance?._machineSidCache.TryAdd(key, value); + CacheInstance?.MachineSidCache.TryAdd(key, value); } internal static bool GetMachineSid(string key, out string value) { - if (CacheInstance != null) return CacheInstance._machineSidCache.TryGetValue(key, out value); + if (CacheInstance != null) return CacheInstance.MachineSidCache.TryGetValue(key, out value); value = null; return false; } internal static void AddConvertedValue(string key, string value) { - CacheInstance?._valueToIDCache.TryAdd(key, value); + CacheInstance?.ValueToIdCache.TryAdd(key, value); } internal static void AddPrefixedValue(string key, string domain, string value) { - CacheInstance?._valueToIDCache.TryAdd(GetPrefixKey(key, domain), value); + CacheInstance?.ValueToIdCache.TryAdd(GetPrefixKey(key, domain), value); } internal static void AddType(string key, Label value) { - CacheInstance?._idToTypeCache.TryAdd(key, value); + CacheInstance?.IdToTypeCache.TryAdd(key, value); } internal static void AddGCCache(string key, string[] value) { - CacheInstance?._globalCatalogCache?.TryAdd(key, value); + CacheInstance?.GlobalCatalogCache?.TryAdd(key, value); } internal static bool GetGCCache(string key, out string[] value) { - if (CacheInstance != null) return CacheInstance._globalCatalogCache.TryGetValue(key, out value); + if (CacheInstance != null) return CacheInstance.GlobalCatalogCache.TryGetValue(key, out value); value = null; return false; } internal static bool GetConvertedValue(string key, out string value) { - if (CacheInstance != null) return CacheInstance._valueToIDCache.TryGetValue(key, out value); + if (CacheInstance != null) return CacheInstance.ValueToIdCache.TryGetValue(key, out value); value = null; return false; } @@ -105,14 +105,14 @@ internal static bool GetConvertedValue(string key, out string value) internal static bool GetPrefixedValue(string key, string domain, out string value) { if (CacheInstance != null) - return CacheInstance._valueToIDCache.TryGetValue(GetPrefixKey(key, domain), out value); + return CacheInstance.ValueToIdCache.TryGetValue(GetPrefixKey(key, domain), out value); value = null; return false; } internal static bool GetIDType(string key, out Label value) { - if (CacheInstance != null) return CacheInstance._idToTypeCache.TryGetValue(key, out value); + if (CacheInstance != null) return CacheInstance.IdToTypeCache.TryGetValue(key, out value); value = Label.Base; return false; } @@ -123,7 +123,7 @@ private static string GetPrefixKey(string key, string domain) } /// - /// Creates a new empty cache instance + /// Creates a new empty cache instance /// /// public static Cache CreateNewCache() @@ -132,7 +132,7 @@ public static Cache CreateNewCache() } /// - /// Sets the cache instance being used by the common library + /// Sets the cache instance being used by the common library /// /// public static void SetCacheInstance(Cache cache) @@ -142,7 +142,7 @@ public static void SetCacheInstance(Cache cache) } /// - /// Gets stats from the currently loaded cache + /// Gets stats from the currently loaded cache /// /// public string GetCacheStats() @@ -150,16 +150,16 @@ public string GetCacheStats() try { return - $"{_idToTypeCache.Count} ID to type mappings.\n {_valueToIDCache.Count} name to SID mappings.\n {_machineSidCache.Count} machine sid mappings.\n {_sidToDomainCache.Count} sid to domain mappings.\n {_globalCatalogCache.Count} global catalog mappings."; + $"{IdToTypeCache.Count} ID to type mappings.\n {ValueToIdCache.Count} name to SID mappings.\n {MachineSidCache.Count} machine sid mappings.\n {SIDToDomainCache.Count} sid to domain mappings.\n {GlobalCatalogCache.Count} global catalog mappings."; } catch { return ""; } } - + /// - /// Returns the currently loaded cache instance + /// Returns the currently loaded cache instance /// /// public static Cache GetCacheInstance() @@ -170,11 +170,11 @@ public static Cache GetCacheInstance() private static void CreateMissingDictionaries() { CacheInstance ??= new Cache(); - CacheInstance._idToTypeCache ??= new ConcurrentDictionary(); - CacheInstance._globalCatalogCache ??= new ConcurrentDictionary(); - CacheInstance._machineSidCache ??= new ConcurrentDictionary(); - CacheInstance._sidToDomainCache ??= new ConcurrentDictionary(); - CacheInstance._valueToIDCache ??= new ConcurrentDictionary(); + CacheInstance.IdToTypeCache ??= new ConcurrentDictionary(); + CacheInstance.GlobalCatalogCache ??= new ConcurrentDictionary(); + CacheInstance.MachineSidCache ??= new ConcurrentDictionary(); + CacheInstance.SIDToDomainCache ??= new ConcurrentDictionary(); + CacheInstance.ValueToIdCache ??= new ConcurrentDictionary(); } } } \ No newline at end of file diff --git a/src/CommonLib/LDAPProperties.cs b/src/CommonLib/LDAPProperties.cs index ea09e266..27a894b5 100644 --- a/src/CommonLib/LDAPProperties.cs +++ b/src/CommonLib/LDAPProperties.cs @@ -45,5 +45,6 @@ public class LDAPProperties public const string UnixUserPassword = "unixuserpassword"; public const string UnicodePassword = "unicodepwd"; public const string MsSFU30Password = "msSFU30Password"; + public const string ScriptPath = "scriptpath"; } } \ No newline at end of file diff --git a/src/CommonLib/OutputTypes/MetaTag.cs b/src/CommonLib/OutputTypes/MetaTag.cs index c243c3fd..5541a1cd 100644 --- a/src/CommonLib/OutputTypes/MetaTag.cs +++ b/src/CommonLib/OutputTypes/MetaTag.cs @@ -2,6 +2,7 @@ namespace SharpHoundCommonLib.OutputTypes { + [DataContract] public class MetaTag { [DataMember(Name="methods")] public long CollectionMethods { get; set; } diff --git a/src/CommonLib/Processors/LDAPPropertyProcessor.cs b/src/CommonLib/Processors/LDAPPropertyProcessor.cs index 5ce3c10f..bdb0028d 100644 --- a/src/CommonLib/Processors/LDAPPropertyProcessor.cs +++ b/src/CommonLib/Processors/LDAPPropertyProcessor.cs @@ -224,6 +224,7 @@ public async Task ReadUserProperties(ISearchResultEntry entry) props.Add("unixpassword", entry.GetProperty(LDAPProperties.UnixUserPassword)); props.Add("unicodepassword", entry.GetProperty(LDAPProperties.UnicodePassword)); props.Add("sfupassword", entry.GetProperty(LDAPProperties.MsSFU30Password)); + props.Add("logonscript", entry.GetProperty(LDAPProperties.ScriptPath)); var ac = entry.GetProperty(LDAPProperties.AdminCount); if (ac != null) @@ -385,7 +386,7 @@ public async Task ReadComputerProperties(ISearchResultEntry /// format using a best guess /// /// - private static Dictionary ParseAllProperties(ISearchResultEntry entry) + public Dictionary ParseAllProperties(ISearchResultEntry entry) { var flag = IsTextUnicodeFlags.IS_TEXT_UNICODE_STATISTICS; var props = new Dictionary(); diff --git a/src/CommonLib/SharpHoundCommonLib.csproj b/src/CommonLib/SharpHoundCommonLib.csproj index ef2f4b95..b06f7eb3 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 - 2.0.15 + 2.1.0 SharpHoundCommonLib SharpHoundCommonLib