impacket icon indicating copy to clipboard operation
impacket copied to clipboard

Feature Request - Kerberos support for SMBPasswd.py

Open mubix opened this issue 3 years ago • 6 comments

It would be very awesome to support kerberos (if possible) for password changes.

mubix avatar Sep 16 '21 18:09 mubix

I tried this in smbclient.py and got STATUS_WRONG_PASSWORD even though, as you can see I logged in just fine.

# ./smbclient.py -k -no-pass [email protected]
Impacket v0.9.24.dev1+20210906.175840.50c76958 - Copyright 2021 SecureAuth Corporation

Type help for list of commands
# password
New Password:
[-] SAMR SessionError: code: 0xc000006a - STATUS_WRONG_PASSWORD - When trying to update a password, this return status indicates that the value provided as the current password is not correct

mubix avatar Sep 16 '21 19:09 mubix

Logging in is not the issue here. Here's what @p0dalirius and I can tell you about this.

When attempting a password change, the SamrUnicodeChangePasswordUser2 method is invoked by smbclient.py. This method requires multiple arguments including the OldNtOwfPasswordEncryptedWithNewNt which is the old user's password hash. When you authenticated using kerberos, you used -no-pass so that smbclient.py doesn't ask you the user password, resulting in an empty "oldpassword" variable.

The following should work. It uses Kerberos pass-the-cache AND uses the user password supplied for the password change to work.

$ export KRB5CCNAME=user1.ccache
$ ./smbclient.py -k -debug "lab.local"/"user1":"oldPassword123"@"dc01"
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[+] Impacket Library Installation Path: /usr/local/lib/python2.7/dist-packages/impacket-0.9.23-py2.7.egg/impacket
[+] Using Kerberos Cache: user1.ccache
[+] SPN CIFS/[email protected] not found in cache
[+] AnySPN is True, looking for another suitable SPN
[+] Returning cached credential for KRBTGT/[email protected]
[+] Using TGT from cache
[+] Trying to connect to KDC at 192.168.2.1
Type help for list of commands
# password
New Password:
# exit

Regarding smbpasswd.py, supporting Kerberos would still require users to have knowledge of the old user password, or password hash. Still, @p0dalirius and I are working on a PR to add Kerberos support.

On a side note: obtaining knowledge of the actual user hash from a Kerberos/PKINIT authentication could be done via an UnPAC-the-Hash attack.

ShutdownRepo avatar Oct 06 '21 09:10 ShutdownRepo

We checked with @ShutdownRepo, and it is not possible to perform a password change with SamrUnicodeChangePasswordUser2 using Kerberos when the current password is expired (STATUS_PASSWORD_EXPIRED), since the bypass relies on a null session, which cannot be obtained through Kerberos.

However we submitted a pull request to smbpasswd.py and it is now possible to authenticate using Kerberos (only when password is not expired).

Here is a demo:

image

p0dalirius avatar Oct 06 '21 10:10 p0dalirius

I see cme I press thumb up

mpgn avatar Oct 06 '21 11:10 mpgn

If you use changepw instead of SamrUnicodeChangePasswordUser2 you can set the password without the need of the old password when you have a valid kerberos ticket - see here:

  • https://github.com/GhostPack/Rubeus#changepw
  • and the detailed blogpost about it: https://www.harmj0y.net/blog/redteaming/rubeus-now-with-more-kekeo/ by @harmj0y

I realize this would fall outside of the "smb" part of smbpasswd.py so it might be worth a kpasswd.py ? but personally it would be more convenient in my opinion to have it in a single example script.

mubix avatar Oct 08 '21 04:10 mubix

You may be interested in #1189. I have preferred to create a new script (kpasswd) because the two protocols and implementations are very different.

Alef-Burzmali avatar Oct 16 '21 22:10 Alef-Burzmali

Merged in master @ https://github.com/fortra/impacket/pull/1559

gabrielg5 avatar Aug 10 '23 15:08 gabrielg5