Skip to content

Commit

Permalink
fix: replace BUILTIN container with domain node
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 committed Apr 17, 2024
1 parent e9ef5be commit ff106e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/CommonLib/Processors/ContainerProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.DirectoryServices.Protocols;
using Microsoft.Extensions.Logging;
using SharpHoundCommonLib.Enums;
using SharpHoundCommonLib.LDAPQueries;
using SharpHoundCommonLib.OutputTypes;

Expand Down Expand Up @@ -48,6 +49,13 @@ public TypedPrincipal GetContainingObject(string distinguishedName)
{
var containerDn = Helpers.RemoveDistinguishedNamePrefix(distinguishedName);

if (containerDn.StartsWith("CN=BUILTIN", StringComparison.OrdinalIgnoreCase))
{
var domain = Helpers.DistinguishedNameToDomain(distinguishedName);
var domainSid = _utils.GetSidFromDomainName(domain);
return new TypedPrincipal(domainSid, Label.Domain);
}

if (string.IsNullOrEmpty(containerDn))
return null;

Expand Down
4 changes: 4 additions & 0 deletions test/unit/ContainerProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public void ContainerProcessor_GetContainingObject_ExpectedResult()
result = proc.GetContainingObject("CN=PRIMARY,OU=DOMAIN CONTROLLERS,DC=TESTLAB,DC=LOCAL");
Assert.Equal(Label.OU, result.ObjectType);
Assert.Equal("0DE400CD-2FF3-46E0-8A26-2C917B403C65", result.ObjectIdentifier);

result = proc.GetContainingObject("CN=ADMINISTRATORS,CN=BUILTIN,DC=TESTLAB,DC=LOCAL");
Assert.Equal(Label.Domain, result.ObjectType);
Assert.Equal("S-1-5-21-3130019616-2776909439-2417379446", result.ObjectIdentifier);
}

[Fact]
Expand Down
7 changes: 6 additions & 1 deletion test/unit/Facades/MockLDAPUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,12 @@ public string GetDomainNameFromSid(string sid)

public string GetSidFromDomainName(string domainName)
{
throw new NotImplementedException();
if (domainName.Equals("TESTLAB.LOCAL", StringComparison.OrdinalIgnoreCase))
{
return "S-1-5-21-3130019616-2776909439-2417379446";
}

return null;
}

public string ConvertWellKnownPrincipal(string sid, string domain)
Expand Down

0 comments on commit ff106e5

Please sign in to comment.