Skip to content

Commit

Permalink
chore: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jul 26, 2024
1 parent 0dbd085 commit 7dd5709
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/CommonLib/Processors/LdapPropertyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SharpHoundCommonLib.Enums;
using SharpHoundCommonLib.LDAPQueries;
using SharpHoundCommonLib.OutputTypes;

// ReSharper disable StringLiteralTypo

namespace SharpHoundCommonLib.Processors {
Expand Down Expand Up @@ -186,7 +187,7 @@ public async Task<UserProperties> ReadUserProperties(IDirectoryObject entry, str
}

props.Add("lastlogon", Helpers.ConvertFileTimeToUnixEpoch(lastLogon));

if (!entry.TryGetProperty(LDAPProperties.LastLogonTimestamp, out var lastLogonTimeStamp)) {
lastLogonTimeStamp = null;
}
Expand All @@ -196,6 +197,7 @@ public async Task<UserProperties> 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);
Expand Down Expand Up @@ -264,7 +266,7 @@ public async Task<ComputerProperties> 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<TypedPrincipal>();
if (flags.HasFlag(UacFlags.TrustedToAuthForDelegation) &&
entry.TryGetArrayProperty(LDAPProperties.AllowedToDelegateTo, out var delegates)) {
Expand Down Expand Up @@ -365,7 +367,7 @@ public static Dictionary<string, object> ReadRootCAProperties(IDirectoryObject e
props.Add("hasbasicconstraints", cert.HasBasicConstraints);
props.Add("basicconstraintpathlength", cert.BasicConstraintPathLength);
}

return props;
}

Expand All @@ -376,7 +378,7 @@ public static Dictionary<string, object> ReadRootCAProperties(IDirectoryObject e
/// <returns>Returns a dictionary with the common properties and the crosscertificatepair property of the AICA</returns>
public static Dictionary<string, object> 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);
Expand All @@ -397,7 +399,8 @@ public static Dictionary<string, object> ReadAIACAProperties(IDirectoryObject en

public static Dictionary<string, object> 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));

Expand Down Expand Up @@ -471,7 +474,8 @@ public static Dictionary<string, object> 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);
Expand All @@ -487,7 +491,7 @@ public static Dictionary<string, object> ReadCertTemplateProperties(IDirectoryOb
}

entry.TryGetArrayProperty(LDAPProperties.ApplicationPolicies, out var appPolicies);

props.Add("applicationpolicies",
ParseCertTemplateApplicationPolicies(appPolicies,
schemaVersion, hasUseLegacyProvider));
Expand Down Expand Up @@ -551,21 +555,28 @@ public Dictionary<string, object> 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());
}
Expand Down

0 comments on commit 7dd5709

Please sign in to comment.