Skip to content

Commit

Permalink
wip: initial cleanup commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Dec 11, 2024
1 parent 9a5eb07 commit 52de010
Show file tree
Hide file tree
Showing 34 changed files with 970 additions and 1,600 deletions.
16 changes: 9 additions & 7 deletions src/CommonLib/Enums/CollectionMethod.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;

namespace SharpHoundCommonLib.Enums
{
namespace SharpHoundCommonLib.Enums {
[Flags]
public enum CollectionMethod
{
public enum CollectionMethod {
None = 0,
Group = 1,
LocalAdmin = 1 << 1,
Expand All @@ -30,9 +28,13 @@ public enum CollectionMethod
SmbInfo = 1 << 22,
EventLogs = 1 << 23,
LocalGroups = DCOM | RDP | LocalAdmin | PSRemote,
ComputerOnly = LocalGroups | Session | UserRights | CARegistry | DCRegistry | WebClientService | SmbInfo | EventLogs,
ComputerOnly = LocalGroups | Session | UserRights | CARegistry | DCRegistry | WebClientService | SmbInfo,
DCOnly = ACL | Container | Group | ObjectProps | Trusts | GPOLocalGroup | CertServices | LdapServices | SmbInfo,
Default = Group | Session | Trusts | ACL | ObjectProps | LocalGroups | SPNTargets | Container | CertServices | LdapServices | SmbInfo,
All = Default | LoggedOn | GPOLocalGroup | UserRights | CARegistry | DCRegistry | WebClientService | LdapServices | EventLogs

Default = Group | Session | Trusts | ACL | ObjectProps | LocalGroups | SPNTargets | Container | CertServices |
LdapServices | SmbInfo,

All = Default | LoggedOn | GPOLocalGroup | UserRights | CARegistry | DCRegistry | WebClientService |
LdapServices
}
}
6 changes: 6 additions & 0 deletions src/CommonLib/Enums/EventIds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace SharpHoundCommonLib.Enums;

public class EventIds {
public static int LogonEvent = 4624;
public static int ValidateCredentialsEvent = 4776;
}
6 changes: 2 additions & 4 deletions src/CommonLib/Enums/LdapErrorCodes.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace SharpHoundCommonLib.Enums
{
public enum LdapErrorCodes : int
{
namespace SharpHoundCommonLib.Enums {
public enum LdapErrorCodes : int {
Success = 0,
StrongAuthRequired = 8,
SaslBindInProgress = 14,
Expand Down
8 changes: 3 additions & 5 deletions src/CommonLib/Enums/LdapOption.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace SharpHoundCommonLib.Enums
{
public enum LdapOption : int
{
namespace SharpHoundCommonLib.Enums {
public enum LdapOption : int {
Ssl = 0x0A,
ProtocolVersion = 0x11,
ResultCode = 0x31,
Expand All @@ -11,4 +9,4 @@ public enum LdapOption : int
Encrypt = 0x96,
Timeout = 0x5002,
}
}
}
8 changes: 3 additions & 5 deletions src/CommonLib/Enums/LdapOptionValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
using System.Text;
using System.Threading.Tasks;

namespace SharpHoundCommonLib.Enums
{
public enum LdapOptionValue : int
{
namespace SharpHoundCommonLib.Enums {
public enum LdapOptionValue : int {
Off = 0,
On = 1,
Version3 = 3,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
using System.Text;
using System.Threading.Tasks;

namespace SharpHoundCommonLib.Enums
{
public static class LdapSupportedSaslMechansims
{
namespace SharpHoundCommonLib.Enums {
public static class LdapSupportedSaslMechanisms {
public const string GSSAPI = "GSSAPI";
public const string GSS_SPNEGO = "GSS-SPNEGO";
public const string EXTERNAL = "EXTERNAL";
public const string DIGEST_MD5 = "DIGEST_MD5";
}
}
}
2 changes: 1 addition & 1 deletion src/CommonLib/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static string LdapValue(this Guid s)
/// <param name="methods"></param>
/// <returns></returns>
public static bool IsComputerCollectionSet(this CollectionMethod methods) {
const CollectionMethod test = CollectionMethod.ComputerOnly | CollectionMethod.LoggedOn;
const CollectionMethod test = CollectionMethod.ComputerOnly | CollectionMethod.LoggedOn | CollectionMethod.SmbInfo | CollectionMethod.SmbInfo;
return (methods & test) != 0;
}

Expand Down
18 changes: 8 additions & 10 deletions src/CommonLib/Impersonate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Impersonator : IDisposable {
///<param name = "domainName" > Name of the domain.</param>
///<param name = "password" > The password. <see cref = "System.String" /></ param >
///< param name="logonType">Type of the logon.</param>
///<param name = "logonProvider" > The logon provider. <see cref = "Mit.Sharepoint.WebParts.EventLogQuery.Network.LogonProvider" /></ param >
///<param name = "logonProvider" > The logon provider. <see cref = "Mit.Sharepoint.WebParts.EventLogQuery.Network.LogonProvider" /></param >
public Impersonator(string userName, string domainName, string password, LogonType logonType,
LogonProvider logonProvider) {
Impersonate(userName, domainName, password, logonType, logonProvider);
Expand Down Expand Up @@ -125,10 +125,11 @@ public void Dispose() {
/// </summary>
///<param name = "userName" > Name of the user.</param>
///<param name = "domainName" > Name of the domain.</param>
///<param name = "password" > The password. <see cref = "System.String" /></ param >
///< param name="logonType">Type of the logon.</param>
///<param name = "password" > The password. <see cref = "System.String" /></param >
///<param name="logonType">Type of the logon.</param>
///<param name = "logonProvider" > The logon provider. <see cref = "Mit.Sharepoint.WebParts.EventLogQuery.Network.LogonProvider" /></ param >
public void Impersonate(string userName, string domainName, string password, LogonType logonType = LogonType.LOGON32_LOGON_INTERACTIVE,
public void Impersonate(string userName, string domainName, string password,
LogonType logonType = LogonType.LOGON32_LOGON_INTERACTIVE,
LogonProvider logonProvider = LogonProvider.LOGON32_PROVIDER_DEFAULT) {
UndoImpersonation();

Expand All @@ -149,14 +150,11 @@ public void Impersonate(string userName, string domainName, string password, Log
ref logonTokenDuplicate) != 0) {
var wi = new WindowsIdentity(logonTokenDuplicate);
wi.Impersonate(); // discard the returned identity context (which is the context of the application pool)
}
else
} else
throw new Win32Exception(Marshal.GetLastWin32Error());
}
else
} else
throw new Win32Exception(Marshal.GetLastWin32Error());
}
finally {
} finally {
if (logonToken != IntPtr.Zero)
Win32NativeMethods.CloseHandle(logonToken);

Expand Down
Loading

0 comments on commit 52de010

Please sign in to comment.