Skip to content
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

Initial NTLM Implementation #177

Open
wants to merge 8 commits into
base: v4
Choose a base branch
from
Open
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
22 changes: 14 additions & 8 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 @@ -25,10 +23,18 @@ public enum CollectionMethod
CARegistry = 1 << 16,
DCRegistry = 1 << 17,
CertServices = 1 << 18,
LdapServices = 1 << 19,
WebClientService = 1 << 21,
SmbInfo = 1 << 22,
EventLogs = 1 << 23,
LocalGroups = DCOM | RDP | LocalAdmin | PSRemote,
ComputerOnly = LocalGroups | Session | UserRights | CARegistry | DCRegistry,
DCOnly = ACL | Container | Group | ObjectProps | Trusts | GPOLocalGroup | CertServices,
Default = Group | Session | Trusts | ACL | ObjectProps | LocalGroups | SPNTargets | Container | CertServices,
All = Default | LoggedOn | GPOLocalGroup | UserRights | CARegistry | DCRegistry
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
}
}
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;
}
10 changes: 5 additions & 5 deletions src/CommonLib/Enums/LdapErrorCodes.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace SharpHoundCommonLib.Enums
{
public enum LdapErrorCodes : int
{
namespace SharpHoundCommonLib.Enums {
public enum LdapErrorCodes : int {
Success = 0,
StrongAuthRequired = 8,
SaslBindInProgress = 14,
InvalidCredentials = 49,
Busy = 51,
ServerDown = 81,
LocalError = 82,
KerberosAuthType = 83
KerberosAuthType = 83,
}
}
12 changes: 12 additions & 0 deletions src/CommonLib/Enums/LdapOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SharpHoundCommonLib.Enums {
public enum LdapOption : int {
Ssl = 0x0A,
ProtocolVersion = 0x11,
ResultCode = 0x31,
ServerError = 0x33,
ServerCertificate = 0x81,
Sign = 0x95,
Encrypt = 0x96,
Timeout = 0x5002,
}
}
13 changes: 13 additions & 0 deletions src/CommonLib/Enums/LdapOptionValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SharpHoundCommonLib.Enums {
public enum LdapOptionValue : int {
Off = 0,
On = 1,
Version3 = 3,
};
}
14 changes: 14 additions & 0 deletions src/CommonLib/Enums/LdapSupportedSaslMechanisms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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.WebClientService;
return (methods & test) != 0;
}

Expand Down
26 changes: 12 additions & 14 deletions src/CommonLib/Impersonate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public class Impersonator : IDisposable {
/// <summary>
/// Begins impersonation with the given credentials, Logon type and Logon provider.
/// </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 = "logonProvider" > The logon provider. <see cref = "Mit.Sharepoint.WebParts.EventLogQuery.Network.LogonProvider" /></ param >
///<param name="userName" > Name of the user.</param>
///<param name="domainName" > Name of the domain.</param>
///<param name="password" > The password.</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 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
Loading