From 8040bdd4730d5ad18306d4a27dfb968f4d765714 Mon Sep 17 00:00:00 2001 From: LuemmelSec <58529760+LuemmelSec@users.noreply.github.com> Date: Thu, 16 Feb 2023 12:42:54 +0100 Subject: [PATCH] Update Sharphound.cs --- src/Sharphound.cs | 55 ++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/Sharphound.cs b/src/Sharphound.cs index cc8730d..eb687c1 100644 --- a/src/Sharphound.cs +++ b/src/Sharphound.cs @@ -80,9 +80,8 @@ internal class SharpLinks : Links /// /// /// - /// /// - public IContext Initialize(IContext context, LDAPConfig options, Sharphound.Options options2) + public IContext Initialize(IContext context, LDAPConfig options) { context.Logger.LogTrace("Entering initialize link"); JsonConvert.DefaultSettings = () => new JsonSerializerSettings @@ -105,28 +104,6 @@ public IContext Initialize(IContext context, LDAPConfig options, Sharphound.Opti return context; } - // Check to make sure both Local Admin Session Enum options are set if either is set - - if (options2.LocalAdminPassword != null && options2.LocalAdminUsername == null || - options2.LocalAdminUsername != null && options2.LocalAdminPassword == null) - { - context.Logger.LogTrace("You must specify both LocalAdminUsername and LocalAdminPassword if using these options!"); - context.Flags.IsFaulted = true; - return context; - } - - // Check to make sure doLocalAdminSessionEnum is set when specifying localadmin and password - - if (options2.LocalAdminPassword != null || options2.LocalAdminUsername != null) - { - if (options2.DoLocalAdminSessionEnum == false) - { - context.Logger.LogTrace("You must use the --doLocalAdminSessionEnum switch in combination with --LocalAdminUsername and --LocalAdminPassword!"); - context.Flags.IsFaulted = true; - return context; - } - } - //Check some loop options if (!context.Flags.Loop) return context; //If loop is set, ensure we actually set options properly @@ -420,7 +397,37 @@ await options.WithParsedAsync(async options => ldapOptions.Username = options.LDAPUsername; ldapOptions.Password = options.LDAPPassword; } + + // Check to make sure both Local Admin Session Enum options are set if either is set + if (options.LocalAdminPassword != null && options.LocalAdminUsername == null || + options.LocalAdminUsername != null && options.LocalAdminPassword == null) + { + logger.LogError("You must specify both LocalAdminUsername and LocalAdminPassword if using these options!"); + return; + } + + // Check to make sure doLocalAdminSessionEnum is set when specifying localadmin and password + + if (options.LocalAdminPassword != null || options.LocalAdminUsername != null) + { + if (options.DoLocalAdminSessionEnum == false) + { + logger.LogError("You must use the --doLocalAdminSessionEnum switch in combination with --LocalAdminUsername and --LocalAdminPassword!"); + return; + } + } + + // Check to make sure LocalAdminUsername and LocalAdminPassword are set when using doLocalAdminSessionEnum + + if (options.DoLocalAdminSessionEnum == true) + { + if (options.LocalAdminPassword == null || options.LocalAdminUsername == null) + { + logger.LogError("You must specify both LocalAdminUsername and LocalAdminPassword if using the --doLocalAdminSessionEnum option!"); + return; + } + } IContext context = new BaseContext(logger, ldapOptions, flags) {