Skip to content

Commit 74f80e6

Browse files
committed
Default value added to OLDPASS and OLDNTHASH option
1 parent 4604d49 commit 74f80e6

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

nxc/modules/change-password.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class NXCModule:
66
"""
77
Module for changing or resetting user passwords
8-
Module by Fagan Afandiyev
8+
Module by Fagan Afandiyev and termanix
99
"""
1010

1111
name = "change-password"
@@ -33,12 +33,12 @@ def options(self, context, module_options):
3333
self.newpass = module_options.get("NEWPASS")
3434
self.newhash = module_options.get("NEWNTHASH")
3535
self.oldpass = module_options.get("OLDPASS")
36-
self.oldhash = module_options.get("OLDNTHASH")
36+
self.oldhash = module_options.get("OLDNTHASH" )
3737
self.target_user = module_options.get("USER")
3838
self.reset = module_options.get("RESET", True)
3939

4040
if not self.newpass and not self.newhash:
41-
context.log.fail("Either NEWPASS or NEWHASH is required!")
41+
context.log.fail("Either NEWPASS or NEWNTHASH is required!")
4242
sys.exit(1)
4343

4444
def authenticate(self, context, connection, protocol, anonymous=False):
@@ -79,7 +79,15 @@ def authenticate(self, context, connection, protocol, anonymous=False):
7979
def on_login(self, context, connection):
8080
target_username = self.target_user or connection.username
8181
target_domain = connection.domain
82+
83+
# If OLDPASS or OLDHASH are not specified, default to the credentials used for authentication.
8284

85+
if not self.oldpass:
86+
self.oldpass = connection.password
87+
if not self.oldhash:
88+
self.oldhash = connection.nthash
89+
90+
8391
new_lmhash, new_nthash = "", ""
8492

8593
# Parse new hash values if provided
@@ -133,6 +141,8 @@ def _smb_samr_change(self, context, connection, target_username, target_domain,
133141
else:
134142
# Handle anonymous/null session password change
135143
self.mustchangePassword(target_username, target_domain, self.oldpass, newPassword, "", oldHash, "", newHash)
144+
except AttributeError as e:
145+
context.log.fail("SMB-SAMR password change failed: Ensure that either the OLDPASS or OLDNTHASH option is provided and attempt again.")
136146
except Exception as e:
137147
context.log.fail(f"SMB-SAMR password change failed: {e}")
138148
finally:

0 commit comments

Comments
 (0)