Skip to content

Commit

Permalink
Add collection of DC reg keys
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBK committed Oct 3, 2023
1 parent 34ddcd5 commit 0503a7e
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/CommonLib/Enums/CollectionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public enum ResolvedCollectionMethod
PSRemote = 1 << 14,
UserRights = 1 << 15,
CARegistry = 1 << 16,
DCRegistry = 1 << 17,
LocalGroups = DCOM | RDP | LocalAdmin | PSRemote,
ComputerOnly = LocalGroups | Session | UserRights | CARegistry,
ComputerOnly = LocalGroups | Session | UserRights | CARegistry | DCRegistry,
DCOnly = ACL | Container | Group | ObjectProps | Trusts | GPOLocalGroup,
Default = Group | Session | Trusts | ACL | ObjectProps | LocalGroups | SPNTargets | Container,
All = Default | LoggedOn | GPOLocalGroup | UserRights | CARegistry
All = Default | LoggedOn | GPOLocalGroup | UserRights | CARegistry | DCRegistry
}
}
103 changes: 103 additions & 0 deletions src/CommonLib/Processors/DCRegistryProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Win32;
using SharpHoundCommonLib.Enums;
using SharpHoundCommonLib.OutputTypes;
using SharpHoundRPC;
using SharpHoundRPC.Wrappers;

namespace SharpHoundCommonLib.Processors
{
public class DCRegistryProcessor
{
private readonly ILogger _log;
public readonly ILDAPUtils _utils;
public delegate Task ComputerStatusDelegate(CSVComputerStatus status);
public event ComputerStatusDelegate ComputerStatusEvent;

Check warning on line 22 in src/CommonLib/Processors/DCRegistryProcessor.cs

View workflow job for this annotation

GitHub Actions / build

The event 'DCRegistryProcessor.ComputerStatusEvent' is never used


public DCRegistryProcessor(ILDAPUtils utils, ILogger log = null)
{
_utils = utils;
_log = log ?? Logging.LogProvider.CreateLogger("DCRegProc");
}

public (bool collected, int value) GetCertificateMappingMethods(string target)
{
bool collected = false;
int value = -1;

try
{
var baseKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, target);
var key = baseKey.OpenSubKey(
$"SYSTEM\\CurrentControlSet\\Control\\SecurityProviders\\Schannel");
if (key == null)
{
_log.LogDebug("Registry path for CertificateMappingMethods is null on {Target}", target);
}
else
{
var val = key.GetValue("CertificateMappingMethods");
if (val == null)
{
_log.LogDebug("Registry key for CertificateMappingMethods is null on {Target}", target);
}
else
{
value = (int) val;
collected = true;
}
}
}
catch (Exception e)
{
_log.LogError(e, "Error getting CertificateMappingMethods on {Target}", target);
}

return (collected, value);
}

public (bool collected, int value) GetStrongCertificateBindingEnforcement(string target)
{
bool collected = false;
int value = -1;

try
{
var baseKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, target);
var key = baseKey.OpenSubKey(
$"SYSTEM\\CurrentControlSet\\Services\\Kdc");
if (key == null)
{
_log.LogDebug("Registry path for StrongCertificateBindingEnforcement is null on {Target}", target);
}
else
{
var val = key.GetValue("StrongCertificateBindingEnforcement");
if (val == null)
{
_log.LogDebug("Registry key for StrongCertificateBindingEnforcement is null on {Target}", target);
}
else
{
value = (int) val;
collected = true;
}
}
}
catch (Exception e)
{
_log.LogError(e, "Error getting StrongCertificateBindingEnforcement on {Target}", target);
}

return (collected, value);
}
}
}

0 comments on commit 0503a7e

Please sign in to comment.