From 7dd57091ba9d7e6f4e1a7df6e1b3a8cdcab7c8f9 Mon Sep 17 00:00:00 2001 From: rvazarkar Date: Fri, 26 Jul 2024 15:42:06 -0400 Subject: [PATCH] chore: reformat --- .../Processors/LdapPropertyProcessor.cs | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/CommonLib/Processors/LdapPropertyProcessor.cs b/src/CommonLib/Processors/LdapPropertyProcessor.cs index a947da75..6cd33ba0 100644 --- a/src/CommonLib/Processors/LdapPropertyProcessor.cs +++ b/src/CommonLib/Processors/LdapPropertyProcessor.cs @@ -11,6 +11,7 @@ using SharpHoundCommonLib.Enums; using SharpHoundCommonLib.LDAPQueries; using SharpHoundCommonLib.OutputTypes; + // ReSharper disable StringLiteralTypo namespace SharpHoundCommonLib.Processors { @@ -186,7 +187,7 @@ public async Task ReadUserProperties(IDirectoryObject entry, str } props.Add("lastlogon", Helpers.ConvertFileTimeToUnixEpoch(lastLogon)); - + if (!entry.TryGetProperty(LDAPProperties.LastLogonTimestamp, out var lastLogonTimeStamp)) { lastLogonTimeStamp = null; } @@ -196,6 +197,7 @@ public async Task ReadUserProperties(IDirectoryObject entry, str if (!entry.TryGetProperty(LDAPProperties.PasswordLastSet, out var passwordLastSet)) { passwordLastSet = null; } + props.Add("pwdlastset", Helpers.ConvertFileTimeToUnixEpoch(passwordLastSet)); entry.TryGetArrayProperty(LDAPProperties.ServicePrincipalNames, out var spn); @@ -264,7 +266,7 @@ public async Task ReadComputerProperties(IDirectoryObject en props.Add("unconstraineddelegation", flags.HasFlag(UacFlags.TrustedForDelegation)); props.Add("trustedtoauth", flags.HasFlag(UacFlags.TrustedToAuthForDelegation)); props.Add("isdc", flags.HasFlag(UacFlags.ServerTrustAccount)); - + var comps = new List(); if (flags.HasFlag(UacFlags.TrustedToAuthForDelegation) && entry.TryGetArrayProperty(LDAPProperties.AllowedToDelegateTo, out var delegates)) { @@ -365,7 +367,7 @@ public static Dictionary ReadRootCAProperties(IDirectoryObject e props.Add("hasbasicconstraints", cert.HasBasicConstraints); props.Add("basicconstraintpathlength", cert.BasicConstraintPathLength); } - + return props; } @@ -376,7 +378,7 @@ public static Dictionary ReadRootCAProperties(IDirectoryObject e /// Returns a dictionary with the common properties and the crosscertificatepair property of the AICA public static Dictionary ReadAIACAProperties(IDirectoryObject entry) { var props = GetCommonProps(entry); - entry.TryGetByteArrayProperty(LDAPProperties.CrossCertificatePair, out var crossCertificatePair); + entry.TryGetByteArrayProperty(LDAPProperties.CrossCertificatePair, out var crossCertificatePair); var hasCrossCertificatePair = crossCertificatePair.Length > 0; props.Add("crosscertificatepair", crossCertificatePair); @@ -397,7 +399,8 @@ public static Dictionary ReadAIACAProperties(IDirectoryObject en public static Dictionary ReadEnterpriseCAProperties(IDirectoryObject entry) { var props = GetCommonProps(entry); - if (entry.TryGetIntProperty("flags", out var flags)) props.Add("flags", (PKICertificateAuthorityFlags)flags); + if (entry.TryGetIntProperty("flags", out var flags)) + props.Add("flags", (PKICertificateAuthorityFlags)flags); props.Add("caname", entry.GetProperty(LDAPProperties.Name)); props.Add("dnshostname", entry.GetProperty(LDAPProperties.DNSHostName)); @@ -471,7 +474,8 @@ public static Dictionary ReadCertTemplateProperties(IDirectoryOb entry.TryGetArrayProperty(LDAPProperties.ExtendedKeyUsage, out var ekus); props.Add("ekus", ekus); - entry.TryGetArrayProperty(LDAPProperties.CertificateApplicationPolicy, out var certificateApplicationPolicy); + entry.TryGetArrayProperty(LDAPProperties.CertificateApplicationPolicy, + out var certificateApplicationPolicy); props.Add("certificateapplicationpolicy", certificateApplicationPolicy); entry.TryGetArrayProperty(LDAPProperties.CertificatePolicy, out var certificatePolicy); @@ -487,7 +491,7 @@ public static Dictionary ReadCertTemplateProperties(IDirectoryOb } entry.TryGetArrayProperty(LDAPProperties.ApplicationPolicies, out var appPolicies); - + props.Add("applicationpolicies", ParseCertTemplateApplicationPolicies(appPolicies, schemaVersion, hasUseLegacyProvider)); @@ -551,21 +555,28 @@ public Dictionary ParseAllProperties(IDirectoryObject entry) { if (entry.TryGetByteProperty(property, out var testBytes)) { if (testBytes == null || testBytes.Length == 0) { continue; - }; + } + + ; // SIDs try { var sid = new SecurityIdentifier(testBytes, 0); props.Add(property, sid.Value); continue; - } catch { /* Ignore */ } + } catch { + /* Ignore */ + } // GUIDs try { var guid = new Guid(testBytes); props.Add(property, guid.ToString()); continue; - } catch { /* Ignore */ } + } catch { + /* Ignore */ + } } + if (entry.TryGetArrayProperty(property, out var arr) && arr.Length > 0) { props.Add(property, arr.Select(BestGuessConvert).ToArray()); }