Skip to content

Commit a727f02

Browse files
committed
Add choice to use old or new technique
1 parent 9770306 commit a727f02

2 files changed

Lines changed: 41 additions & 16 deletions

File tree

nxc/protocols/smb.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
from impacket.smb import SMB_DIALECT
1010
from impacket.examples.secretsdump import (
1111
RemoteOperations,
12+
SAMHashes,
13+
LSASecrets,
1214
NTDSHashes,
1315
)
1416
from impacket.examples.regsecrets import (
1517
RemoteOperations as RegSecretsRemoteOperations,
16-
SAMHashes,
17-
LSASecrets
18+
SAMHashes as RegSecretsSAMHashes,
19+
LSASecrets as RegSecretsLSASecrets
1820
)
1921
from impacket.nmb import NetBIOSError, NetBIOSTimeout
2022
from 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.')

nxc/protocols/smb/proto_args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def proto_args(parser, parents):
2525
self_delegate_arg.make_required = [delegate_arg]
2626

2727
cred_gathering_group = smb_parser.add_argument_group("Credential Gathering", "Options for gathering credentials")
28-
cred_gathering_group.add_argument("--sam", action="store_true", help="dump SAM hashes from target systems")
29-
cred_gathering_group.add_argument("--lsa", action="store_true", help="dump LSA secrets from target systems")
28+
cred_gathering_group.add_argument("--sam", choices={"regdump", "secdump"}, nargs="?", const="regdump", help="dump SAM hashes from target systems")
29+
cred_gathering_group.add_argument("--lsa", choices={"regdump", "secdump"}, nargs="?", const="regdump", help="dump LSA secrets from target systems")
3030
cred_gathering_group.add_argument("--ntds", choices={"vss", "drsuapi"}, nargs="?", const="drsuapi", help="dump the NTDS.dit from target DCs using the specifed method")
3131
cred_gathering_group.add_argument("--dpapi", choices={"cookies", "nosystem"}, nargs="*", help="dump DPAPI secrets from target systems, can dump cookies if you add 'cookies', will not dump SYSTEM dpapi if you add nosystem")
3232
cred_gathering_group.add_argument("--sccm", choices={"wmi", "disk"}, nargs="?", const="disk", help="dump SCCM secrets from target systems")

0 commit comments

Comments
 (0)