Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BED-4820] OPTIONAL: Going a step further - ignoring error code values #162

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/CommonLib/Processors/LdapPropertyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;
using SharpHoundCommonLib.Enums;
using SharpHoundCommonLib.LDAPQueries;
using SharpHoundCommonLib.OutputTypes;
Expand Down Expand Up @@ -70,16 +71,28 @@ public async Task<Dictionary<string, object>> ReadDomainProperties(IDirectoryObj
props.Add("lockoutthreshold", entry.GetProperty(LDAPProperties.LockoutThreshold));

if (entry.TryGetLongProperty(LDAPProperties.MinPwdAge, out var minpwdage)) {
props.Add("minpwdage", ConvertNanoDuration(minpwdage));
var duration = ConvertNanoDuration(minpwdage);
if (duration != null) {
props.Add("minpwdage", duration);
}
}
if (entry.TryGetLongProperty(LDAPProperties.MaxPwdAge, out var maxpwdage)) {
props.Add("maxpwdage", ConvertNanoDuration(maxpwdage));
var duration = ConvertNanoDuration(maxpwdage);
if (duration != null) {
props.Add("maxpwdage", duration);
}
}
if (entry.TryGetLongProperty(LDAPProperties.LockoutDuration, out var lockoutduration)) {
props.Add("lockoutduration", ConvertNanoDuration(lockoutduration));
var duration = ConvertNanoDuration(lockoutduration);
if (duration != null) {
props.Add("lockoutduration", duration);
}
}
if (entry.TryGetLongProperty(LDAPProperties.LockOutObservationWindow, out var lockoutobservationwindow)) {
props.Add("lockoutobservationwindow", ConvertNanoDuration(lockoutobservationwindow));
var duration = ConvertNanoDuration(lockoutobservationwindow);
if (duration != null) {
props.Add("lockoutobservationwindow", lockoutobservationwindow);
}
}
if (!entry.TryGetLongProperty(LDAPProperties.DomainFunctionalLevel, out var functionalLevel)) {
functionalLevel = -1;
Expand Down Expand Up @@ -724,6 +737,14 @@ private static List<string> ConvertEncryptionTypes(string encryptionTypes)

private static string ConvertNanoDuration(long duration)
{
// In case duration is long.MinValue, Math.Abs will overflow. Value represents Forever or Never
if (duration == long.MinValue) {
return "Forever";
// And if the value is positive, it indicates an error code
} else if (duration > 0) {
return null;
}

// duration is in 100-nanosecond intervals
// Convert it to TimeSpan (which uses 1 tick = 100 nanoseconds)
TimeSpan durationSpan = TimeSpan.FromTicks(Math.Abs(duration));
Expand Down
Loading