Group Managed Service Accounts (GMSAs) The CanReadGMSAPassword permission in Active Directory allows an account to read the passwords associated with Group Managed Service Accounts (GMSAs). GMSAs are designed for automated and secure service account management, enabling services and applications to authenticate seamlessly without manual password handling. If the PrincipalsAllowedToRetrieveManagedPassword attribute is not configured, administrators or users cannot view these passwords. By granting the CanReadGMSAPassword permission to services, organizations facilitate seamless authentication processes, reduce the administrative overhead of manual password management, and enhance overall security by ensuring that service account credentials are complex and regularly updated without human intervention.
However, if the CanReadGMSAPassword permission is misconfigured, an attacker can extract the passwords of GMSA accounts, which are integrated with numerous critical services and applications. With access to these credentials, the attacker can impersonate service accounts to interact with critical services, access sensitive data repositories, and manipulate essential infrastructure components. This level of access can facilitate lateral movement across the network, enable unauthorized data exfiltration, and allow for the deployment of malicious configurations or software.
Identification
PowerShell
Active Directory Module
Using the ActiveDirectory PowerShell module, you can enumerate CanReadGMSAPassword entries.
1. Find-CanReadGMSAPassword function
functionFind-CanReadGMSAPassword { [CmdletBinding()]param ( [string]$Target, [string]$OutputPath ="CanReadGMSAPassword.csv")Import-Module ActiveDirectory -ErrorAction Stopif ($Target) {Write-Host"Searching for gMSAs under '$Target'..."-ForegroundColor Yellow $serviceAccounts =Get-ADServiceAccount-Filter *-SearchBase $Target -Properties 'msDS-GroupMSAMembership' } else {Write-Host"Searching for all gMSAs in the domain..."-ForegroundColor Yellow $serviceAccounts =Get-ADServiceAccount-Filter *-Properties 'msDS-GroupMSAMembership' } $results =foreach ($sa in $serviceAccounts) {if ($sa.'msDS-GroupMSAMembership') {foreach ($entry in $sa.'msDS-GroupMSAMembership') { [PSCustomObject]@{ GMSA = $sa.Name DistinguishedName = $sa.DistinguishedName AllowedPrincipal = $entry.Access.IdentityReference AccessType = $entry.Access.AccessControlType } } } }if ($results) {Write-Host"Found $($results.Count) gMSA(s) with retrievable password permissions."-ForegroundColor Greentry { $results |Export-Csv-Path $OutputPath -NoTypeInformation -Encoding UTF8 -ErrorAction StopWrite-Host"Results exported to '$OutputPath'"-ForegroundColor Green } catch {Write-Error"Failed to export results to '$OutputPath'. Error: $_" } } else {Write-Host"No gMSAs with msDS-GroupMSAMembership set were found."-ForegroundColor Green }}
2. Scan all domain service accounts
3. Scan a specific service account
.NET Directory Services
By leveraging PowerShell’s built-in .NET DirectoryServices namespace, you can enumerate CanReadGMSAPassword entries without relying on any external modules or dependencies.
1. Find-CanReadGMSAPasswordSimple function
2. Scan all domain service accounts
3. Scan a specific service account
Exploitation
This permission can be exploited on Windows systems with DSInternals, while on Linux systems, tools such as GMSADumper can be effectively used for exploitation.
Windows
An attacker can Read GMSA Password with this cmdlet on Windows. (DSInternals should be installed) DSInternals
Example:
After this, you can obtain NT Hash. With NT Hash attacker can perform attacks like PassTheHash
Linux
An attacker can get GMSA password with this command on Linux. (You should download the GMSADumper tool before running the command) GMSADumper
Example:
Read GMSA NT hash using NetExec
Example:
Mitigation
In the script below, assign the vulnerable GMSA’s distinguished name to the GMSADistinguishedName variable and the dangerous user’s name to the DangerousUser variable.
(To run this script successfully, you should have Write permission on the msDS-GroupMSAMembership attribute of the GMSA object (Write msDS-GroupMSAMembership). This permission is typically granted to Domain Admins and Enterprise Admins. If you do not have this permission, you will need to contact your Active Directory administrator to perform this action.)
Detection
Adding new access control entries to Active Directory objects changes the ntSecurityDescriptor attribute of the objects. These changes can be detected with Event IDs 5136 and 4662 to identify dangerous modifications.