Attacking Active Directory Group Managed Service Accounts (GMSAs) - Active Directory Security
Attacking Active Directory Group Managed Service Accounts (GMSAs) - Active Directory Security
Attacking Active Directory Group Managed Service Accounts (GMSAs) - Active Directory Security
p=4367
• (https://adsecurity.org/?feed=rss2)
From Azure AD to Active Directory (via Azure) – An Unanticipated Attack Path (https://adsecurity.org
/?p=4277)
May 29 2020
In May 2020, I presented some Active Directory security topics in a Trimarc Webcast called “Securing
Active Directory: Resolving Common Issues” (https://www.hub.trimarcsecurity.com/post/webcast-securing-
active-directory-resolving-common-issues) and included some information I put together relating to the
security of AD Group Managed Service Accounts (GMSA). This post includes the expanded version of
attacking and defending GMSAs I covered in the webcast.
I put this information together after speaking with someone about using GMSAs running services on servers
that have privileged AD rights and there was confusion about what GMSAs actually do and what they can’t.
The confusion seemed to be rooted in the belief that GMSA credentials are protected more than regular
accounts (they aren’t). The key benefit is that their passwords change automatically, not that the credential
data has stronger protections.
This post is meant to highlight what GMSAs can do and what an attacker can do if not protected
appropriately. We have seen limited usage of Group Managed Service Accounts in AD environments when
we perform Active Directory Security Assessments at Trimarc (http://trimarc.co/ADSA). GMSAs should be
used wherever possible to replace user accounts as service accounts since the passwords will rotate
automatically.
1 of 10 10/15/23, 16:36
Attacking Active Directory Group Managed Service A... https://adsecurity.org/?p=4367
• msDS-GroupMSAMembership (https://docs.microsoft.com/en-us/windows/win32/adschema/a-msds-
groupmsamembership) (PrincipalsAllowedToRetrieveManagedPassword) – stores the security
principals that can access the GMSA password.
• msds-ManagedPassword (https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-
adts/9cd2fc5e-7305-4fb8-b233-2a60bc3eec68) – This attribute contains a BLOB with password
information for group-managed service accounts.
• msDS-ManagedPasswordId (https://docs.microsoft.com/en-us/windows/win32/adschema/a-msds-
managedpasswordid) – This constructed attribute contains the key identifier for the current managed
password data for a group MSA.
• msDS-ManagedPasswordInterval (https://docs.microsoft.com/en-us/windows/win32/adschema/a-
msds-managedpasswordinterval) – This attribute is used to retrieve the number of days before a
managed password is automatically changed for a group MSA.
Running the AD PowerShell cmdlet Get-ADServiceAccount, we can retrieve information about the GMSA,
including specific GMSA attrbiutes. This GMSA is a member of the domain Administrators group which has
full AD & DC admin rights to the domain. The screenshot shows that the password changed recently and
won’t change for a few weeks – changed on 5/11/2020 and configured to change every 30 days. This
means that if we can get the password for this account, we have almost a month to use the account
credentials before it changes. We can also identify a group that can retrieve the password data. We’ll take a
look at this is a bit.
Once we get on the server/servers running services under the context of the GMSA we have some options.
Let’s take a look…
2 of 10 10/15/23, 16:36
Attacking Active Directory Group Managed Service A... https://adsecurity.org/?p=4367
We can identify the LCNSQL01 server is registered as a Service Principal Name (SPN) on the GMSA and
we see this server is in the Servers OU.
If we can compromise an account with rights to the Servers OU, or delegated admin rights via GPO
Restricted Groups or similar, or have the ability to modify a GPO that links to this OU, we can we can get
admin rights on the LCN server
After getting admin rights on the server associated with the GMSA, we can see there is a service running
under the context of the GMSA (I cheated here and configured Windows License Manager Service to start
with this account).
3 of 10 10/15/23, 16:36
Attacking Active Directory Group Managed Service A... https://adsecurity.org/?p=4367
Since there’s a service running under the context of an account, we can get the password data associated
with the service account. Here we use Mimikatz (https://github.com/gentilkiwi/mimikatz)to dump LSASS
using sekurlsa::logonpasswords.
That’s not a standard password (and not actually the one associated with the account). What’s more, this
password hash isn’t correct. Microsoft loads the GMSA credential into LSASS but doesn’t seem to use it.
To get the right NT password hash we need to use the Mimikatz (https://github.com/gentilkiwi
/mimikatz)command “Sekurlsa::ekeys” which is what’s used to get Kerberos tickets.
4 of 10 10/15/23, 16:36
Attacking Active Directory Group Managed Service A... https://adsecurity.org/?p=4367
After running this Mimikatz command, we are able to see password hash. With this password hash, we can
pass the hash (PTH) to compromise AD.
5 of 10 10/15/23, 16:36
Attacking Active Directory Group Managed Service A... https://adsecurity.org/?p=4367
When enumerating the membership of the group “SVC-LAB-GMSA1 Group” there are computers, users,
and another group (“Server Admins”), so lets check the members of that group.
6 of 10 10/15/23, 16:36
Attacking Active Directory Group Managed Service A... https://adsecurity.org/?p=4367
Now we have a list of all accounts that can get the clear-text password for the GMSA. There are 11 user
accounts with that ability and 9 of those look like regular user accounts (hint: they are!). That’s a big
problem.
Compromise one of those and the GMSA account is compromised and since it’s a member of the
Administrators group in the domain, we own the domain.
Once we compromise a user (or computer!) account that has the ability to pull the clear text password.
(PrincipalsAllowedToRetriveManagedPassword), we can request that using the Microsoft PowerShell
cmdlet Get-ADServiceAccount.
We can leverage the PowerShell cmdlet Get-ADServiceAccount to get the clear-text password data for the
GMSA (attribute msds-ManagedPassword). Using the DSInternals module (ConvertTo-NTHash)
(https://www.dsinternals.com/en/retrieving-cleartext-gmsa-passwords-from-active-directory/), we can
convert the clear-text password blob to the NT hash.
7 of 10 10/15/23, 16:36
Attacking Active Directory Group Managed Service A... https://adsecurity.org/?p=4367
If the account we are able to compromise is the computer account, we need to run these commands as
SYSTEM on the computer. This method would be used if we’re able to get admin/SYSTEM rights on the
server with rights to pull the GMSA password, but the GMSA is not running under the context of a service
(so running Mimikatz doesn’t help since the GMSA creds aren’t in memory).
Here I use PSEXEC to spawn a command shell running under the context of the local SYSTEM account.
Once running as SYSTEM, we can perform the same action as shown above. The computer account has
the right to pull the password, but not a user on that computer, so I elevate to SYSTEM which then interacts
with AD as the associated AD computer account. Now I can get the GMSA password.
Next step I perform in the lab is to to confirm that the NT password hash that DSInternals provides matches
that in Active Directory.
I use the DSInternals (https://www.dsinternals.com/)command Get-ADReplAccount to get the AD password
hash and can confirm that the password hash pulled from the GMSA is the same as that gathered from AD.
8 of 10 10/15/23, 16:36
Attacking Active Directory Group Managed Service A... https://adsecurity.org/?p=4367
Mitigation
• Determine rights actually required and ensure the only the required, limited rights apply to the GMSA.
• Don’t add to AD privileged groups unless the servers the GMSAs are used on are limited to Tier 0
(Domain Controllers).
• Limit GMSA access & location (especially if privileged).
Thank You!
Huge shout-out to Michael Grafnetter (https://twitter.com/MGrafnetter) at DSInternals for hist blogpost
(https://www.dsinternals.com/en/retrieving-cleartext-gmsa-passwords-from-active-directory/)that provided
the information I needed to walk through this process.
Also to Benjamin Delpy (https://twitter.com/gentilkiwi) for helping me test a recent version of Mimikatz
against the LSASS data containing GMSA credentials.
9 of 10 10/15/23, 16:36
Attacking Active Directory Group Managed Service A... https://adsecurity.org/?p=4367
(https://adsecurity.org/?author=2)
Sean Metcalf
I improve security for enterprises around the world working for TrimarcSecurity.com
Read the About page (top left) for information about me. :)
https://adsecurity.org/?page_id=8
• (mailto:[email protected])
Copyright
Content Disclaimer: This blog and its contents are provided "AS IS" with no warranties, and they confer no
rights. Script samples are provided for informational purposes only and no guarantee is provided as to
functionality or suitability. The views shared on this blog reflect those of the authors and do not represent
the views of any companies mentioned. Content Ownership: All content posted here is intellectual work and
under the current law, the poster owns the copyright of the article. Terms of Use Copyright © 2011 - 2020.
Content Disclaimer: This blog and its contents are provided "AS IS" with no warranties, and they confer no
rights. Script samples are provided for informational purposes only and no guarantee is provided as to
functionality or suitability. The views shared on this blog reflect those of the authors and do not represent the
views of any companies mentioned.
10 of 10 10/15/23, 16:36