-
Notifications
You must be signed in to change notification settings - Fork 52
Improve NTLM Collection Logging BED-7374 #272
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
Open
lrfalslev
wants to merge
11
commits into
v4
Choose a base branch
from
lfalslev/bed-7374
base: v4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e8cb013
add compstatus to registryprocessor
lrfalslev 53a2e0f
add RegistryProcessorTests
lrfalslev 9019d99
null handling
lrfalslev 221ce52
clean up compstatus log
lrfalslev 9383031
fact attribute
lrfalslev 9350ffe
include registry strategy in successful compstat log
lrfalslev dd88aa0
use strategy name in log
lrfalslev b4939bb
include successful strategy in result
lrfalslev 92f7351
add strategyExecutor tests
lrfalslev ad7495d
.net test dependency
lrfalslev d5867b6
Merge branch 'v4' into lfalslev/bed-7374
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <LangVersion>latest</LangVersion> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> | ||
| <PackageReference Include="xunit" Version="2.4.1" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\src\SharpHoundRPC\SharpHoundRPC.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
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,130 @@ | ||
| using SharpHoundRPC.Registry; | ||
| using Xunit; | ||
|
|
||
| namespace RPCTest.Registry; | ||
|
|
||
| public class StrategyExecutorTests { | ||
| private readonly StrategyExecutor _strategyExecutor = new(); | ||
|
|
||
| [Fact] | ||
| public async Task CollectAsync_NoStrategies_ReturnsFailure_WithNoAttempts() { | ||
| // Act | ||
| var result = await _strategyExecutor.CollectAsync<RegistryQueryResult, RegistryQuery>("target machine", [], []); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(result); | ||
| Assert.False(result.WasSuccessful); | ||
| Assert.Empty(result.FailureAttempts!); | ||
| Assert.Null(result.Results); | ||
| Assert.Null(result.SuccessfulStrategy); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CollectAsync_CanExecuteIsFalse_ReturnsFailure_WithAttempt() { | ||
| //Arrange | ||
| var strategy = new FakeCollectionStrategy(false, "well now I am not doing it"); | ||
|
|
||
| // Act | ||
| var result = await _strategyExecutor.CollectAsync("target machine", [], [strategy]); | ||
|
|
||
| // Assert | ||
| Assert.False(result.WasSuccessful); | ||
| Assert.Null(result.Results); | ||
| Assert.Null(result.SuccessfulStrategy); | ||
|
|
||
| var attempt = result.FailureAttempts?.Single(); | ||
| Assert.Equal("well now I am not doing it", attempt?.FailureReason); | ||
| Assert.Equal(strategy.GetType(), attempt?.StrategyType); | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(StrategyExceptions))] | ||
| public async Task CollectAsync_ThrowsException_ReturnsFailure_WithExceptionMessage(Exception strategyException) { | ||
| //Arrange | ||
| var strategy = new FakeCollectionStrategy( | ||
| canExecute: true, | ||
| exception: strategyException | ||
| ); | ||
|
|
||
| // Act | ||
| var result = await _strategyExecutor.CollectAsync("target machine", [], [strategy]); | ||
|
|
||
| // Assert | ||
| Assert.False(result.WasSuccessful); | ||
| Assert.Null(result.Results); | ||
| Assert.Null(result.SuccessfulStrategy); | ||
|
|
||
| var attempt = result.FailureAttempts?.Single(); | ||
| Assert.Contains($"Collector failed: {strategyException.Message}.", attempt!.FailureReason!); | ||
|
|
||
| if (strategyException.InnerException is not null) | ||
| Assert.Contains($"\nInner Exception: {strategyException.InnerException}", attempt!.FailureReason!); | ||
| else | ||
| Assert.DoesNotContain("Inner Exception:", attempt!.FailureReason!); | ||
| } | ||
|
|
||
| public static IEnumerable<object[]> StrategyExceptions => | ||
| [ | ||
| [new Exception("Outer Exception")], | ||
| [new Exception("Outer Exception", new Exception("Inner Exception"))] | ||
| ]; | ||
|
|
||
| [Fact] | ||
| public async Task CollectAsync_FirstStrategySuccessful_ReturnsSuccess_WithNoAttempts() { | ||
| //Arrange | ||
| var strategyResult = new RegistryQueryResult(@"SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0", "NtlmMinClientSec", 1, null, true); | ||
| var strategy = new FakeCollectionStrategy( | ||
| true, | ||
| results: [strategyResult] | ||
| ); | ||
|
|
||
| // Act | ||
| var result = await _strategyExecutor.CollectAsync("target machine", [], [strategy]); | ||
|
|
||
| // Assert | ||
| Assert.True(result.WasSuccessful); | ||
| Assert.Empty(result.FailureAttempts!); | ||
| Assert.Equal(strategy.GetType(), result.SuccessfulStrategy); | ||
| Assert.Equal(strategyResult, result.Results?.Single()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CollectAsync_SecondStrategySuccessful_ReturnsSuccess_WithAttempt() { | ||
| //Arrange | ||
| var failedStrategy = new FakeCollectionStrategy(false, "well now I am not doing it"); | ||
| var strategyResult = new RegistryQueryResult(@"SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0", "NtlmMinClientSec", 1, null, true); | ||
| var successfulStrategy = new FakeCollectionStrategy( | ||
| true, | ||
| results: [strategyResult] | ||
| ); | ||
|
|
||
| // Act | ||
| var result = await _strategyExecutor.CollectAsync("target machine", [], [failedStrategy, successfulStrategy]); | ||
|
|
||
| // Assert | ||
| Assert.True(result.WasSuccessful); | ||
| Assert.Single(result.FailureAttempts!); | ||
| Assert.Equal(successfulStrategy.GetType(), result.SuccessfulStrategy); | ||
| Assert.Equal(strategyResult, result.Results?.Single()); | ||
| } | ||
lrfalslev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| internal sealed class FakeCollectionStrategy( | ||
| bool canExecute, | ||
| string failureReason = "", | ||
| Exception? exception = null, | ||
| IEnumerable<RegistryQueryResult>? results = null | ||
| ) : ICollectionStrategy<RegistryQueryResult, RegistryQuery> | ||
| { | ||
| public Task<(bool, string)> CanExecute(string target) | ||
| => Task.FromResult((canExecute, failureReason)); | ||
|
|
||
| public Task<IEnumerable<RegistryQueryResult>> ExecuteAsync( | ||
| string target, | ||
| IEnumerable<RegistryQuery> queries) { | ||
| if (exception is not null) | ||
| throw exception; | ||
|
|
||
| return Task.FromResult(results ?? []); | ||
| } | ||
| } | ||
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
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
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
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.