-
Notifications
You must be signed in to change notification settings - Fork 53
Add CompStatus Events to CertAbuseProcessor BED-6967 #264
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
352238f
write to compStatus for CA lookups
lrfalslev 0c72806
move remote registry dependencies out of static helpers
lrfalslev 39c87b6
add certAbuseProc tests
lrfalslev b20b2dd
replace registry lookup functions in Helpers/IRegistryKey with Regist…
lrfalslev 4d3636a
test cleanup
lrfalslev 69da9fb
add tests for successful lookup in ProcessEAPermissions
lrfalslev 1590a84
test successful lookup for ProcessRegistryEnrollmentPermissions
lrfalslev 41b4f25
consolidate ProcessEAPermissions Tests
lrfalslev 434738e
resolve pr comments
lrfalslev 6c2b85e
Merge branch 'v4' into lfalslev/bed-6967
lrfalslev e8a8102
Collect EnrollmentAgent Restrictions For AllTemplates, add CertAbuseP…
lrfalslev db33182
fix success const in test
lrfalslev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Security; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Win32; | ||
| using SharpHoundCommonLib.Processors; | ||
|
|
||
| namespace SharpHoundCommonLib { | ||
| public interface IRegistryAccessor { | ||
| public RegistryResult GetRegistryKeyData(string target, string subkey, string subvalue, ILogger log); | ||
| public IRegistryKey OpenRemoteRegistry(string target); | ||
| public Task<IRegistryKey> Connect(RegistryHive hive, string machineName); | ||
| } | ||
|
|
||
| public class RegistryAccessor : IRegistryAccessor { | ||
| private static readonly AdaptiveTimeout _adaptiveTimeout = | ||
| new AdaptiveTimeout(maxTimeout: TimeSpan.FromSeconds(10), Logging.LogProvider.CreateLogger(nameof(SHRegistryKey))); | ||
|
|
||
| public RegistryResult GetRegistryKeyData(string target, string subkey, string subvalue, ILogger log) { | ||
| var data = new RegistryResult(); | ||
|
|
||
| try { | ||
| var baseKey = OpenRemoteRegistry(target); | ||
| var value = baseKey.GetValue(subkey, subvalue); | ||
| data.Value = value; | ||
| data.Collected = true; | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| catch (IOException e) { | ||
| log.LogDebug(e, "Error getting data from registry for {Target}: {RegSubKey}:{RegValue}", | ||
| target, subkey, subvalue); | ||
| data.FailureReason = "Target machine was not found or not connectable"; | ||
| } | ||
| catch (SecurityException e) { | ||
| log.LogDebug(e, "Error getting data from registry for {Target}: {RegSubKey}:{RegValue}", | ||
| target, subkey, subvalue); | ||
| data.FailureReason = "User does not have the proper permissions to perform this operation"; | ||
| } | ||
| catch (UnauthorizedAccessException e) { | ||
| log.LogDebug(e, "Error getting data from registry for {Target}: {RegSubKey}:{RegValue}", | ||
| target, subkey, subvalue); | ||
| data.FailureReason = "User does not have the necessary registry rights"; | ||
| } | ||
| catch (Exception e) { | ||
| log.LogDebug(e, "Error getting data from registry for {Target}: {RegSubKey}:{RegValue}", | ||
| target, subkey, subvalue); | ||
| data.FailureReason = e.Message; | ||
| } | ||
|
|
||
| return data; | ||
| } | ||
|
|
||
| public IRegistryKey OpenRemoteRegistry(string target) { | ||
| return Connect(RegistryHive.LocalMachine, target).GetAwaiter().GetResult(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets a handle to a remote registry. | ||
| /// </summary> | ||
| /// <param name="hive"></param> | ||
| /// <param name="machineName"></param> | ||
| /// <returns></returns> | ||
| /// <exception cref="TimeoutException"></exception> | ||
| /// <exception cref="ArgumentException"></exception> | ||
| /// <exception cref="System.IO.IOException"></exception> | ||
| /// <exception cref="ArgumentNullException"></exception> | ||
| /// <exception cref="System.Security.SecurityException"></exception> | ||
| /// <exception cref="UnauthorizedAccessException"></exception> | ||
| public async Task<IRegistryKey> Connect(RegistryHive hive, string machineName) { | ||
| var remoteKey = await _adaptiveTimeout.ExecuteWithTimeout((_) => RegistryKey.OpenRemoteBaseKey(hive, machineName)); | ||
| if (remoteKey.IsSuccess) | ||
| return new SHRegistryKey(remoteKey.Value); | ||
| throw new TimeoutException($"Failed to connect to registry on {machineName}: {remoteKey.Error}"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.