Skip to content

Commit

Permalink
fix: filter empty spns during host resolution to prevent bad edges
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Feb 1, 2024
1 parent 0a08d00 commit bf08556
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/CommonLib/LDAPUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ public IEnumerable<string> DoRangedRetrieval(string distinguishedName, string at
public async Task<string> ResolveHostToSid(string hostname, string domain)
{
var strippedHost = Helpers.StripServicePrincipalName(hostname).ToUpper().TrimEnd('$');
if (string.IsNullOrEmpty(strippedHost))
{
return null;
}

if (_hostResolutionMap.TryGetValue(strippedHost, out var sid)) return sid;

Expand Down
9 changes: 9 additions & 0 deletions test/unit/CommonLibHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ public void StripServicePrincipalName_InValidServicePrincipal_ExpectedHostName()
var actual = SharpHoundCommonLib.Helpers.StripServicePrincipalName(testString);
Assert.Equal(expected, actual);
}

[Fact]
public void StripServicePrincipalName_EmptyHost_Valid()
{
var testString = "MSSQLSvc/:1433";
var expected = "";
var actual = SharpHoundCommonLib.Helpers.StripServicePrincipalName(testString);
Assert.Equal(expected, actual);
}

[Fact]
public void B64ToBytes_String_ValidBase64String()
Expand Down

0 comments on commit bf08556

Please sign in to comment.