diff --git a/src/CommonLib/LDAPUtils.cs b/src/CommonLib/LDAPUtils.cs index 7804ad4d..80ccde11 100644 --- a/src/CommonLib/LDAPUtils.cs +++ b/src/CommonLib/LDAPUtils.cs @@ -571,6 +571,10 @@ public IEnumerable DoRangedRetrieval(string distinguishedName, string at public async Task 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; diff --git a/test/unit/CommonLibHelperTests.cs b/test/unit/CommonLibHelperTests.cs index d498a5f3..4b83dc3c 100644 --- a/test/unit/CommonLibHelperTests.cs +++ b/test/unit/CommonLibHelperTests.cs @@ -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()