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

add support for env credentials or loading creds from json file #127

Open
wants to merge 2 commits into
base: 2.X
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ The listing below details the CLI arguments SharpHound supports. Additional deta

--ldappassword Password for LDAP

--ldapenvusername Username for LDAP stored in a defined environment variable (argument takes the environment variable as input)

--ldapenvpassword Password for LDAP stored in a defined environment variable (argument takes the environment variable as input)

--ldapcredentialsjsonpath Path argument for a json file containing {"Username": "xxxx", "Password": "xxxx"} to be used instead of --ldapusername and --ldappassword

--domaincontroller Override domain controller to pull LDAP from. This option can result in data loss

--ldapport (Default: 0) Override port for LDAP
Expand Down
6 changes: 6 additions & 0 deletions src/JsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

namespace Sharphound
{

public class Credentials
{
public string Username { get; set; }
public string Password { get; set; }
}
public class CacheContractResolver : DefaultContractResolver
{
private static readonly CacheContractResolver Instance = new();
Expand Down
9 changes: 9 additions & 0 deletions src/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ public class Options
[Option(HelpText = "Password for LDAP", Default = null)]
public string LDAPPassword { get; set; }

[Option(HelpText = "Path to Json file containing username/password", Default = null)]
public string LDAPCredentialJsonPath { get; set; }

[Option(HelpText = "Enviroment variable name for LDAP Username", Default = null)]
public string LDAPEnvUsername { get; set; }

[Option(HelpText = "Enviroment variable name for LDAP Password", Default = null)]
public string LDAPEnvPassword { get; set; }

[Option(HelpText = "Do the session enumeration with local admin credentials instead of domain credentials", Default = false)]
public bool DoLocalAdminSessionEnum { get; set; }

Expand Down
20 changes: 20 additions & 0 deletions src/Sharphound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,26 @@ await options.WithParsedAsync(async options => {

if (options.DomainController != null) ldapOptions.Server = options.DomainController;

if (options.LDAPCredentialJsonPath != null) {
string json = File.ReadAllText(options.LDAPCredentialJsonPath);
Credentials ldapCreds = JsonConvert.DeserializeObject<Credentials>(json);
ldapOptions.Username = ldapCreds.Username;
ldapOptions.Password = ldapCreds.Password;
}

if (options.LDAPEnvUsername != null) {
if (options.LDAPEnvPassword == null) {
logger.LogError("You must specify LDAPEnvPassword if using the LDAPEnvUsername options");
return;
}

string EnvUsername = Environment.GetEnvironmentVariable(options.LDAPEnvUsername);
string EnvPassword = Environment.GetEnvironmentVariable(options.LDAPEnvPassword);

ldapOptions.Username = EnvUsername;
ldapOptions.Password = EnvPassword;
}

if (options.LDAPUsername != null) {
if (options.LDAPPassword == null) {
logger.LogError("You must specify LDAPPassword if using the LDAPUsername options");
Expand Down
Loading