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

GetGroupsFromActiveDirectory: Allow the use of Encryption aka SecureSocketLayer with SimpleBind #232

Open
ChristophHannappel opened this issue Oct 29, 2024 · 4 comments

Comments

@ChristophHannappel
Copy link

Hello,

currently it's not possible to use the SimpleBind in companion with SecureSocketLayer.
According to System.DirectoryServices.AccountManagement it should be possible to use them together:

Caution: Communications may be sent over the Internet in clear text if the SecureSocketsLayer option is not specified with simple bind.

The code in question is:

if (ldapConnection.AuthenticationType == AuthenticationTypes.None)

if (ldapConnection.AuthenticationType == AuthenticationTypes.None)
{
    contextOptions |= ContextOptions.SimpleBind;
}

Could you add support for the SecureSocketLayer ContextOption if the Encrypt AuthenticationType is present at the LDAP Connection.

Thank you

@ChristophHannappel
Copy link
Author

If you could also add ServerBind that would be great.

@Yvand
Copy link
Owner

Yvand commented Oct 29, 2024

Hello @ChristophHannappel, not sure how to do what you ask:
In enum AuthenticationTypes, None (equivalent of simple bind) has value 0, so I do not see how to possibly mix it with any other authentication option (even though SimpleBind has value 2 in enum ContextOptions)

@ChristophHannappel
Copy link
Author

Hello @Yvand

with the AuthenticationTypes set to Value 2 wouldn't that mean Simple Bind with Encryption and SecureSocketLayer and if set to 3 it would be NTLM Auth with SecureSocketLayer and Encryption

As a PowerShell Example for using SimpleBind with SecureSocketLayer for Augementation:

Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ldapUser = "DOMAIN\user"
if (!$ldapPassword) { $ldapPassword = Read-Host "Enter the password (will appear in clear text)" }
$userToAugment = "userName"
$domainFQDN = "DomainFQDN:636"
# domainContainer must be set, otherwise UserPrincipal.FindByIdentity throsws error 0x80005000 (tested only in AD)
$domainContainer = "DC=fhhnet,DC=stadt,DC=hamburg,DC=de"
$contextOptions = [System.DirectoryServices.AccountManagement.ContextOptions] "SimpleBind, SecureSocketLayer" # Encrypted connection, traffic unreadable in network analyzer
$contextType = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$principalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new($contextType, $domainFQDN , $domainContainer, $contextOptions, $ldapUser, $ldapPassword)
if ($principalContext -ne $null -and [String]::IsNullOrEmpty($principalContext.ConnectedServer) -eq $false) {
    $user = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($principalContext, $userToAugment)
    $groups = $user.GetAuthorizationGroups()

    # The foreach group calls an enumerator that does separate LDAP binds for each group
    $groupNames = foreach($group in $groups) {
            $group.SamAccountName
    }
    $groupNames | Sort-Object
}

As an alternative Idea, do you have any documentation for unsupported use cases or Limitations?

Thank you

@Yvand
Copy link
Owner

Yvand commented Nov 15, 2024

@ChristophHannappel maybe you're right, so the possible mappings would be:

[AuthenticationTypes] Encryption <=> [ContextOptions] SimpleBind, SecureSocketLayer
[AuthenticationTypes] None, Encryption <=> [ContextOptions] SimpleBind, SecureSocketLayer
[AuthenticationTypes] Secure, Encryption <=> [ContextOptions] Negotiate, SecureSocketLayer

Is that correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants