99from impacket .smb import SMB_DIALECT
1010from impacket .examples .secretsdump import (
1111 RemoteOperations ,
12- SAMHashes ,
13- LSASecrets ,
1412 NTDSHashes ,
1513)
14+ from impacket .examples .regsecrets import (
15+ RemoteOperations as RegSecretsRemoteOperations ,
16+ SAMHashes ,
17+ LSASecrets
18+ )
1619from impacket .nmb import NetBIOSError , NetBIOSTimeout
1720from impacket .dcerpc .v5 import transport , lsat , lsad , scmr , rrp , srvs , wkst
1821from impacket .dcerpc .v5 .rpcrt import DCERPCException
@@ -1532,9 +1535,12 @@ def get_file(self):
15321535 for src , dest in self .args .get_file :
15331536 self .get_file_single (src , dest )
15341537
1535- def enable_remoteops (self ):
1538+ def enable_remoteops (self , regsecret = False ):
15361539 try :
1537- self .remote_ops = RemoteOperations (self .conn , self .kerberos , self .kdcHost )
1540+ if regsecret :
1541+ self .remote_ops = RegSecretsRemoteOperations (self .conn , self .kerberos , self .kdcHost )
1542+ else :
1543+ self .remote_ops = RemoteOperations (self .conn , self .kerberos , self .kdcHost )
15381544 self .remote_ops .enableRegistry ()
15391545 if self .bootkey is None :
15401546 self .bootkey = self .remote_ops .getBootKey ()
@@ -1544,7 +1550,7 @@ def enable_remoteops(self):
15441550 @requires_admin
15451551 def sam (self ):
15461552 try :
1547- self .enable_remoteops ()
1553+ self .enable_remoteops (regsecret = True )
15481554 host_id = self .db .get_hosts (filter_term = self .host )[0 ][0 ]
15491555
15501556 def add_sam_hash (sam_hash , host_id ):
@@ -1562,11 +1568,9 @@ def add_sam_hash(sam_hash, host_id):
15621568 add_sam_hash .sam_hashes = 0
15631569
15641570 if self .remote_ops and self .bootkey :
1565- SAM_file_name = self .remote_ops .saveSAM ()
15661571 SAM = SAMHashes (
1567- SAM_file_name ,
15681572 self .bootkey ,
1569- isRemote = True ,
1573+ remoteOps = self . remote_ops ,
15701574 perSecretCallback = lambda secret : add_sam_hash (secret , host_id ),
15711575 )
15721576
@@ -1579,7 +1583,6 @@ def add_sam_hash(sam_hash, host_id):
15791583 self .remote_ops .finish ()
15801584 except Exception as e :
15811585 self .logger .debug (f"Error calling remote_ops.finish(): { e } " )
1582- SAM .finish ()
15831586 except SessionError as e :
15841587 if "STATUS_ACCESS_DENIED" in e .getErrorString ():
15851588 self .logger .fail ('Error "STATUS_ACCESS_DENIED" while dumping SAM. This is likely due to an endpoint protection.' )
@@ -1796,7 +1799,7 @@ def firefox_callback(secret):
17961799 @requires_admin
17971800 def lsa (self ):
17981801 try :
1799- self .enable_remoteops ()
1802+ self .enable_remoteops (regsecret = True )
18001803
18011804 def add_lsa_secret (secret ):
18021805 add_lsa_secret .secrets += 1
@@ -1815,12 +1818,9 @@ def add_lsa_secret(secret):
18151818 add_lsa_secret .secrets = 0
18161819
18171820 if self .remote_ops and self .bootkey :
1818- SECURITYFileName = self .remote_ops .saveSECURITY ()
18191821 LSA = LSASecrets (
1820- SECURITYFileName ,
18211822 self .bootkey ,
18221823 self .remote_ops ,
1823- isRemote = True ,
18241824 perSecretCallback = lambda secret_type , secret : add_lsa_secret (secret ),
18251825 )
18261826 self .logger .success ("Dumping LSA secrets" )
@@ -1833,7 +1833,6 @@ def add_lsa_secret(secret):
18331833 self .remote_ops .finish ()
18341834 except Exception as e :
18351835 self .logger .debug (f"Error calling remote_ops.finish(): { e } " )
1836- LSA .finish ()
18371836 except SessionError as e :
18381837 if "STATUS_ACCESS_DENIED" in e .getErrorString ():
18391838 self .logger .fail ('Error "STATUS_ACCESS_DENIED" while dumping LSA. This is likely due to an endpoint protection.' )
0 commit comments