| | 1 | | using SharpHoundCommonLib.OutputTypes; |
| | 2 | | using System; |
| | 3 | | using System.Diagnostics.CodeAnalysis; |
| | 4 | | using System.Threading.Tasks; |
| | 5 | | using Microsoft.Extensions.Logging; |
| | 6 | |
|
| | 7 | | namespace SharpHoundCommonLib.Processors |
| | 8 | | { |
| | 9 | | public class DCRegistryProcessor |
| | 10 | | { |
| | 11 | | private readonly ILogger _log; |
| | 12 | | public readonly ILdapUtils _utils; |
| | 13 | | public delegate Task ComputerStatusDelegate(CSVComputerStatus status); |
| | 14 | |
|
| 0 | 15 | | public DCRegistryProcessor(ILdapUtils utils, ILogger log = null) |
| 0 | 16 | | { |
| 0 | 17 | | _utils = utils; |
| 0 | 18 | | _log = log ?? Logging.LogProvider.CreateLogger("DCRegProc"); |
| 0 | 19 | | } |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// This function gets the CertificateMappingMethods registry value stored on DCs. |
| | 23 | | /// </summary> |
| | 24 | | /// <remarks>https://support.microsoft.com/en-us/topic/kb5014754-certificate-based-authentication-changes-on-win |
| | 25 | | /// <param name="target"></param> |
| | 26 | | /// <returns>IntRegistryAPIResult</returns> |
| | 27 | | /// <exception cref="Exception"></exception> |
| | 28 | | [ExcludeFromCodeCoverage] |
| | 29 | | public IntRegistryAPIResult GetCertificateMappingMethods(string target) |
| | 30 | | { |
| | 31 | | var ret = new IntRegistryAPIResult(); |
| | 32 | | const string subKey = @"SYSTEM\CurrentControlSet\Control\SecurityProviders\Schannel"; |
| | 33 | | const string subValue = "CertificateMappingMethods"; |
| | 34 | | var data = Helpers.GetRegistryKeyData(target, subKey, subValue, _log); |
| | 35 | |
|
| | 36 | | ret.Collected = data.Collected; |
| | 37 | | if (!data.Collected) |
| | 38 | | { |
| | 39 | | ret.FailureReason = data.FailureReason; |
| | 40 | | return ret; |
| | 41 | | } |
| | 42 | |
|
| | 43 | | if (data.Value == null) |
| | 44 | | { |
| | 45 | | ret.Value = -1; |
| | 46 | | return ret; |
| | 47 | | } |
| | 48 | |
|
| | 49 | | ret.Value = (int)data.Value; |
| | 50 | |
|
| | 51 | | return ret; |
| | 52 | | } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// This function gets the StrongCertificateBindingEnforcement registry value stored on DCs. |
| | 56 | | /// </summary> |
| | 57 | | /// <remarks>https://support.microsoft.com/en-us/topic/kb5014754-certificate-based-authentication-changes-on-win |
| | 58 | | /// <param name="target"></param> |
| | 59 | | /// <returns>IntRegistryAPIResult</returns> |
| | 60 | | /// <exception cref="Exception"></exception> |
| | 61 | | [ExcludeFromCodeCoverage] |
| | 62 | | public IntRegistryAPIResult GetStrongCertificateBindingEnforcement(string target) |
| | 63 | | { |
| | 64 | | var ret = new IntRegistryAPIResult(); |
| | 65 | | const string subKey = @"SYSTEM\CurrentControlSet\Services\Kdc"; |
| | 66 | | const string subValue = "StrongCertificateBindingEnforcement"; |
| | 67 | | var data = Helpers.GetRegistryKeyData(target, subKey, subValue, _log); |
| | 68 | |
|
| | 69 | | ret.Collected = data.Collected; |
| | 70 | | if (!data.Collected) |
| | 71 | | { |
| | 72 | | ret.FailureReason = data.FailureReason; |
| | 73 | | return ret; |
| | 74 | | } |
| | 75 | |
|
| | 76 | | if (data.Value == null) |
| | 77 | | { |
| | 78 | | ret.Value = -1; |
| | 79 | | return ret; |
| | 80 | | } |
| | 81 | |
|
| | 82 | | ret.Value = (int)data.Value; |
| | 83 | |
|
| | 84 | | return ret; |
| | 85 | | } |
| | 86 | | } |
| | 87 | | } |