|
5 | 5 | class NXCModule: |
6 | 6 | """ |
7 | 7 | Module for changing or resetting user passwords |
8 | | - Module by Fagan Afandiyev |
| 8 | + Module by Fagan Afandiyev and termanix |
9 | 9 | """ |
10 | 10 |
|
11 | 11 | name = "change-password" |
@@ -33,12 +33,12 @@ def options(self, context, module_options): |
33 | 33 | self.newpass = module_options.get("NEWPASS") |
34 | 34 | self.newhash = module_options.get("NEWNTHASH") |
35 | 35 | self.oldpass = module_options.get("OLDPASS") |
36 | | - self.oldhash = module_options.get("OLDNTHASH") |
| 36 | + self.oldhash = module_options.get("OLDNTHASH" ) |
37 | 37 | self.target_user = module_options.get("USER") |
38 | 38 | self.reset = module_options.get("RESET", True) |
39 | 39 |
|
40 | 40 | 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!") |
42 | 42 | sys.exit(1) |
43 | 43 |
|
44 | 44 | def authenticate(self, context, connection, protocol, anonymous=False): |
@@ -79,7 +79,15 @@ def authenticate(self, context, connection, protocol, anonymous=False): |
79 | 79 | def on_login(self, context, connection): |
80 | 80 | target_username = self.target_user or connection.username |
81 | 81 | target_domain = connection.domain |
| 82 | + |
| 83 | + # If OLDPASS or OLDHASH are not specified, default to the credentials used for authentication. |
82 | 84 |
|
| 85 | + if not self.oldpass: |
| 86 | + self.oldpass = connection.password |
| 87 | + if not self.oldhash: |
| 88 | + self.oldhash = connection.nthash |
| 89 | + |
| 90 | + |
83 | 91 | new_lmhash, new_nthash = "", "" |
84 | 92 |
|
85 | 93 | # Parse new hash values if provided |
@@ -133,6 +141,8 @@ def _smb_samr_change(self, context, connection, target_username, target_domain, |
133 | 141 | else: |
134 | 142 | # Handle anonymous/null session password change |
135 | 143 | 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.") |
136 | 146 | except Exception as e: |
137 | 147 | context.log.fail(f"SMB-SAMR password change failed: {e}") |
138 | 148 | finally: |
|
0 commit comments