Skip to content

Commit

Permalink
wip: processor merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Sep 11, 2024
1 parent 5a377b3 commit 30870bc
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 29 deletions.
344 changes: 321 additions & 23 deletions SharpHoundProcessors/BaseObjectProcessor.cs

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions SharpHoundProcessors/ProcessorConfig.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
using System;
using System.Threading.Tasks;

namespace SharpHoundProcessors {
public class ProcessorConfig {
private static readonly Lazy<Random> RandomGen = new();
//Computer Availability Arguments
public int PortScanTimeout { get; set;}= 10000;
public int ComputerExpiryDays { get; set; } = 60;
public bool SkipPortScan { get; set; } = false;
public bool SkipComputerAgeCheck { get; set; } = false;
public string DNSName { get; set; } = null;

//Session Processor Arguments
public bool UseAlternateLocalAdminCredentials { get; set; } = false;
public string AlternateLocalAdminUsername { get; set; } = null;
public string AlternateLocalAdminPassword { get; set; } = null;
public string OverrideCurrentUserName { get; set; } = null;
public bool SkipRegistryLoggedOn { get; set; } = false;

//Ldap Property Processor
public bool CollectAllProperties { get; set; } = false;

//Throttle
public int Throttle { get; set; } = 0;
public int Jitter { get; set; } = 0;

public async Task Delay()
{
if (Throttle == 0)
return;

if (Jitter == 0)
{
await Task.Delay(Throttle);
return;
}

var percent = (int)Math.Floor((double)(Jitter * (Throttle / 100)));
var delay = Throttle + RandomGen.Value.Next(-percent, percent);
await Task.Delay(delay);
}
}
}
20 changes: 20 additions & 0 deletions src/CommonLib/DirectoryObjects/DirectoryEntryWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,24 @@ public IEnumerable<string> PropertyNames() {
foreach (var property in _entry.Properties.PropertyNames)
yield return property.ToString().ToLower();
}

public string GetDNSName(string overrideDomainName) {
var shortName = GetProperty(LDAPProperties.SAMAccountName);
var dns = GetProperty(LDAPProperties.DNSHostName);
var cn = GetProperty(LDAPProperties.CanonicalName);

if (dns != null) {
return dns;
}

if (shortName == null && cn == null) {
return null;
}

if (shortName != null) {
return $"{shortName}.{overrideDomainName}";
}

return $"{cn}.{overrideDomainName}";
}
}
1 change: 1 addition & 0 deletions src/CommonLib/DirectoryObjects/IDirectoryObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public interface IDirectoryObject {
byte[] GetByteProperty(string propertyName);
int PropertyCount(string propertyName);
IEnumerable<string> PropertyNames();
public string GetDNSName(string overrideDomainName);
}
20 changes: 20 additions & 0 deletions src/CommonLib/DirectoryObjects/SearchResultEntryWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,24 @@ public IEnumerable<string> PropertyNames() {
foreach (var property in _entry.Attributes.AttributeNames)
yield return property.ToString().ToLower();
}

public string GetDNSName(string overrideDomainName) {
var shortName = GetProperty(LDAPProperties.SAMAccountName);
var dns = GetProperty(LDAPProperties.DNSHostName);
var cn = GetProperty(LDAPProperties.CanonicalName);

if (dns != null) {
return dns;
}

if (shortName == null && cn == null) {
return null;
}

if (shortName != null) {
return $"{shortName}.{overrideDomainName}";
}

return $"{cn}.{overrideDomainName}";
}
}
13 changes: 9 additions & 4 deletions src/CommonLib/Enums/OutputNames.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
namespace SharpHoundCommonLib.Enums;

public static class OutputNames {
public static string Domain = "domain";
public static string Name = "name";
public static string DistinguishedName = "distinguishedname";
public static string DomainSID = "domainsid";
public const string Domain = "domain";
public const string Name = "name";
public const string DistinguishedName = "distinguishedname";
public const string DomainSID = "domainsid";
public const string SAMAccountName = "samaccountname";
public const string IsACLProtected = "isaclprotected";
public const string MSA = "msa";
public const string GMSA = "gmsa";
public const string HasLAPS = "haslaps";
}
1 change: 0 additions & 1 deletion src/CommonLib/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
Expand Down
15 changes: 15 additions & 0 deletions src/CommonLib/Processors/ComputerAvailability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ public ComputerAvailability(PortScanner scanner, int timeout = 500, int computer
}

public event ComputerStatusDelegate ComputerStatusEvent;

/// <summary>
/// Helper function to use commonlib types for IsComputerAvailable
/// </summary>
/// <param name="computerName"></param>
/// <param name="entry"></param>
/// <returns></returns>
public Task<ComputerStatus> IsComputerAvailable(string computerName, IDirectoryObject entry)
{
var os = entry.GetProperty(LDAPProperties.OperatingSystem);
var pwdlastset = entry.GetProperty(LDAPProperties.PasswordLastSet);
var lastLogon = entry.GetProperty(LDAPProperties.LastLogonTimestamp);

return IsComputerAvailable(computerName, os, pwdlastset, lastLogon);
}

/// <summary>
/// Helper function to use commonlib types for IsComputerAvailable
Expand Down
8 changes: 8 additions & 0 deletions src/CommonLib/Processors/ComputerSessionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ await SendComputerStatus(new CSVComputerStatus {
return ret;
}

public Task<SessionAPIResult> ReadUserSessionsPrivileged(string computerName, IDirectoryObject entry,
ResolvedSearchResult resolvedSearchResult, TimeSpan timeout = default) {
var samAccountName = entry.GetProperty(LDAPProperties.SAMAccountName)?.TrimEnd('$');
var sid = resolvedSearchResult.ObjectId;

return ReadUserSessionsPrivileged(computerName, samAccountName, sid, timeout);
}

/// <summary>
/// Uses the privileged win32 API, NetWkstaUserEnum, to return the logged on users on a remote computer.
/// Requires administrator rights on the target system
Expand Down
3 changes: 2 additions & 1 deletion src/CommonLib/Processors/LdapPropertyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public static Dictionary<string, object> ReadGroupProperties(IDirectoryObject en
/// </summary>
/// <param name="entry"></param>
/// <returns></returns>
public static Dictionary<string, object> ReadContainerProperties(IDirectoryObject entry) {
public static Dictionary<string, object>
ReadContainerProperties(IDirectoryObject entry) {
var props = GetCommonProps(entry);
return props;
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/Facades/MockDirectoryObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,24 @@ public int PropertyCount(string propertyName) {
public IEnumerable<string> PropertyNames() {
foreach (var property in Properties.Keys) yield return property.ToString().ToLower();
}

public string GetDNSName(string overrideDomainName) {
var shortName = GetProperty(LDAPProperties.SAMAccountName);
var dns = GetProperty(LDAPProperties.DNSHostName);
var cn = GetProperty(LDAPProperties.CanonicalName);

if (dns != null) {
return dns;
}

if (shortName == null && cn == null) {
return null;
}

if (shortName != null) {
return $"{shortName}.{overrideDomainName}";
}

return $"{cn}.{overrideDomainName}";
}
}

0 comments on commit 30870bc

Please sign in to comment.