Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sharphound.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<PropertyGroup>
<CommonLibsVersion>4.8.0-rc1</CommonLibsVersion>
<CommonLibsVersion>4.8.0-rc2</CommonLibsVersion>
<CommonSource>Dev</CommonSource>
<_CommonSource>$(CommonSource.ToLower())</_CommonSource>
<_CommonLibPath>..\SharpHoundCommon\src\CommonLib\bin\$(Configuration)\net472\SharpHoundCommonLib.dll</_CommonLibPath>
Expand Down
38 changes: 8 additions & 30 deletions src/BaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Sharphound.Runtime;
using SharpHoundCommonLib;
using SharpHoundCommonLib.Enums;
using SharpHoundCommonLib.Processors;
using Timer = System.Timers.Timer;

namespace Sharphound
Expand All @@ -29,6 +30,7 @@ public BaseContext(ILogger logger, LdapConfig ldapConfig, Flags flags)
Flags = flags;
LDAPUtils = new LdapUtils();
LDAPUtils.SetLdapConfig(ldapConfig);
ACLProcessorContext = new ACLProcessorContext();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
CancellationTokenSource = new CancellationTokenSource();
AdminSDHolderHash = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
Expand Down Expand Up @@ -59,6 +61,7 @@ public BaseContext(ILogger logger, LdapConfig ldapConfig, Flags flags)
public int PortScanTimeout { get; set; } = 500;
public CancellationTokenSource CancellationTokenSource { get; set; }
public ILdapUtils LDAPUtils { get; set; }
public ACLProcessorContext ACLProcessorContext { get; }
public Task CollectionTask { get; set; }
public Flags Flags { get; set; }

Expand Down Expand Up @@ -129,40 +132,15 @@ public string ResolveFileName(string filename, string extension, bool addTimesta
/// </summary>
public ConcurrentDictionary<string, string> AdminSDHolderHash { get; set; }

// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~Context()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }

/// <summary>
/// TODO: Implement the primary dispose pattern
/// </summary>
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// TODO: Implement the primary dispose pattern
/// </summary>
/// <param name="disposing"></param>
private void Dispose(bool disposing)
{
if (!disposedValue)
if (disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}

// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
disposedValue = true;
return;
}

ACLProcessorContext.Dispose();
disposedValue = true;
}
}
}
4 changes: 3 additions & 1 deletion src/Client/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Logging;
using SharpHoundCommonLib;
using SharpHoundCommonLib.Enums;
using SharpHoundCommonLib.Processors;
using Timer = System.Timers.Timer;

namespace Sharphound.Client
Expand Down Expand Up @@ -49,6 +50,7 @@ public interface IContext

ILogger Logger { get; set; }
ILdapUtils LDAPUtils { get; set; }
ACLProcessorContext ACLProcessorContext { get; }

string OutputPrefix { get; set; }
string OutputDirectory { get; set; }
Expand Down Expand Up @@ -83,4 +85,4 @@ public interface IContext
/// </summary>
ConcurrentDictionary<string, string> AdminSDHolderHash { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions src/Producers/LdapProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override async Task Produce()
//Context.Logger.LogDebug("{Domain} AdminSDHolder SD Bytes: {Bytes}", domain.Name, B64);

// Create an instance of ACLProcessor - _aclProcessor from ObjectProcessors isn't in this context
var aclProcessor = new ACLProcessor(Context.LDAPUtils);
var aclProcessor = Context.ACLProcessorContext.CreateACLProcessor(Context.LDAPUtils);

// Calculate the authoritative SD based on a hash of the implicit ACLs & AclProtected
var authoritativeSd = aclProcessor.CalculateImplicitACLHash(sd);
Expand Down Expand Up @@ -242,4 +242,4 @@ public override async Task ProduceConfigNC()
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/Runtime/ObjectProcessors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ObjectProcessors {

public ObjectProcessors(IContext context, ILogger log, Channel<CSVComputerStatus> compStatusChannel) {
_context = context;
_aclProcessor = new ACLProcessor(context.LDAPUtils);
_aclProcessor = context.ACLProcessorContext.CreateACLProcessor(context.LDAPUtils);
_spnProcessor = new SPNProcessors(context.LDAPUtils);
_ldapPropertyProcessor = new LdapPropertyProcessor(context.LDAPUtils);
_domainTrustProcessor = new DomainTrustProcessor(context.LDAPUtils);
Expand Down Expand Up @@ -956,4 +956,4 @@ private async Task<IssuancePolicy> ProcessIssuancePolicy(IDirectoryObject entry,
return ret;
}
}
}
}
5 changes: 3 additions & 2 deletions src/Sharphound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ await options.WithParsedAsync(async options =>

private static async Task StartCollection(Options options, BasicLogger logger, CollectionMethod resolved, Flags flags, LdapConfig ldapOptions)
{
IContext context = new BaseContext(logger, ldapOptions, flags)
using var baseContext = new BaseContext(logger, ldapOptions, flags)
{
DomainName = options.Domain,
CacheFileName = options.CacheName,
Expand All @@ -222,6 +222,7 @@ private static async Task StartCollection(Options options, BasicLogger logger, C
LocalAdminUsername = options.LocalAdminUsername,
LocalAdminPassword = options.LocalAdminPassword
};
IContext context = baseContext;

var cancellationTokenSource = new CancellationTokenSource();
context.CancellationTokenSource = cancellationTokenSource;
Expand Down Expand Up @@ -264,4 +265,4 @@ public static void InvokeSharpHound(string[] args) {
}

#endregion
}
}
Loading