Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/secretsdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ def dump(self):
SECURITYFileName = self.__securityHive

self.__LSASecrets = LSASecrets(SECURITYFileName, bootKey, self.__remoteOps,
isRemote=self.__isRemote, history=self.__history)
isRemote=self.__isRemote, history=self.__history,
systemHive=self.__systemHive)
self.__LSASecrets.dumpCachedHashes()
if self.__outputFileName is not None:
self.__LSASecrets.exportCached(self.__outputFileName)
Expand Down
24 changes: 22 additions & 2 deletions impacket/examples/secretsdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,8 @@ class SECRET_TYPE:
LSA_KERBEROS = 3

def __init__(self, securityFile, bootKey, remoteOps=None, isRemote=False, history=False,
perSecretCallback=lambda secretType, secret: _print_helper(secret)):
perSecretCallback=lambda secretType, secret: _print_helper(secret),
systemHive=None):
OfflineRegistry.__init__(self, securityFile, isRemote)
self.__hashedBootKey = b''
self.__bootKey = bootKey
Expand All @@ -1994,6 +1995,7 @@ def __init__(self, securityFile, bootKey, remoteOps=None, isRemote=False, histor
self.__secretItems = []
self.__perSecretCallback = perSecretCallback
self.__history = history
self.__systemHive = systemHive

def MD5(self, data):
md5 = hashlib.new('md5')
Expand Down Expand Up @@ -2090,6 +2092,22 @@ def __pad(self, data):
else:
return data

def getServiceUser(self, svcName):
LOG.debug(f'Retrieving {svcName}\'s user')
winreg = winregistry.get_registry_parser(self.__systemHive, False)
user = '(Unknown User)'
try:
currentControlSet = winreg.getValue('\\Select\\Current')[1]
currentControlSet = "ControlSet%03d" % currentControlSet

user = winreg.getValue('\\%s\\Services\\%s\\ObjectName' % (currentControlSet, svcName))
if user is not None:
user = user[1].decode('utf-16-le').rstrip('\x00')
except:
pass

return user

def dumpCachedHashes(self):
if self.__securityFile is None:
# No SECURITY file provided
Expand Down Expand Up @@ -2182,7 +2200,9 @@ def __printSecret(self, name, secretItem):
else:
# We have to get the account the service
# runs under
if hasattr(self.__remoteOps, 'getServiceAccount'):
if self.__systemHive:
secret = self.getServiceUser(name[4:]) + ':'
elif hasattr(self.__remoteOps, 'getServiceAccount'):
account = self.__remoteOps.getServiceAccount(name[4:])
if account is None:
secret = self.UNKNOWN_USER + ':'
Expand Down