Skip to content

Commit

Permalink
wip: rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jul 2, 2024
1 parent 9e690d5 commit bd077d6
Show file tree
Hide file tree
Showing 21 changed files with 184 additions and 192 deletions.
2 changes: 1 addition & 1 deletion src/CommonLib/ConnectionPoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private bool GetDomainSidFromDomainName(string domainName, out string domainSid)
//we expect this to fail sometimes
}

if (LdapUtilsNew.GetDomain(domainName, _ldapConfig, out var domainObject))
if (LdapUtils.GetDomain(domainName, _ldapConfig, out var domainObject))
try {
domainSid = domainObject.GetDirectoryEntry().GetSid();
if (domainSid != null) {
Expand Down
144 changes: 0 additions & 144 deletions src/CommonLib/ILDAPUtils.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System.Collections.Generic;
using System.DirectoryServices.Protocols;
using System.Runtime.CompilerServices;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using SharpHoundCommonLib.Enums;
using SharpHoundCommonLib.OutputTypes;

namespace SharpHoundCommonLib {
public interface ILdapUtilsNew {
public interface ILdapUtils {
IAsyncEnumerable<LdapResult<ISearchResultEntry>> Query(LdapQueryParameters queryParameters,
CancellationToken cancellationToken = new());

Expand Down
148 changes: 147 additions & 1 deletion src/CommonLib/LDAPUtils.cs → src/CommonLib/LDAPUtilsBackup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// using System;
// using System;
// using System.Collections.Concurrent;
// using System.Collections.Generic;
// using System.Diagnostics;
Expand Down Expand Up @@ -2112,4 +2112,150 @@
// return false;
// }
// }
// }


// using System.Collections.Generic;
// using System.DirectoryServices.ActiveDirectory;
// using System.DirectoryServices.Protocols;
// using System.Security.Principal;
// using System.Threading;
// using System.Threading.Tasks;
// using SharpHoundCommonLib.Enums;
// using SharpHoundCommonLib.OutputTypes;
// using SharpHoundRPC.Wrappers;
// using Domain = System.DirectoryServices.ActiveDirectory.Domain;
//
// namespace SharpHoundCommonLib
// {
// /// <summary>
// /// Struct representing options to create an LDAP query
// /// </summary>
// public struct LDAPQueryOptions
// {
// public string Filter;
// public SearchScope Scope;
// public string[] Properties;
// public CancellationToken CancellationToken;
// public string DomainName;
// public bool IncludeAcl;
// public bool ShowDeleted;
// public string AdsPath;
// public bool GlobalCatalog;
// public bool SkipCache;
// public bool ThrowException;
// }
//
// public interface ILDAPUtils
// {
// void SetLDAPConfig(LDAPConfig config);
// bool TestLDAPConfig(string domain);
// string[] GetUserGlobalCatalogMatches(string name);
// TypedPrincipal ResolveIDAndType(string id, string fallbackDomain);
// TypedPrincipal ResolveCertTemplateByProperty(string propValue, string propName, string containerDN, string domainName);
// Label LookupSidType(string sid, string domain);
// Label LookupGuidType(string guid, string domain);
// string GetDomainNameFromSid(string sid);
// string GetSidFromDomainName(string domainName);
// string ConvertWellKnownPrincipal(string sid, string domain);
// bool GetWellKnownPrincipal(string sid, string domain, out TypedPrincipal commonPrincipal);
//
// bool ConvertLocalWellKnownPrincipal(SecurityIdentifier sid, string computerDomainSid, string computerDomain,
// out TypedPrincipal principal);
// Domain GetDomain(string domainName = null);
// void AddDomainController(string domainControllerSID);
// IEnumerable<OutputBase> GetWellKnownPrincipalOutput(string domain);
//
// /// <summary>
// /// Performs Attribute Ranged Retrieval
// /// https://docs.microsoft.com/en-us/windows/win32/adsi/attribute-range-retrieval
// /// The function self-determines the range and internally handles the maximum step allowed by the server
// /// </summary>
// /// <param name="distinguishedName"></param>
// /// <param name="attributeName"></param>
// /// <returns></returns>
// IEnumerable<string> DoRangedRetrieval(string distinguishedName, string attributeName);
//
// /// <summary>
// /// Takes a host in most applicable forms from AD and attempts to resolve it into a SID.
// /// </summary>
// /// <param name="hostname"></param>
// /// <param name="domain"></param>
// /// <returns></returns>
// Task<string> ResolveHostToSid(string hostname, string domain);
//
// /// <summary>
// /// Attempts to convert a bare account name (usually from session enumeration) to its corresponding ID and object type
// /// </summary>
// /// <param name="name"></param>
// /// <param name="domain"></param>
// /// <returns></returns>
// TypedPrincipal ResolveAccountName(string name, string domain);
//
// /// <summary>
// /// Attempts to convert a distinguishedname to its corresponding ID and object type.
// /// </summary>
// /// <param name="dn">DistinguishedName</param>
// /// <returns>A <c>TypedPrincipal</c> object with the SID and Label</returns>
// TypedPrincipal ResolveDistinguishedName(string dn);
//
// /// <summary>
// /// Performs an LDAP query using the parameters specified by the user.
// /// </summary>
// /// <param name="options">LDAP query options</param>
// /// <returns>All LDAP search results matching the specified parameters</returns>
// IEnumerable<ISearchResultEntry> QueryLDAP(LDAPQueryOptions options);
//
// /// <summary>
// /// Performs an LDAP query using the parameters specified by the user.
// /// </summary>
// /// <param name="ldapFilter">LDAP filter</param>
// /// <param name="scope">SearchScope to query</param>
// /// <param name="props">LDAP properties to fetch for each object</param>
// /// <param name="cancellationToken">Cancellation Token</param>
// /// <param name="includeAcl">Include the DACL and Owner values in the NTSecurityDescriptor</param>
// /// <param name="showDeleted">Include deleted objects</param>
// /// <param name="domainName">Domain to query</param>
// /// <param name="adsPath">ADS path to limit the query too</param>
// /// <param name="globalCatalog">Use the global catalog instead of the regular LDAP server</param>
// /// <param name="skipCache">
// /// Skip the connection cache and force a new connection. You must dispose of this connection
// /// yourself.
// /// </param>
// /// <param name="throwException">Throw exceptions rather than logging the errors directly</param>
// /// <returns>All LDAP search results matching the specified parameters</returns>
// IEnumerable<ISearchResultEntry> QueryLDAP(string ldapFilter, SearchScope scope,
// string[] props, CancellationToken cancellationToken, string domainName = null, bool includeAcl = false,
// bool showDeleted = false, string adsPath = null, bool globalCatalog = false, bool skipCache = false,
// bool throwException = false);
//
// /// <summary>
// /// Performs an LDAP query using the parameters specified by the user.
// /// </summary>
// /// <param name="ldapFilter">LDAP filter</param>
// /// <param name="scope">SearchScope to query</param>
// /// <param name="props">LDAP properties to fetch for each object</param>
// /// <param name="includeAcl">Include the DACL and Owner values in the NTSecurityDescriptor</param>
// /// <param name="showDeleted">Include deleted objects</param>
// /// <param name="domainName">Domain to query</param>
// /// <param name="adsPath">ADS path to limit the query too</param>
// /// <param name="globalCatalog">Use the global catalog instead of the regular LDAP server</param>
// /// <param name="skipCache">
// /// Skip the connection cache and force a new connection. You must dispose of this connection
// /// yourself.
// /// </param>
// /// <param name="throwException">Throw exceptions rather than logging the errors directly</param>
// /// <returns>All LDAP search results matching the specified parameters</returns>
// IEnumerable<ISearchResultEntry> QueryLDAP(string ldapFilter, SearchScope scope,
// string[] props, string domainName = null, bool includeAcl = false, bool showDeleted = false,
// string adsPath = null, bool globalCatalog = false, bool skipCache = false, bool throwException = false);
//
// Forest GetForest(string domainName = null);
// string GetConfigurationPath(string domainName);
// string GetSchemaPath(string domainName);
//
// ActiveDirectorySecurityDescriptor MakeSecurityDescriptor();
// string BuildLdapPath(string dnPath, string domain);
// bool IsDomainController(string computerObjectId, string domainName);
// }
// }
2 changes: 1 addition & 1 deletion src/CommonLib/LdapConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void Dispose() {
}
}

if (!LdapUtilsNew.GetDomain(_identifier, _ldapConfig, out var domainObject) || domainObject.Name == null) {
if (!LdapUtils.GetDomain(_identifier, _ldapConfig, out var domainObject) || domainObject.Name == null) {
//If we don't get a result here, we effectively have no other ways to resolve this domain, so we'll just have to exit out
_log.LogDebug(
"Could not get domain object from GetDomain, unable to create ldap connection for domain {Domain}",
Expand Down
2 changes: 1 addition & 1 deletion src/CommonLib/LdapResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protected LdapResult(T value, bool success, string error, string queryInfo, int
ErrorCode = errorCode;
}

public static LdapResult<T> Ok(T value) {
public new static LdapResult<T> Ok(T value) {
return new LdapResult<T>(value, true, string.Empty, null, 0);
}

Expand Down
7 changes: 4 additions & 3 deletions src/CommonLib/LdapUtilsNew.cs → src/CommonLib/LdapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using SecurityMasks = System.DirectoryServices.Protocols.SecurityMasks;

namespace SharpHoundCommonLib {
public class LdapUtilsNew : ILdapUtilsNew {
public class LdapUtils : ILdapUtils {
//This cache is indexed by domain sid
private readonly ConcurrentDictionary<string, NetAPIStructs.DomainControllerInfo?> _dcInfoCache = new();
private static readonly ConcurrentDictionary<string, Domain> DomainCache = new();
Expand Down Expand Up @@ -73,14 +73,14 @@ private class ResolvedWellKnownPrincipal {
public string WkpId { get; set; }
}

public LdapUtilsNew() {
public LdapUtils() {
_nativeMethods = new NativeMethods();
_portScanner = new PortScanner();
_log = Logging.LogProvider.CreateLogger("LDAPUtils");
_connectionPool = new ConnectionPoolManager(_ldapConfig);
}

public LdapUtilsNew(NativeMethods nativeMethods = null, PortScanner scanner = null, ILogger log = null) {
public LdapUtils(NativeMethods nativeMethods = null, PortScanner scanner = null, ILogger log = null) {
_nativeMethods = nativeMethods ?? new NativeMethods();
_portScanner = scanner ?? new PortScanner();
_log = log ?? Logging.LogProvider.CreateLogger("LDAPUtils");
Expand Down Expand Up @@ -1017,6 +1017,7 @@ public static bool GetDomain(string domainName, LDAPConfig ldapConfig, out Domai
return true;
}
catch (Exception e) {
Logging.Logger.LogDebug("Static GetDomain call failed for domain {DomainName}: {Error}", domainName, e.Message);
return false;
}
}
Expand Down
Loading

0 comments on commit bd077d6

Please sign in to comment.