Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cf59335
wip: more updates
rvazarkar Jul 18, 2022
4549ec6
feat: add scriptpath to users as logonscript
rvazarkar Jul 18, 2022
4e656e6
fix: make ParseAllProperties public
rvazarkar Jul 19, 2022
e519d87
fix: make cache members public with private set to allow serializatio…
rvazarkar Jul 19, 2022
396b98b
fix: add DataContract to MetaTag
rvazarkar Jul 20, 2022
3913099
Merge branch '4.2' into rpc_lib
rvazarkar Jul 20, 2022
033f4bb
wip: commit for wip
rvazarkar Aug 1, 2022
f4e0ee7
wip: commit for wip
rvazarkar Aug 15, 2022
9056cec
wip: commit for wip
rvazarkar Aug 22, 2022
799c057
feat: finish new URA processor + integrate RPC lib
rvazarkar Aug 25, 2022
fd716fc
chore: add event delegate to SessionProcessor
rvazarkar Aug 26, 2022
b55afde
Merge remote-tracking branch 'origin/user_assignment_rights' into rpc…
rvazarkar Sep 29, 2022
1571e09
chore: some small fixes
rvazarkar Sep 30, 2022
4559291
chore: remove RPCServer and associated native methods in favor of RPC…
rvazarkar Sep 30, 2022
c233c43
chore: fixed consistency for logwarning yield break
superlinkx Sep 30, 2022
73664ae
feat: refactor remaining API calls into RPCLib. Update tests.
rvazarkar Oct 3, 2022
5e96c4a
Merge remote-tracking branch 'origin/rpc_lib' into rpc_lib
rvazarkar Oct 3, 2022
9e34223
chore: clean up handle earlier
rvazarkar Oct 3, 2022
b751b8e
chore: cleanup test project
rvazarkar Oct 3, 2022
5c4e173
chore: code cleanup RPC Lib
rvazarkar Oct 3, 2022
414aa53
chore: code cleanup commonlib
rvazarkar Oct 3, 2022
fb221bc
fix: add project reference
rvazarkar Oct 3, 2022
42c7dd3
chore: add UserRights collection method
rvazarkar Oct 4, 2022
fd9ea80
chore: remove GroupRid from API result
rvazarkar Oct 4, 2022
5497793
fix: fix output for local groups, and name/sid resolution
rvazarkar Oct 4, 2022
1afe482
fix: remove look-ahead memory frees that were breaking everything
rvazarkar Oct 4, 2022
10d4c20
fix: break control flow in URA processor when privilege fails
rvazarkar Oct 4, 2022
9086c65
chore: use helper func for LookupSidType
rvazarkar Oct 4, 2022
30723db
chore: remove log entry
rvazarkar Oct 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion SharpHoundCommon.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
#
#
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpHoundCommonLib", "src\CommonLib\SharpHoundCommonLib.csproj", "{88EB8B09-EB8A-4E59-BBF7-CA5374DFA9EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonLibTest", "test\unit\CommonLibTest.csproj", "{F1E060CB-58D0-42A7-9BBC-E08C6FD5DD43}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Docfx", "docfx\Docfx.csproj", "{BD8C7EB8-F357-4499-8C08-76B42F600076}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpHoundRPC", "src\SharpHoundRPC\SharpHoundRPC.csproj", "{4F06116D-88A7-4601-AB28-B48F2857D458}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,5 +27,9 @@ Global
{BD8C7EB8-F357-4499-8C08-76B42F600076}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD8C7EB8-F357-4499-8C08-76B42F600076}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD8C7EB8-F357-4499-8C08-76B42F600076}.Release|Any CPU.Build.0 = Release|Any CPU
{4F06116D-88A7-4601-AB28-B48F2857D458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F06116D-88A7-4601-AB28-B48F2857D458}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F06116D-88A7-4601-AB28-B48F2857D458}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F06116D-88A7-4601-AB28-B48F2857D458}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
74 changes: 43 additions & 31 deletions src/CommonLib/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,38 @@

namespace SharpHoundCommonLib
{
[DataContract]
public class Cache
{
[DataMember] private ConcurrentDictionary<string, string[]> _globalCatalogCache;
//Leave these here until we switch back to Newtonsoft which doesn't suck
// [DataMember]private ConcurrentDictionary<string, string[]> _globalCatalogCache;
//
// [DataMember]private ConcurrentDictionary<string, Label> _idToTypeCache;
//
// [DataMember]private ConcurrentDictionary<string, string> _machineSidCache;
//
// [DataMember]private ConcurrentDictionary<string, string> _sidToDomainCache;
//
// [DataMember]private ConcurrentDictionary<string, string> _valueToIDCache;

[DataMember] private ConcurrentDictionary<string, Label> _idToTypeCache;
private Cache()
{
ValueToIdCache = new ConcurrentDictionary<string, string>();
IdToTypeCache = new ConcurrentDictionary<string, Label>();
GlobalCatalogCache = new ConcurrentDictionary<string, string[]>();
MachineSidCache = new ConcurrentDictionary<string, string>();
SIDToDomainCache = new ConcurrentDictionary<string, string>();
}

[DataMember] private ConcurrentDictionary<string, string> _machineSidCache;
[DataMember] public ConcurrentDictionary<string, string[]> GlobalCatalogCache { get; private set; }

[DataMember] private ConcurrentDictionary<string, string> _sidToDomainCache;
[DataMember] public ConcurrentDictionary<string, Label> IdToTypeCache { get; private set; }

[DataMember] private ConcurrentDictionary<string, string> _valueToIDCache;
[DataMember] public ConcurrentDictionary<string, string> MachineSidCache { get; private set; }

private Cache()
{
_valueToIDCache = new ConcurrentDictionary<string, string>();
_idToTypeCache = new ConcurrentDictionary<string, Label>();
_globalCatalogCache = new ConcurrentDictionary<string, string[]>();
_machineSidCache = new ConcurrentDictionary<string, string>();
_sidToDomainCache = new ConcurrentDictionary<string, string>();
}
[DataMember] public ConcurrentDictionary<string, string> SIDToDomainCache { get; private set; }

[DataMember] public ConcurrentDictionary<string, string> ValueToIdCache { get; private set; }

[IgnoreDataMember] private static Cache CacheInstance { get; set; }

Expand All @@ -34,7 +46,7 @@ private Cache()
/// <param name="value"></param>
internal static void AddSidToDomain(string key, string value)
{
CacheInstance?._sidToDomainCache.TryAdd(key, value);
CacheInstance?.SIDToDomainCache.TryAdd(key, value);
}

/// <summary>
Expand All @@ -45,7 +57,7 @@ internal static void AddSidToDomain(string key, string value)
/// <returns></returns>
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;
}
Expand All @@ -57,61 +69,61 @@ internal static bool GetDomainSidMapping(string key, out string value)
/// <param name="value"></param>
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;
}

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;
}
Expand Down Expand Up @@ -149,7 +161,7 @@ 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
{
Expand All @@ -169,11 +181,11 @@ public static Cache GetCacheInstance()
private static void CreateMissingDictionaries()
{
CacheInstance ??= new Cache();
CacheInstance._idToTypeCache ??= new ConcurrentDictionary<string, Label>();
CacheInstance._globalCatalogCache ??= new ConcurrentDictionary<string, string[]>();
CacheInstance._machineSidCache ??= new ConcurrentDictionary<string, string>();
CacheInstance._sidToDomainCache ??= new ConcurrentDictionary<string, string>();
CacheInstance._valueToIDCache ??= new ConcurrentDictionary<string, string>();
CacheInstance.IdToTypeCache ??= new ConcurrentDictionary<string, Label>();
CacheInstance.GlobalCatalogCache ??= new ConcurrentDictionary<string, string[]>();
CacheInstance.MachineSidCache ??= new ConcurrentDictionary<string, string>();
CacheInstance.SIDToDomainCache ??= new ConcurrentDictionary<string, string>();
CacheInstance.ValueToIdCache ??= new ConcurrentDictionary<string, string>();
}
}
}
5 changes: 3 additions & 2 deletions src/CommonLib/Enums/CollectionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public enum ResolvedCollectionMethod
DCOM = 1 << 12,
SPNTargets = 1 << 13,
PSRemote = 1 << 14,
UserRights = 1 << 15,
LocalGroups = DCOM | RDP | LocalAdmin | PSRemote,
ComputerOnly = LocalGroups | Session,
ComputerOnly = LocalGroups | Session | UserRights,
DCOnly = ACL | Container | Group | ObjectProps | Trusts | GPOLocalGroup,
Default = Group | Session | Trusts | ACL | ObjectProps | LocalGroups | SPNTargets | Container,
All = Default | LoggedOn | GPOLocalGroup
All = Default | LoggedOn | GPOLocalGroup | UserRights
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ namespace SharpHoundCommonLib.Exceptions
{
public class LDAPQueryException : Exception
{
public LDAPQueryException() { }
public LDAPQueryException(string message) : base(message) { }
public LDAPQueryException(string message, Exception inner) : base(message, inner) { }
public LDAPQueryException()
{
}

public LDAPQueryException(string message) : base(message)
{
}

public LDAPQueryException(string message, Exception inner) : base(message, inner)
{
}
}
}
}
1 change: 1 addition & 0 deletions src/CommonLib/LDAPProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
2 changes: 1 addition & 1 deletion src/CommonLib/LDAPQueries/CommonProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class CommonProperties

public static readonly string[] BaseQueryProps =
{
"objectsid", "distiguishedname", "objectguid", "ms-mcs-admpwdexpirationtime", "isDeleted",
"objectsid", "distinguishedname", "objectguid", "ms-mcs-admpwdexpirationtime", "isDeleted",
"useraccountcontrol"
};

Expand Down
Loading