Occurs when an attacker attempts to use Kerberos authentication across two (or more) hops. The issue concerns how Kerberos tickets are granted for specific ersources. Kerberos tickets should not be viewed as passwords ; they are signed pieces of data from KDC that state what resources an account can access.
KDC -> Ticket permits access to service/resources Password -> NTLM hash stored in session and used elsewhere seamlessly.
Double hop issue often occurs when using winrm/PS. Default auth mechanism provides ticket to specific resource.
- Causes issues moving laterally
- even accessing file shares
The user account being used has rights to perform an action but is denied. Most common way to get shells is by attacking an application on target host or using credentials and a tool such as PSexec. Both scenarios initial authentication was likely performed over SMB or LDAP meaning user NTLM hash would be stored in memory. Sometimes we have a set of creds restricted to particular mode of auth such as winrm
Crux of the issue is as follows:
- Using WinRM to auth over two/more connections
- User password is never cached as part of their login
- Using mimikatz to look at session, credentials are blank.
- Stated previously when we use kerberos to establish a remote sesion we're not using a password for authentication.
- When PW auth is used with psexec, the NTLM hash is stored in the session, so when we go to access another resource the machine is able to pull the NTLM hash from memory and authenticate.
PS C:\htb> PS C:\Users\ben.INLANEFREIGHT> Enter-PSSession -ComputerName DEV01 -Credential INLANEFREIGHT\backupadm
[DEV01]: PS C:\Users\backupadm\Documents> cd 'C:\Users\Public\'
[DEV01]: PS C:\Users\Public> .\mimikatz "privilege::debug" "sekurlsa::logonpasswords" exit
{The resulting output from these commands run in sequence do not show `backupadm` logged in.}
There /are/ some processes running in backupadm context:
[DEV01]: PS C:\Users\Public> tasklist /V |findstr backupadm
such as wsmprovhost.exe which is run when a remote PS session is spawned
In simplest terms: When we try to issue a multi-server command, our credentials will not be sent from the first machine to the second.
Assume three hosts: Attack host -> Dev01 -> DC01  Obtain creds for domain user and find they are part of Remote Management Users group on DEV01 - We want to use PowerView to enum, which requires communication with DC01. When we connect to DEV01 with winrm, we connect with network auth and our creds are not stored in memory. Thus we cannot auth to other resources
- Kerberos has no way of telling the DC that our user can access resources in the domain
- User TGT is not sent to remote session - User cannot prove identity.
- Commands will no longer be sent from this user's context.
- When auth to target host the user's TGS is sent to the remote service, which allows command execution, but the user's TGT ticket is not sent. When the user attempts to access subsequent resources in the domain, their TGT is not present in the request, so remote service has no way to prove their auth attempt is valid.
If unconstrained delegation is enabled, we won't worry about the double hop problem. In this scenario, when a user sends their TGS ticket to access the target server, their TGT ticket will be sent along with the request. The target server now has the user's TGT ticket in memory and can use it to request a TGS ticket on their behalf on the next host they are attempting to access.
- Account's TGS ticket is cached,
- Has ability to sign TGTs and grant remote access
Workarounds to double hop issue: https://posts.slayerlabs.com/double-hop/
- Nested
Invoke-Commandto 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. - Two methods:
- Via
evil-winrmsession - Via GUI access to windows host.
- Via
PSCredential object double hop workaround
Connect to remote host via HOST A and setup PSCredential obj to pass our credentials again.
- After connecting to remote host with domain creds, import PowerView and try to run a command.
*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
Checking with klist we see that we only have a cached Kerberos ticket for our current server.
After this, let's setup PSCredential obj and try again.
$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
$Cred = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\backupadm', $SecPassword)
Now retry SPN query:
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
[......]
Attempting the same command without the -Credential flag:
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.
If we RDP to the same host and open a CMD prompt and type klist we'll see that we have the necessary tickets cached to interact directly with the DC and don't have to worry about double hop. This is because our password is stored in memory.
Double hop register PSSession configuration
- What if we're on:
- Domain-joined host
- and we try to connect remotely to another host with WinRM
- Or, working from win atk host + connected with winrm using
Enter-PSSessioncmdlet. - In this scenario we can alter the setup to be able to interact directly with the DC / other hosts+resources without having to setup a PSCred obj and include creds along with every command, which may not be available with some tools.
Establish a winrm session on remote host.
Enter-PSSession -ComputerName ACADEMY-AEN-DEV01.INLANEFREIGHT.LOCAL -Credential inlanefreight\backupadm
If we check cached kerb tickets with klist we see the same problem exists (null creds)
Due to doublehop we can only interact with resources in our current session but cannot access the DC directly using PowerView
We'll see our TGS is good for accessing the HTTP service on the target since we connected over winRM which uses SOAP (Simple Object Access Protocol) requests in XML format to communicate over http.
But we 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.
Trick we'll use here is registering a new session configuration using Register-PSSessionConfiguration cmdlet
PS C:\htb> Register-PSSessionConfiguration -Name backupadmsess -RunAsCredential inlanefreight\backupadm
We get the below output:
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 we do this, we need to restart WinRM in our current PSSession - this will kick us out, and we start a new PSSession using the named registered session we setup earlier
Restart-Service WinRM
PS C:\htb> Enter-PSSession -ComputerName DEV01 -Credential INLANEFREIGHT\backupadm -ConfigurationName backupadmsess
Note backupadmsess
After we start the session, notice the double hop problem is no longer present. If we type klist we'll have cached tickets.
- This works because our local machine will now impersonate the remote machine in the context of the
backupadmuser and all requests from our local machine will be sent directly to the Domain Controller
KLIST OUTPUT AFTER PERFORMING THE ABOVE WORKAROUND
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
KLIST OUTPUT BEFORE PERFORMING THE ABOVE WORKAROUND
#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:
Note like we said before, we have HTTP access.
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. .
There's also other methods like CredSSP, Port Forwarding or injecting into a process running in the context of a target user (SACRIFICIAL process) that we won't cover here.