diff --git a/README.md b/README.md index 29fcf9b..d3f90b7 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ dotnet build --ldapusername Username for LDAP - --ldappassword Password for LDAP + --ldappassword Password for LDAP. If not specified, an interactive prompt will be used --domaincontroller Override domain controller to pull LDAP from. This option can result in data loss diff --git a/src/Options.cs b/src/Options.cs index 204c168..f41001b 100644 --- a/src/Options.cs +++ b/src/Options.cs @@ -73,7 +73,7 @@ public class Options [Option(HelpText = "Username for LDAP", Default = null)] public string LDAPUsername { get; set; } - [Option(HelpText = "Password for LDAP", Default = null)] + [Option(HelpText = "Password for LDAP. If not specified, an interactive prompt will be used", Default = null)] public string LDAPPassword { get; set; } [Option(HelpText = "Override domain controller to pull LDAP from. This option can result in data loss", diff --git a/src/Sharphound.cs b/src/Sharphound.cs index 3da19fa..130ed60 100644 --- a/src/Sharphound.cs +++ b/src/Sharphound.cs @@ -21,6 +21,7 @@ using System.IO; using System.Linq; using System.Security.Principal; +using System.Text; using System.Threading; using System.Threading.Tasks; using CommandLine; @@ -389,8 +390,31 @@ await options.WithParsedAsync(async options => { if (options.LDAPPassword == null) { - logger.LogError("You must specify LDAPPassword if using the LDAPUsername options"); - return; + logger.LogInformation("Prompting for interactive LDAPPassword"); + StringBuilder passwordBuilder = new StringBuilder(); + Console.Write("LDAPPassword: "); + while (true) + { + ConsoleKeyInfo key = Console.ReadKey(true); + if (key.Key == ConsoleKey.Enter) + break; + + if (key.Key == ConsoleKey.Backspace) + { + // Don't allow user to backspace through prompt + if (passwordBuilder.Length > 0) + { + passwordBuilder.Length--; + Console.Write("\b \b"); + } + continue; + } + + passwordBuilder.Append(key.KeyChar); + Console.Write("*"); + } + Console.WriteLine(); + options.LDAPPassword = passwordBuilder.ToString(); } ldapOptions.Username = options.LDAPUsername;