Table of Contents


Kerberos

Kerberos has been the default authentication protocol for domain accounts since Windows 2000. Kerberos is an open standard and allows for interoperability with other systems using the same standard. When a user logs into their PC, Kerberos is used to authenticate them via mutual authentication, or both the user and the server verify their identity. Kerberos is a stateless authentication protocol based on tickets instead of transmitting user passwords over the network. As part of Active Directory Domain Services (AD DS), Domain Controllers have a Kerberos Key Distribution Center (KDC) that issues tickets.

When a user initiates a login request to a system, the client they are using to authenticate requests a ticket from the KDC, encrypting the request with the user’s password. If the KDC can decrypt the request (AS-REQ) using their password, it will create a Ticket Granting Ticket (TGT) and transmit it to the user. The user then presents its TGT to a Domain Controller to request a Ticket Granting Service (TGS) ticket, encrypted with the associated service’s NTLM password hash. Finally, the client requests access to the required service by presenting the TGS to the application or service, which decrypts it with its password hash. If the entire process completes appropriately, the user will be permitted to access the requested service or application.

Kerberos authentication effectively decouples users’ credentials from their requests to consumable resources, ensuring that their password isn’t transmitted over the network (i.e., accessing an internal SharePoint intranet site).

The Kerberos Key Distribution Centre (KDC) does not record previous transactions. Instead, the Kerberos Ticket Granting Service ticket (TGS) relies on a valid Ticket Granting Ticket (TGT). It assumes that if the user has a valid TGT, they must have proven their identity.

Kerberos Authentication Process

Here’s a high-level summary of Kerberos authentication:

  1. User Sends Username:
    • The user sends their username to the Key Distribution Center (KDC) as part of the Authentication Service Request (AS-REQ).
  2. KDC Sends Challenge:
    • The KDC responds with a challenge (encrypted nonce), which is a random value that the user must encrypt using their password.
  3. User Encrypts Challenge with Password Hash:
    • The user’s machine uses the password hash (e.g., NTLM) to encrypt the challenge sent by the KDC.
  4. KDC Verifies the Response:
    • The KDC uses its stored version of the user’s password hash to decrypt the challenge. If it matches, the user is authenticated.
  5. TGT Issued:
    • The KDC generates a Ticket Granting Ticket (TGT), which is encrypted using a session key derived from the password hash. This TGT is sent back to the user.
  6. User Requests Service Access:
    • With the TGT, the user can request access to services (e.g., a file server) by sending the TGT to the KDC to request a service ticket.
  7. Service Access Granted:
    • The KDC issues a service ticket that the user presents to the requested service. The service uses its own key to decrypt the ticket and grant access.

Here’s an in depth canvas about showcasing this authentication - Kerberos Authentication.canvas.

Security Measures:

  • Password hash is never transmitted directly.
  • Session key ensures the TGT is encrypted securely.
  • Challenge-response mechanism prevents impersonation by requiring the correct password hash.

In essence, the KDC acts as a trusted intermediary, securely issuing tickets based on the user’s credentials, without needing to send passwords across the network.

And here’s HTB’s short version:

1. The user logs on, and their password is converted to an NTLM hash, which is used to encrypt the TGT ticket. This decouples the user’s credentials from requests to resources.
2. The KDC service on the DC checks the authentication service request (AS-REQ), verifies the user information, and creates a Ticket Granting Ticket (TGT), which is delivered to the user.
3. The user presents the TGT to the DC, requesting a Ticket Granting Service (TGS) ticket for a specific service. This is the TGS-REQ. If the TGT is successfully validated, its data is copied to create a TGS ticket.
4. The TGS is encrypted with the NTLM password hash of the service or computer account in whose context the service instance is running and is delivered to the user in the TGS_REP.
5. The user presents the TGS to the service, and if it is valid, the user is permitted to connect to the resource (AP_REQ).

The Kerberos protocol uses port 88 (both TCP and UDP). When enumerating an Active Directory environment, we can often locate Domain Controllers by performing port scans looking for open port 88 using a tool such as Nmap.


Useful Commands

Kerberos ticket information

klist - View tickets cached on the system
kdestroy - Delete tickets from the cache
klist -v - View detailed information about a specific ticket

Kerberos authentication

kinit username - Obtain a Kerberos ticket for a user
Note: This prompts for the user’s password)

kinit username@REALM - Obtain a ticket with a specified realm

Using impacket tools

python3 GetTGT.py username:password@domain - Get TGT for a user using “GetTGT.py”
python3 kerberos.py domaincontroller - Use “kerberos.py” from Impacket to interact with Kerberos services

Kerberos ticket extraction (Mimikatz)

sekurlsa::logonpasswords - Extract tickets from memory (LSASS)
kerberos::list /export - Dump only Kerberos tickets from LSASS

Enumerating kerberos tickets (PowerView)

Get-DomainUser -Kerberos - List all Kerberos tickets for the current user
Get-DomainUser -PreAuthNotRequired - Enumerate all users with Kerberos pre-authentication disabled (useful for attacks like AS-REP Roasting)
Get-DomainUser -SPN - Find accounts with service principal names (SPNs) set (useful for Kerberos-based attacks like Pass-the-Ticket or Kerberos Bruteforce)

Finding service accounts

Get-DomainServiceAccount - Find service accounts with Kerberos authentication (which can have associated SPNs)

Kerberos TGT extraction

Get-DomainTGT - Export TGT from the current session (if you have the correct privileges)

Finding delegation (Kerberos Constrained Delegation)

Get-DomainDelegation - Check for delegation permissions:


Common scenerio

The most common scenerio is that you either use kinit or imapcket’s commands to get a .ccache file of someone’s TGT. Then you use it to login to different applications. Here’s a small breakdown of how this scenerio usually goes down.

  1. impacket-getTGT frizz.htb/f.frizzle:Jenni_Luvs_Magic23 - You get the .ccache of a user
  2. You run klist to check if you don’t have any old tickets, you run kdestroy if there are to avoid any colissions.
  3. export KRB5CCNAME=$(pwd)/f.frizzle.ccache - Tell Kerberos which file contains your ticket.
  4. Verify with klist if all is well.
  5. Now, you will also likely need to add the specific domain you use into the /etc/krb5.conf. To do so, just edit this template (case is important here!):
[libdefaults]
	default_realm = FRIZZ.HTB
[realms]
	FRIZZ.HTB = {
		kdc = frizzdc.frizz.htb
		admin_server = frizzdc.frizz.htb
}
[domain_realm]
	.frizz.htb = FRIZZ.HTB
	frizz.htb = FRIZZ.HTB
  1. Now you can run all commands with your new ticket.
    ssh -K -o GSSAPIAuthentication=yes f.frizzle@frizz.htb

Kerberos “Double Hop” Problem

As always when considering authentication on Windows remember about the dual-hop problem.
It exists because some protocols and tools don’t cache credentials on our target host. Meaning that when you want to access other hosts or a DC from that target host you will not be granted TGT as it is derived from the stored credentials on the target host that you provided to access it. RDP and SSH are pretty clean from that issue tho but keep it in mind to not be cough by surprise all of a sudden.

Which protocols and tools often have this issue

  • SMB (Server Message Block): When accessing shares across multiple systems, you may need to forward credentials.
  • PowerShell Remoting (PSSession): If you run commands remotely on another machine, Kerberos won’t forward credentials automatically.
  • DCOM/RPC: Remote calls between systems may also face the double-hop issue if credentials aren’t forwarded.
  • WinRM: As mentioned, this can also be impacted unless delegation is configured.

Workarounds

Besides just using other tools if possible a few workarounds for the double-hop issue are covered in this post. We can use a “nested” Invoke-Command to send credentials (after creating a PSCredential object) with every request, so if we try to authenticate from our attack host to host A and run commands on host B, we are permitted.

Workaround 1 - Evil-WinRM and PSCredentials

We can also connect to the remote host via host A and set up a PSCredential object to pass our credentials again. Let’s see that in action.

After connecting to a remote host with domain credentials, we import PowerView and then try to run a command. As seen below, we get an error because we cannot pass our authentication on to the Domain Controller to query for the SPN accounts.

*Evil-WinRM* PS C:\Users\backupadm\Documents> import-module .\PowerView.ps1
 
|S-chain|-<>-127.0.0.1:9051-<><>-172.16.8.50:5985-<><>-OK
|S-chain|-<>-127.0.0.1:9051-<><>-172.16.8.50:5985-<><>-OK
*Evil-WinRM* PS C:\Users\backupadm\Documents> get-domainuser -spn
Exception calling "FindAll" with "0" argument(s): "An operations error occurred.
"
At C:\Users\backupadm\Documents\PowerView.ps1:5253 char:20
+             else { $Results = $UserSearcher.FindAll() }
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DirectoryServicesCOMException

If we check with klist, we see that we only have a cached Kerberos ticket for our current server.

*Evil-WinRM* PS C:\Users\backupadm\Documents> klist
 
Current LogonId is 0:0x57f8a
 
Cached Tickets: (1)
 
#0> Client: backupadm @ INLANEFREIGHT.LOCAL
    Server: academy-aen-ms0$ @
    KerbTicket Encryption Type: AES-256-CTS-HMAC-SHA1-96
    Ticket Flags 0xa10000 -> renewable pre_authent name_canonicalize
    Start Time: 6/28/2022 7:31:53 (local)
    End Time:   6/28/2022 7:46:53 (local)
    Renew Time: 7/5/2022 7:31:18 (local)
    Session Key Type: AES-256-CTS-HMAC-SHA1-96
    Cache Flags: 0x4 -> S4U
    Kdc Called: DC01.INLANEFREIGHT.LOCAL

So now, let’s set up a PSCredential object and try again. First, we set up our authentication.

*Evil-WinRM* PS C:\Users\backupadm\Documents> $SecPassword = ConvertTo-SecureString '!qazXSW@' -AsPlainText -Force
 
|S-chain|-<>-127.0.0.1:9051-<><>-172.16.8.50:5985-<><>-OK
|S-chain|-<>-127.0.0.1:9051-<><>-172.16.8.50:5985-<><>-OK
*Evil-WinRM* PS C:\Users\backupadm\Documents>  $Cred = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\backupadm', $SecPassword)

Now we can try to query the SPN accounts using PowerView and are successful because we passed our credentials along with the command.

*Evil-WinRM* PS C:\Users\backupadm\Documents> get-domainuser -spn -credential $Cred | select samaccountname
 
|S-chain|-<>-127.0.0.1:9051-<><>-172.16.8.50:5985-<><>-OK
|S-chain|-<>-127.0.0.1:9051-<><>-172.16.8.50:5985-<><>-OK
 
samaccountname
--------------
azureconnect
backupjob
krbtgt
mssqlsvc
sqltest
sqlqa
sqldev
mssqladm
svc_sql
sqlprod
sapsso
sapvc
vmwarescvc

If we try again without specifying the -credential flag, we once again get an error message.

get-domainuser -spn | select 
 
*Evil-WinRM* PS C:\Users\backupadm\Documents> get-domainuser -spn | select samaccountname 
 
|S-chain|-<>-127.0.0.1:9051-<><>-172.16.8.50:5985-<><>-OK
|S-chain|-<>-127.0.0.1:9051-<><>-172.16.8.50:5985-<><>-OK
Exception calling "FindAll" with "0" argument(s): "An operations error occurred.
"
At C:\Users\backupadm\Documents\PowerView.ps1:5253 char:20
+             else { $Results = $UserSearcher.FindAll() }
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DirectoryServicesCOMException
Workaround 2 - WinRM and Enter-PSSession

There is also a workaround when we’re on a domain-joined host and can connect remotely to another using WinRM or if we are working from a Windows attack host and connect to our target via WinRM using the Enter-PSSession cmdlet.
Here we have another option to change our setup to be able to interact directly with the DC or other hosts/resources without having to set up a PSCredential object and include credentials along with every command (which may not be an option with some tools).

Let’s start by first establishing a WinRM session on the remote host.

PS C:\htb> Enter-PSSession -ComputerName ACADEMY-AEN-DEV01.INLANEFREIGHT.LOCAL -Credential inlanefreight\backupadm

If we check for cached tickets using klist, we’ll see that the same problem exists. Due to the double hop problem, we can only interact with resources in our current session but cannot access the DC directly using PowerView. We can see that our current TGS is good for accessing the HTTP service on the target since we connected over WinRM.

[ACADEMY-AEN-DEV01.INLANEFREIGHT.LOCAL]: PS C:\Users\backupadm\Documents> klist
 
Current LogonId is 0:0x11e387
 
Cached Tickets: (1)
 
#0>     Client: backupadm @ INLANEFREIGHT.LOCAL
       Server: HTTP/ACADEMY-AEN-DEV01.INLANEFREIGHT.LOCAL @ INLANEFREIGHT.LOCAL
       KerbTicket Encryption Type: AES-256-CTS-HMAC-SHA1-96
       Ticket Flags 0x40a10000 -> forwardable renewable pre_authent name_canonicalize
       Start Time: 6/28/2022 9:09:19 (local)
       End Time:   6/28/2022 19:09:19 (local)
       Renew Time: 0
       Session Key Type: AES-256-CTS-HMAC-SHA1-96
       Cache Flags: 0x8 -> ASC
       Kdc Called:

We also cannot interact directly with the DC using PowerView

[ACADEMY-AEN-DEV01.INLANEFREIGHT.LOCAL]: PS C:\Users\backupadm\Documents> Import-Module .\PowerView.ps1
[ACADEMY-AEN-DEV01.INLANEFREIGHT.LOCAL]: PS C:\Users\backupadm\Documents> get-domainuser -spn | select samaccountname
 
Exception calling "FindAll" with "0" argument(s): "An operations error occurred.
"
At C:\Users\backupadm\Documents\PowerView.ps1:5253 char:20
+             else { $Results = $UserSearcher.FindAll() }
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
   + FullyQualifiedErrorId : DirectoryServicesCOMException

One trick we can use here is registering a new session configuration using the Register-PSSessionConfiguration cmdlet.

PS C:\htb> Register-PSSessionConfiguration -Name backupadmsess -RunAsCredential inlanefreight\backupadm
 
 WARNING: When RunAs is enabled in a Windows PowerShell session configuration, the Windows security model cannot enforce
 a security boundary between different user sessions that are created by using this endpoint. Verify that the Windows
PowerShell runspace configuration is restricted to only the necessary set of cmdlets and capabilities.
WARNING: Register-PSSessionConfiguration may need to restart the WinRM service if a configuration using this name has
recently been unregistered, certain system data structures may still be cached. In that case, a restart of WinRM may be
 required.
All WinRM sessions connected to Windows PowerShell session configurations, such as Microsoft.PowerShell and session
configurations that are created with the Register-PSSessionConfiguration cmdlet, are disconnected.
 
   WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Plugin
 
Type            Keys                                Name
----            ----                                ----
Container       {Name=backupadmsess}                backupadmsess

Once this is done, we need to restart the WinRM service by typing Restart-Service WinRM in our current PSSession. This will kick us out, so we’ll start a new PSSession using the named registered session we set up previously.

After we start the session, we can see that the double hop problem has been eliminated, and if we type klist, we’ll have the cached tickets necessary to reach the Domain Controller. This works because our local machine will now impersonate the remote machine in the context of the backupadm user and all requests from our local machine will be sent directly to the Domain Controller.

PS C:\htb> Enter-PSSession -ComputerName DEV01 -Credential INLANEFREIGHT\backupadm -ConfigurationName  backupadmsess
[DEV01]: PS C:\Users\backupadm\Documents> klist
 
Current LogonId is 0:0x2239ba
 
Cached Tickets: (1)
 
#0>     Client: backupadm @ INLANEFREIGHT.LOCAL
       Server: krbtgt/INLANEFREIGHT.LOCAL @ INLANEFREIGHT.LOCAL
       KerbTicket Encryption Type: AES-256-CTS-HMAC-SHA1-96
       Ticket Flags 0x40e10000 -> forwardable renewable initial pre_authent name_canonicalize
       Start Time: 6/28/2022 13:24:37 (local)
       End Time:   6/28/2022 23:24:37 (local)
       Renew Time: 7/5/2022 13:24:37 (local)
       Session Key Type: AES-256-CTS-HMAC-SHA1-96
       Cache Flags: 0x1 -> PRIMARY
       Kdc Called: DC01

We can now run tools such as PowerView without having to create a new PSCredential object.

[DEV01]: PS C:\Users\Public> get-domainuser -spn | select samaccountname
 
samaccountname
--------------
azureconnect
backupjob
krbtgt
mssqlsvc
sqltest
sqlqa
sqldev
mssqladm
svc_sql
sqlprod
sapsso
sapvc
vmwarescvc

Note: We cannot use Register-PSSessionConfiguration from an evil-winrm shell because we won’t be able to get the credentials popup. Furthermore, if we try to run this by first setting up a PSCredential object and then attempting to run the command by passing credentials like -RunAsCredential $Cred, we will get an error because we can only use RunAs from an elevated PowerShell terminal. Therefore, this method will not work via an evil-winrm session as it requires GUI access and a proper PowerShell console. Furthermore, in our testing, we could not get this method to work from PowerShell on a Parrot or Ubuntu attack host due to certain limitations on how PowerShell on Linux works with Kerberos credentials. This method is still highly effective if we are testing from a Windows attack host and have a set of credentials or compromise a host and can connect via RDP to use it as a “jump host” to mount further attacks against hosts in the environment. .

We can also use other methods such as CredSSP, port forwarding, or injecting into a process running in the context of a target user (sacrificial process).

As always - you can find some more details about it in HTB notes.