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

Inconsistency between --lsa via NTLM and Kerberos #55

Open
Dfte opened this issue Oct 3, 2023 · 8 comments
Open

Inconsistency between --lsa via NTLM and Kerberos #55

Dfte opened this issue Oct 3, 2023 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@Dfte
Copy link
Contributor

Dfte commented Oct 3, 2023

It looks like there is some inconsistency between the result of the --lsa option when connecting via NTLM and Kerberos:

Below is the result when dumping lsa via a NTLM authentication:

image

And here is the result when dumping via Kerberos (-k):

image

The AES and DES keys for the DC$ account are not dumped.

I'll take a look at why ASAP.

@XiaoliChan
Copy link
Contributor

Maybe something is wrong in impacket. 🧐

@Dfte
Copy link
Contributor Author

Dfte commented Oct 6, 2023

The bug is located in secretsdump, function getMachineKerberosSalt(). Using Kerberos, Impacket is not able to obtain the domain FQDN and the computer name which are required to build the salt used to decrypt AESKeys.

The following code patches the bug:

def getMachineKerberosSalt(self):
       """
       Returns Kerberos salt for the current connection if
       we have the correct information
       """
       # Patched by @Defte_ when using Kerberos, the getServerName function returns nothing
       # But we do need the domain FQDN as well as the computer name
       if self.__smbConnection.getServerName() == '':
           # To do we can request the getMachineNameAndDomain() which returns:
           #   - The computer name
           #   - The domain name (not FQDN so we don't need that hence the _)
           # Using the getRemoteHost function we can get the DC FQDN to which we substract the computer name
           # One we have the domain FQDN and the computer name we can compute the Kerberos salt
           host, _ = self.getMachineNameAndDomain()
           domain = self.__smbConnection.getRemoteHost().split(f"{host.lower()}.")[1]
           LOG.debug(f"[Secretsdump][getMachineKerberosSalt] {host}.{domain}")
       else:
           host = self.__smbConnection.getServerName()
           domain = self.__smbConnection.getServerDNSDomainName()
       salt = b'%shost%s.%s' % (domain.upper().encode('utf-8'), host.lower().encode('utf-8'), domain.lower().encode('utf-8'))
       return salt

And now we can obain the AESKeys as well via --lsa -k

image

Leaving this issue open until fix is merged in both fortra/theporgs/our impacket ?

@Marshall-Hallenbeck Marshall-Hallenbeck added the bug Something isn't working label Oct 7, 2023
@Marshall-Hallenbeck Marshall-Hallenbeck added this to the v1.1.0 milestone Oct 7, 2023
@XiaoliChan
Copy link
Contributor

@Dfte This is a Really nice patch, I think this should be made a PR in fortra's upstream

@Dfte
Copy link
Contributor Author

Dfte commented Oct 7, 2023

I'll PR this in the afternoon yeah!

@Dfte
Copy link
Contributor Author

Dfte commented Oct 7, 2023

PR's done, we'll have to wait for it to be merged :)

fortra/impacket#1628

@mpgn
Copy link
Collaborator

mpgn commented Oct 17, 2023

Hello @Dfte can you do the same pr on https://github.com/Pennyw0rth/impacket/tree/gkdi ? :)

@NeffIsBack
Copy link
Contributor

Closed as fixed in Pennyw0rth/impacket#3

@mpgn
Copy link
Collaborator

mpgn commented Nov 2, 2023

Reverted, PR on impacket has not been tested once i think:

  • there is space and tab mix on the PR
  • if you fix the space / tab problem, you have a stacktrace
    image

@mpgn mpgn reopened this Nov 2, 2023
@mpgn mpgn removed this from the v1.1.0 milestone Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants