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

Prompt for --LDAPPassword interactively if password not specified #53

Open
wants to merge 3 commits into
base: dev
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 26 additions & 2 deletions src/Sharphound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down