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

Closed
ChristophHannappel opened this issue Oct 29, 2024 · 8 comments · Fixed by #234
Labels

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?

@ChristophHannappel
Copy link
Author

That looks good to me :) Thank you

@Yvand Yvand linked a pull request Dec 9, 2024 that will close this issue
@Yvand
Copy link
Owner

Yvand commented Dec 9, 2024

@ChristophHannappel feel free to look at the linked PR and tell me if the code change looks good

Copy link

github-actions bot commented Jan 9, 2025

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Jan 9, 2025
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants