Skip to content

Commit d2342db

Browse files
authored
Merge pull request Pennyw0rth#1110 from Coontzy1/main
SAM History Dumping
2 parents 43027f4 + 6cfb52c commit d2342db

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

nxc/protocols/smb.py

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

19761976
def add_sam_hash(sam_hash, host_id):
1977-
add_sam_hash.sam_hashes += 1
19781977
self.logger.highlight(sam_hash)
1978+
if "_history" in sam_hash:
1979+
return
19791980
username, _, lmhash, nthash, _, _, _ = sam_hash.split(":")
19801981
self.db.add_credential(
19811982
"hash",
@@ -1984,6 +1985,7 @@ def add_sam_hash(sam_hash, host_id):
19841985
f"{lmhash}:{nthash}",
19851986
pillaged_from=host_id,
19861987
)
1988+
add_sam_hash.sam_hashes += 1
19871989

19881990
add_sam_hash.sam_hashes = 0
19891991

@@ -1993,13 +1995,15 @@ def add_sam_hash(sam_hash, host_id):
19931995
self.bootkey,
19941996
remoteOps=self.remote_ops,
19951997
perSecretCallback=lambda secret: add_sam_hash(secret, host_id),
1998+
history=self.args.history,
19961999
)
19972000
else:
19982001
SAM_file_name = self.remote_ops.saveSAM()
19992002
SAM = SAMHashes(
20002003
SAM_file_name,
20012004
self.bootkey,
20022005
isRemote=True,
2006+
history=self.args.history,
20032007
perSecretCallback=lambda secret: add_sam_hash(secret, host_id),
20042008
)
20052009

nxc/protocols/smb/proto_args.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ def proto_args(parser, parents):
3434
cred_gathering_group.add_argument("--sam", choices={"regdump", "secdump"}, nargs="?", const="regdump", help="dump SAM hashes from target systems")
3535
cred_gathering_group.add_argument("--lsa", choices={"regdump", "secdump"}, nargs="?", const="regdump", help="dump LSA secrets from target systems")
3636
ntds_arg = cred_gathering_group.add_argument("--ntds", choices={"vss", "drsuapi"}, nargs="?", const="drsuapi", help="dump the NTDS.dit from target DCs using the specifed method")
37+
cred_gathering_group.add_argument("--history", action="store_true", help="Also retrieve password history (NTDS.dit or SAM)")
3738
# NTDS options
3839
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)")
3940
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)")
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)