Skip to content

Commit

Permalink
Merge branch 'v4' into BED-4901-fix-TGTDelegationEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar authored Oct 15, 2024
2 parents a2edcf1 + 48e136d commit 10fff45
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 33 deletions.
29 changes: 20 additions & 9 deletions src/CommonLib/Processors/ACLProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
namespace SharpHoundCommonLib.Processors {
public class ACLProcessor {
private static readonly Dictionary<Label, string> BaseGuids;
private static readonly ConcurrentDictionary<string, string> GuidMap = new();
private readonly ConcurrentDictionary<string, string> _guidMap = new();
private readonly ILogger _log;
private readonly ILdapUtils _utils;
private static readonly HashSet<string> BuiltDomainCaches = new(StringComparer.OrdinalIgnoreCase);
private readonly ConcurrentHashSet _builtDomainCaches = new(StringComparer.OrdinalIgnoreCase);

static ACLProcessor() {
//Create a dictionary with the base GUIDs of each object type
Expand Down Expand Up @@ -50,23 +50,33 @@ public ACLProcessor(ILdapUtils utils, ILogger log = null) {
/// LAPS
/// </summary>
private async Task BuildGuidCache(string domain) {
BuiltDomainCaches.Add(domain);
await foreach (var result in _utils.Query(new LdapQueryParameters {
_log.LogInformation("Building GUID Cache for {Domain}", domain);
await foreach (var result in _utils.PagedQuery(new LdapQueryParameters {
DomainName = domain,
LDAPFilter = "(schemaIDGUID=*)",
NamingContext = NamingContext.Schema,
Attributes = new[] { LDAPProperties.SchemaIDGUID, LDAPProperties.Name },
})) {
if (result.IsSuccess) {
if (!result.Value.TryGetProperty(LDAPProperties.Name, out var name) ||
!result.Value.TryGetGuid(out var guid)) {
!result.Value.TryGetByteProperty(LDAPProperties.SchemaIDGUID, out var schemaGuid)) {
continue;
}

name = name.ToLower();
string guid;
try
{
guid = new Guid(schemaGuid).ToString();
}
catch
{
continue;
}

if (name is LDAPProperties.LAPSPassword or LDAPProperties.LegacyLAPSPassword) {
_log.LogDebug("Found GUID for ACL Right {Name}: {Guid} in domain {Domain}", name, guid, domain);
GuidMap.TryAdd(guid, name);
_log.LogInformation("Found GUID for ACL Right {Name}: {Guid} in domain {Domain}", name, guid, domain);
_guidMap.TryAdd(guid, name);
}
} else {
_log.LogDebug("Error while building GUID cache for {Domain}: {Message}", domain, result.Error);
Expand Down Expand Up @@ -217,7 +227,8 @@ public IEnumerable<string> GetInheritedAceHashes(byte[] ntSecurityDescriptor, st
public async IAsyncEnumerable<ACE> ProcessACL(byte[] ntSecurityDescriptor, string objectDomain,
Label objectType,
bool hasLaps, string objectName = "") {
if (!BuiltDomainCaches.Contains(objectDomain)) {
if (!_builtDomainCaches.Contains(objectDomain)) {
_builtDomainCaches.Add(objectDomain);
await BuildGuidCache(objectDomain);
}

Expand Down Expand Up @@ -288,7 +299,7 @@ public async IAsyncEnumerable<ACE> ProcessACL(byte[] ntSecurityDescriptor, strin
aceInheritanceHash = CalculateInheritanceHash(ir, aceRights, aceType, ace.InheritedObjectType());
}

GuidMap.TryGetValue(aceType, out var mappedGuid);
_guidMap.TryGetValue(aceType, out var mappedGuid);

_log.LogTrace("Processing ACE with rights {Rights} and guid {GUID} on object {Name}", aceRights,
aceType, objectName);
Expand Down
Loading

0 comments on commit 10fff45

Please sign in to comment.