Skip to content

Commit

Permalink
chore: add some missing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jul 25, 2024
1 parent ba5420e commit ec07256
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/CommonLib/Enums/LDAPProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ public static class LDAPProperties
public const string DnsRoot = "dnsroot";
public const string ServerName = "servername";
public const string OU = "ou";
public const string ProfilePath = "profilepath";
}
}
4 changes: 4 additions & 0 deletions src/CommonLib/LdapQueries/CommonProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,9 @@ public static class CommonProperties
LDAPProperties.CertificateApplicationPolicy, LDAPProperties.CertificatePolicy, LDAPProperties.IssuancePolicies, LDAPProperties.CrossCertificatePair,
LDAPProperties.ApplicationPolicies, LDAPProperties.PKIPrivateKeyFlag, LDAPProperties.OIDGroupLink
};

public static readonly string[] StealthProperties = {
LDAPProperties.HomeDirectory, LDAPProperties.ScriptPath, LDAPProperties.ProfilePath
};
}
}
11 changes: 4 additions & 7 deletions src/CommonLib/Processors/SPNProcessors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@ public SPNProcessors(ILdapUtils utils, ILogger log = null) {

public IAsyncEnumerable<SPNPrivilege> ReadSPNTargets(ResolvedSearchResult result,
IDirectoryObject entry) {
if (entry.TryGetArrayProperty(LDAPProperties.ServicePrincipalNames, out var members) &&
entry.TryGetDistinguishedName(out var dn)) {
return ReadSPNTargets(members, dn, result.DisplayName);
if (entry.TryGetArrayProperty(LDAPProperties.ServicePrincipalNames, out var members)) {
return ReadSPNTargets(members, result.Domain, result.DisplayName);
}

return AsyncEnumerable.Empty<SPNPrivilege>();
}

public async IAsyncEnumerable<SPNPrivilege> ReadSPNTargets(string[] servicePrincipalNames,
string distinguishedName, string objectName = "") {
string domainName, string objectName = "") {
if (servicePrincipalNames.Length == 0) {
_log.LogTrace("SPN Array is empty for {Name}", objectName);
yield break;
}

_log.LogDebug("Processing SPN targets for {ObjectName}", objectName);

var domain = Helpers.DistinguishedNameToDomain(distinguishedName);

foreach (var spn in servicePrincipalNames) {
//This SPN format isn't useful for us right now (username@domain)
if (spn.Contains("@")) {
Expand All @@ -53,7 +50,7 @@ public async IAsyncEnumerable<SPNPrivilege> ReadSPNTargets(string[] servicePrinc
if (!int.TryParse(spn.Split(':')[1], out port))
port = 1433;

if (await _utils.ResolveHostToSid(spn, domain) is (true, var host) && host.StartsWith("S-1")) {
if (await _utils.ResolveHostToSid(spn, domainName) is (true, var host) && host.StartsWith("S-1")) {
_log.LogTrace("Resolved {SPN} to {Hostname}", spn, host);
yield return new SPNPrivilege {
ComputerSID = host,
Expand Down

0 comments on commit ec07256

Please sign in to comment.