| | 1 | | using System.DirectoryServices.Protocols; |
| | 2 | | using System.Text; |
| | 3 | |
|
| | 4 | | namespace SharpHoundCommonLib |
| | 5 | | { |
| | 6 | | public class LdapConfig |
| | 7 | | { |
| 66 | 8 | | public string Username { get; set; } = null; |
| 60 | 9 | | public string Password { get; set; } = null; |
| 61 | 10 | | public string Server { get; set; } = null; |
| 60 | 11 | | public int Port { get; set; } = 0; |
| 60 | 12 | | public int SSLPort { get; set; } = 0; |
| 61 | 13 | | public bool ForceSSL { get; set; } = false; |
| 62 | 14 | | public bool DisableSigning { get; set; } = false; |
| 62 | 15 | | public bool DisableCertVerification { get; set; } = false; |
| 62 | 16 | | public AuthType AuthType { get; set; } = AuthType.Kerberos; |
| 60 | 17 | | public int MaxConcurrentQueries { get; set; } = 15; |
| | 18 | |
|
| | 19 | | //Returns the port for connecting to LDAP. Will always respect a user's overridden config over anything else |
| | 20 | | public int GetPort(bool ssl) |
| 0 | 21 | | { |
| 0 | 22 | | if (ssl && SSLPort != 0) { |
| 0 | 23 | | return SSLPort; |
| | 24 | | } |
| 0 | 25 | | if (!ssl && Port != 0) |
| 0 | 26 | | { |
| 0 | 27 | | return Port; |
| | 28 | | } |
| | 29 | |
|
| 0 | 30 | | return ssl ? 636 : 389; |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | public int GetGCPort(bool ssl) |
| 2 | 34 | | { |
| 2 | 35 | | return ssl ? 3269 : 3268; |
| 2 | 36 | | } |
| | 37 | |
|
| 0 | 38 | | public override string ToString() { |
| 0 | 39 | | var sb = new StringBuilder(); |
| 0 | 40 | | sb.AppendLine($"Server: {Server}"); |
| 0 | 41 | | sb.AppendLine($"LdapPort: {GetPort(false)}"); |
| 0 | 42 | | sb.AppendLine($"LdapSSLPort: {GetPort(true)}"); |
| 0 | 43 | | sb.AppendLine($"ForceSSL: {ForceSSL}"); |
| 0 | 44 | | sb.AppendLine($"AuthType: {AuthType.ToString()}"); |
| 0 | 45 | | sb.AppendLine($"MaxConcurrentQueries: {MaxConcurrentQueries}"); |
| 0 | 46 | | if (!string.IsNullOrWhiteSpace(Username)) { |
| 0 | 47 | | sb.AppendLine($"Username: {Username}"); |
| 0 | 48 | | } |
| | 49 | |
|
| 0 | 50 | | if (!string.IsNullOrWhiteSpace(Password)) { |
| 0 | 51 | | sb.AppendLine($"Password: {new string('*', Password.Length)}"); |
| 0 | 52 | | } |
| 0 | 53 | | return sb.ToString(); |
| 0 | 54 | | } |
| | 55 | | } |
| | 56 | | } |